From 421da9480b30bacfd344e3c960114169d503df8b Mon Sep 17 00:00:00 2001 From: Anton Fedurtsya Date: Wed, 15 Nov 2023 16:54:42 +0200 Subject: [PATCH] OXDEV-7557 Refactor the getSettingList test to check if setting getter is called correctly Signed-off-by: Anton Fedurtsya --- .../ModuleSettingRepository.php | 1 - .../ModuleSettingRepositoryTest.php | 40 +++++++++++-------- 2 files changed, 24 insertions(+), 17 deletions(-) diff --git a/src/Setting/Infrastructure/ModuleSettingRepository.php b/src/Setting/Infrastructure/ModuleSettingRepository.php index c032d88..d18b50f 100644 --- a/src/Setting/Infrastructure/ModuleSettingRepository.php +++ b/src/Setting/Infrastructure/ModuleSettingRepository.php @@ -13,7 +13,6 @@ use OxidEsales\EshopCommunity\Internal\Framework\Module\Facade\ModuleSettingServiceInterface; use OxidEsales\EshopCommunity\Internal\Framework\Module\Setting\Setting; use OxidEsales\EshopCommunity\Internal\Transition\Utility\BasicContextInterface; -use TheCodingMachine\GraphQLite\Types\ID; final class ModuleSettingRepository implements ModuleSettingRepositoryInterface { diff --git a/tests/Unit/Infrastructure/ModuleSettingRepositoryTest.php b/tests/Unit/Infrastructure/ModuleSettingRepositoryTest.php index ef9518f..7528b3d 100644 --- a/tests/Unit/Infrastructure/ModuleSettingRepositoryTest.php +++ b/tests/Unit/Infrastructure/ModuleSettingRepositoryTest.php @@ -7,12 +7,9 @@ use OxidEsales\EshopCommunity\Internal\Framework\Module\Facade\ModuleSettingServiceInterface; use OxidEsales\EshopCommunity\Internal\Framework\Module\Setting\Setting; use OxidEsales\EshopCommunity\Internal\Transition\Utility\BasicContextInterface; -use OxidEsales\GraphQL\ConfigurationAccess\Setting\DataType\StringSetting; -use OxidEsales\GraphQL\ConfigurationAccess\Setting\Enum\FieldType; use OxidEsales\GraphQL\ConfigurationAccess\Setting\Infrastructure\ModuleSettingRepository; use OxidEsales\GraphQL\ConfigurationAccess\Tests\Unit\UnitTestCase; use Symfony\Component\String\UnicodeString; -use TheCodingMachine\GraphQLite\Types\ID; class ModuleSettingRepositoryTest extends UnitTestCase { @@ -213,25 +210,36 @@ public function testSaveCollectionSettingProxyingDataToShopService(): void public function testGetSettingsList(): void { - $intSetting = (new Setting())->setName('intSetting')->setType(FieldType::NUMBER); - $stringSetting = (new Setting())->setName('stringSetting')->setType(FieldType::STRING); - $arraySetting = (new Setting())->setName('arraySetting')->setType(FieldType::ARRAY); - - $moduleConfiguration = $this->createMock(ModuleConfiguration::class); - $moduleConfiguration->expects($this->once()) - ->method('getModuleSettings') - ->willReturn([$intSetting, $stringSetting, $arraySetting]); + $shopId = 3; + $moduleId = 'awesomeModule'; + + $response = [ + $this->createStub(Setting::class), + $this->createStub(Setting::class), + ]; + $moduleConfigurationDao = $this->createMock(ModuleConfigurationDaoInterface::class); $moduleConfigurationDao->expects($this->once()) ->method('get') - ->willReturn($moduleConfiguration); + ->with($moduleId, $shopId) + ->willReturn( + $this->createConfiguredMock(ModuleConfiguration::class, [ + 'getModuleSettings' => $response + ]) + ); + + $basicContext = $this->createMock(BasicContextInterface::class); + $basicContext->method('getCurrentShopId')->willReturn($shopId); $moduleRepository = $this->getSut( - $this->createMock(ModuleSettingServiceInterface::class), - $moduleConfigurationDao + moduleConfigurationDao: $moduleConfigurationDao, + basicContext: $basicContext, + ); + + $this->assertSame( + $response, + $moduleRepository->getSettingsList($moduleId) ); - $settingsList = $moduleRepository->getSettingsList('awesomeModule'); - $this->assertEquals([$intSetting, $stringSetting, $arraySetting], $settingsList); } public function getSut(