Skip to content

Commit

Permalink
OXDEV-7822 Move getCurrentShopId in test doubles
Browse files Browse the repository at this point in the history
Sieg committed Mar 27, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
1 parent 76bef8e commit 1039f3e
Showing 4 changed files with 28 additions and 20 deletions.
Original file line number Diff line number Diff line change
@@ -12,7 +12,6 @@
use OxidEsales\EshopCommunity\Internal\Framework\DIContainer\ContainerBuilder;
use OxidEsales\EshopCommunity\Internal\Framework\Module\Setup\Event\ServicesYamlConfigurationErrorEvent;
use OxidEsales\EshopCommunity\Internal\Transition\Utility\ContextInterface;
use OxidEsales\EshopCommunity\Tests\Unit\Internal\BasicContextStub;
use OxidEsales\EshopCommunity\Tests\Unit\Internal\ContextStub;
use PHPUnit\Framework\TestCase;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
@@ -27,8 +26,10 @@ class EventLoggingSubscriberTest extends TestCase
public function setup(): void
{
parent::setUp();
$containerBuilder = new ContainerBuilder(new BasicContextStub());

$containerBuilder = new ContainerBuilder(new ContextStub());
$this->container = $containerBuilder->getContainer();

$contextDefinition = $this->container->getDefinition(ContextInterface::class);
$contextDefinition->setClass(ContextStub::class);
$this->container->compile();
Original file line number Diff line number Diff line change
@@ -15,7 +15,7 @@
use OxidEsales\EshopCommunity\Internal\Framework\Module\Setup\Exception\InvalidModuleServicesException;
use OxidEsales\EshopCommunity\Internal\Framework\Module\Setup\Validator\ModuleConfigurationValidatorInterface;
use OxidEsales\EshopCommunity\Internal\Framework\Module\Setup\Validator\ServicesYamlValidator;
use OxidEsales\EshopCommunity\Tests\Unit\Internal\BasicContextStub;
use OxidEsales\EshopCommunity\Tests\Unit\Internal\ContextStub;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Filesystem\Filesystem;
@@ -32,7 +32,7 @@ public function setUp(): void
{
parent::setUp();

$context = new BasicContextStub();
$context = new ContextStub();
$this->modulePathResolver = $this->getMockBuilder(ModulePathResolverInterface::class)->getMock();
$this->moduleConfiguration = new ModuleConfiguration();
$this->validator = new ServicesYamlValidator(
21 changes: 5 additions & 16 deletions tests/Unit/Internal/BasicContextStub.php
Original file line number Diff line number Diff line change
@@ -25,7 +25,6 @@ class BasicContextStub implements BasicContextInterface
private string $enterpriseEditionRootPath;
private string $generatedServicesFilePath;
private string $configurableServicesFilePath;
private string $shopConfigurableServicesFilePath;
private string $professionalEditionRootPath;
private string $sourcePath;
private string $shopRootPath;
@@ -39,8 +38,9 @@ class BasicContextStub implements BasicContextInterface
private string $cacheDirectory;
private string $moduleCacheDirectory;
private string $templateCacheDirectory;
private int $currentShopId;
private string $activeModuleServicesFilePath;

protected string $activeModuleServicesFilePath;
protected string $shopConfigurableServicesFilePath;

public function __construct()
{
@@ -65,10 +65,9 @@ public function __construct()
$this->cacheDirectory = $basicContext->getCacheDirectory();
$this->moduleCacheDirectory = $basicContext->getModuleCacheDirectory();
$this->templateCacheDirectory = $basicContext->getTemplateCacheDirectory();
$this->currentShopId = $basicContext->getCurrentShopId();
$this->activeModuleServicesFilePath = $basicContext->getActiveModuleServicesFilePath($this->getCurrentShopId());
$this->activeModuleServicesFilePath = $basicContext->getActiveModuleServicesFilePath($this->getDefaultShopId());
$this->shopConfigurableServicesFilePath = $basicContext->getShopConfigurableServicesFilePath(
$this->getCurrentShopId()
$this->getDefaultShopId()
);
}

@@ -256,14 +255,4 @@ public function setActiveModuleServicesFilePath(string $path): void
{
$this->activeModuleServicesFilePath = $path;
}

public function getCurrentShopId(): int
{
return $this->currentShopId;
}

public function setCurrentShopId(int $shopId): void
{
$this->currentShopId = $shopId;
}
}
18 changes: 18 additions & 0 deletions tests/Unit/Internal/ContextStub.php
Original file line number Diff line number Diff line change
@@ -25,6 +25,7 @@ class ContextStub extends BasicContextStub implements ContextInterface
private $adminUserId;
private bool $productiveMode;
private $demoMode;
private int $currentShopId;

public function __construct()
{
@@ -39,6 +40,12 @@ public function __construct()
$this->skipLogTags = $context->getSkipLogTags();
$this->demoMode = $context->isShopInDemoMode();
$this->productiveMode = $context->isShopInProductiveMode();
$this->currentShopId = $context->getCurrentShopId();

$this->activeModuleServicesFilePath = $context->getActiveModuleServicesFilePath($this->getCurrentShopId());
$this->shopConfigurableServicesFilePath = $context->getShopConfigurableServicesFilePath(
$this->getCurrentShopId()
);
}

/**
@@ -213,4 +220,15 @@ public function setShopInDemoMode(bool $demoMode)
{
$this->demoMode = $demoMode;
}

public function getCurrentShopId(): int
{
return $this->currentShopId;
}

public function setCurrentShopId(int $shopId): void
{
$this->currentShopId = $shopId;
}

}

0 comments on commit 1039f3e

Please sign in to comment.