Skip to content

Commit

Permalink
OXDEV-7458 Cleanup duplicated basic context mock creation
Browse files Browse the repository at this point in the history
Signed-off-by: Anton Fedurtsya <[email protected]>
  • Loading branch information
Sieg committed Nov 17, 2023
1 parent e51b9c4 commit 78f3317
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 18 deletions.
5 changes: 1 addition & 4 deletions tests/Unit/Infrastructure/ModuleSettingRepositoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -228,12 +228,9 @@ public function testGetSettingsList(): void
])
);

$basicContext = $this->createMock(BasicContextInterface::class);
$basicContext->method('getCurrentShopId')->willReturn($shopId);

$moduleRepository = $this->getSut(
moduleConfigurationDao: $moduleConfigurationDao,
basicContext: $basicContext,
basicContext: $this->getBasicContextMock($shopId),
);

$this->assertSame(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

use OxidEsales\EshopCommunity\Internal\Framework\Config\Dao\ShopConfigurationSettingDaoInterface;
use OxidEsales\EshopCommunity\Internal\Framework\Config\DataObject\ShopConfigurationSetting;
use OxidEsales\EshopCommunity\Internal\Transition\Utility\BasicContextInterface;
use OxidEsales\GraphQL\ConfigurationAccess\Setting\Enum\FieldType;
use OxidEsales\GraphQL\ConfigurationAccess\Setting\Exception\WrongSettingTypeException;
use OxidEsales\GraphQL\ConfigurationAccess\Setting\Exception\WrongSettingValueException;
Expand All @@ -31,11 +30,8 @@ public function testGetShopSetting($method, $type, $possibleValue, $expectedResu
])
);

$basicContext = $this->createStub(BasicContextInterface::class);
$basicContext->method('getCurrentShopId')->willReturn($shopId);

$sut = $this->getSut(
basicContext: $basicContext,
basicContext: $this->getBasicContextMock($shopId),
shopSettingDao: $shopSettingDaoStub
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

use OxidEsales\EshopCommunity\Internal\Framework\Config\Dao\ShopConfigurationSettingDaoInterface;
use OxidEsales\EshopCommunity\Internal\Framework\Config\DataObject\ShopConfigurationSetting;
use OxidEsales\EshopCommunity\Internal\Transition\Utility\BasicContextInterface;
use OxidEsales\GraphQL\ConfigurationAccess\Setting\Enum\FieldType;

/**
Expand All @@ -20,14 +19,11 @@ public function testSetShopSetting(string $method, $settingValue, string $settin

$setting = $this->buildShopSettingStub($shopId, $settingType, $settingName, $settingValue);

$basicContextStub = $this->createStub(BasicContextInterface::class);
$basicContextStub->method('getCurrentShopId')->willReturn($shopId);

$shopSettingDaoSpy = $this->createMock(ShopConfigurationSettingDaoInterface::class);
$shopSettingDaoSpy->expects($this->once())->method('save')->with($setting);

$sut = $this->getSut(
basicContext: $basicContextStub,
basicContext: $this->getBasicContextMock($shopId),
shopSettingDao: $shopSettingDaoSpy
);

Expand Down
6 changes: 2 additions & 4 deletions tests/Unit/UnitTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,10 @@ protected function getSettingTypeList(): array
return [$intSetting, $stringSetting, $arraySetting];
}

protected function getBasicContextMock(int $shopId = 1): BasicContextInterface|MockObject
protected function getBasicContextMock(int $shopId = 1): BasicContextInterface
{
$basicContext = $this->createMock(BasicContextInterface::class);
$basicContext->expects($this->any())
->method('getCurrentShopId')
->willReturn($shopId);
$basicContext->method('getCurrentShopId')->willReturn($shopId);

return $basicContext;
}
Expand Down

0 comments on commit 78f3317

Please sign in to comment.