From 164151d6ffa5695c61d89afe065d6b14b0546e9b Mon Sep 17 00:00:00 2001 From: Anton Fedurtsya Date: Wed, 15 Nov 2023 14:52:04 +0200 Subject: [PATCH] OXDEV-7557 Cleanup using the ID and Graphql types in modules setting repository getters Signed-off-by: Anton Fedurtsya --- .../ModuleSettingRepository.php | 39 +-- .../ModuleSettingRepositoryInterface.php | 14 +- src/Setting/Service/ModuleSettingService.php | 25 +- .../ModuleSettingRepositoryTest.php | 228 +++++++++--------- .../Unit/Service/ModuleSettingServiceTest.php | 94 +++++--- 5 files changed, 211 insertions(+), 189 deletions(-) diff --git a/src/Setting/Infrastructure/ModuleSettingRepository.php b/src/Setting/Infrastructure/ModuleSettingRepository.php index 351a814..20f3f67 100644 --- a/src/Setting/Infrastructure/ModuleSettingRepository.php +++ b/src/Setting/Infrastructure/ModuleSettingRepository.php @@ -13,10 +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 OxidEsales\GraphQL\ConfigurationAccess\Setting\DataType\BooleanSetting; -use OxidEsales\GraphQL\ConfigurationAccess\Setting\DataType\FloatSetting; -use OxidEsales\GraphQL\ConfigurationAccess\Setting\DataType\IntegerSetting; -use OxidEsales\GraphQL\ConfigurationAccess\Setting\DataType\StringSetting; use TheCodingMachine\GraphQLite\Types\ID; final class ModuleSettingRepository implements ModuleSettingRepositoryInterface @@ -28,44 +24,29 @@ public function __construct( ) { } - public function getIntegerSetting(ID $name, string $moduleId): IntegerSetting + public function getIntegerSetting(string $name, string $moduleId): int { - $name = $name->val(); - $value = $this->moduleSettingService->getInteger($name, $moduleId); - - return new IntegerSetting(new ID($name), $value); + return $this->moduleSettingService->getInteger($name, $moduleId); } - public function getFloatSetting(ID $name, string $moduleId): FloatSetting + public function getFloatSetting(string $name, string $moduleId): float { - $name = $name->val(); - $value = $this->moduleSettingService->getFloat($name, $moduleId); - - return new FloatSetting(new ID($name), $value); + return $this->moduleSettingService->getFloat($name, $moduleId); } - public function getBooleanSetting(ID $name, string $moduleId): BooleanSetting + public function getBooleanSetting(string $name, string $moduleId): bool { - $name = $name->val(); - $value = $this->moduleSettingService->getBoolean($name, $moduleId); - - return new BooleanSetting(new ID($name), $value); + return $this->moduleSettingService->getBoolean($name, $moduleId); } - public function getStringSetting(ID $name, string $moduleId): StringSetting + public function getStringSetting(string $name, string $moduleId): string { - $name = $name->val(); - $value = $this->moduleSettingService->getString($name, $moduleId); - - return new StringSetting(new ID($name), (string)$value); + return (string)$this->moduleSettingService->getString($name, $moduleId); } - public function getCollectionSetting(ID $name, string $moduleId): StringSetting + public function getCollectionSetting(string $name, string $moduleId): array { - $name = $name->val(); - $value = $this->moduleSettingService->getCollection($name, $moduleId); - - return new StringSetting(new ID($name), json_encode($value)); + return $this->moduleSettingService->getCollection($name, $moduleId); } public function saveIntegerSetting(ID $name, int $value, string $moduleId): void diff --git a/src/Setting/Infrastructure/ModuleSettingRepositoryInterface.php b/src/Setting/Infrastructure/ModuleSettingRepositoryInterface.php index 84970e7..2e00e19 100644 --- a/src/Setting/Infrastructure/ModuleSettingRepositoryInterface.php +++ b/src/Setting/Infrastructure/ModuleSettingRepositoryInterface.php @@ -3,23 +3,19 @@ namespace OxidEsales\GraphQL\ConfigurationAccess\Setting\Infrastructure; use OxidEsales\EshopCommunity\Internal\Framework\Module\Setting\Setting; -use OxidEsales\GraphQL\ConfigurationAccess\Setting\DataType\BooleanSetting; -use OxidEsales\GraphQL\ConfigurationAccess\Setting\DataType\FloatSetting; -use OxidEsales\GraphQL\ConfigurationAccess\Setting\DataType\IntegerSetting; -use OxidEsales\GraphQL\ConfigurationAccess\Setting\DataType\StringSetting; use TheCodingMachine\GraphQLite\Types\ID; interface ModuleSettingRepositoryInterface { - public function getIntegerSetting(ID $name, string $moduleId): IntegerSetting; + public function getIntegerSetting(string $name, string $moduleId): int; - public function getFloatSetting(ID $name, string $moduleId): FloatSetting; + public function getFloatSetting(string $name, string $moduleId): float; - public function getBooleanSetting(ID $name, string $moduleId): BooleanSetting; + public function getBooleanSetting(string $name, string $moduleId): bool; - public function getStringSetting(ID $name, string $moduleId): StringSetting; + public function getStringSetting(string $name, string $moduleId): string; - public function getCollectionSetting(ID $name, string $moduleId): StringSetting; + public function getCollectionSetting(string $name, string $moduleId): array; public function saveIntegerSetting(ID $name, int $value, string $moduleId): void; diff --git a/src/Setting/Service/ModuleSettingService.php b/src/Setting/Service/ModuleSettingService.php index fa9178d..0765bc6 100644 --- a/src/Setting/Service/ModuleSettingService.php +++ b/src/Setting/Service/ModuleSettingService.php @@ -28,27 +28,42 @@ public function __construct( public function getIntegerSetting(ID $name, string $moduleId): IntegerSetting { - return $this->moduleSettingRepository->getIntegerSetting($name, $moduleId); + return new IntegerSetting( + $name, + $this->moduleSettingRepository->getIntegerSetting((string)$name, $moduleId) + ); } public function getFloatSetting(ID $name, string $moduleId): FloatSetting { - return $this->moduleSettingRepository->getFloatSetting($name, $moduleId); + return new FloatSetting( + $name, + $this->moduleSettingRepository->getFloatSetting((string)$name, $moduleId) + ); } public function getBooleanSetting(ID $name, string $moduleId): BooleanSetting { - return $this->moduleSettingRepository->getBooleanSetting($name, $moduleId); + return new BooleanSetting( + $name, + $this->moduleSettingRepository->getBooleanSetting((string)$name, $moduleId) + ); } public function getStringSetting(ID $name, string $moduleId): StringSetting { - return $this->moduleSettingRepository->getStringSetting($name, $moduleId); + return new StringSetting( + $name, + $this->moduleSettingRepository->getStringSetting((string)$name, $moduleId) + ); } public function getCollectionSetting(ID $name, string $moduleId): StringSetting { - return $this->moduleSettingRepository->getCollectionSetting($name, $moduleId); + return new StringSetting( + $name, + json_encode($this->moduleSettingRepository->getCollectionSetting((string)$name, $moduleId)) + ); } public function changeIntegerSetting(ID $name, int $value, string $moduleId): IntegerSetting diff --git a/tests/Unit/Infrastructure/ModuleSettingRepositoryTest.php b/tests/Unit/Infrastructure/ModuleSettingRepositoryTest.php index 3035a26..2040a67 100644 --- a/tests/Unit/Infrastructure/ModuleSettingRepositoryTest.php +++ b/tests/Unit/Infrastructure/ModuleSettingRepositoryTest.php @@ -7,10 +7,10 @@ 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 PHPUnit\Framework\MockObject\MockObject; use Symfony\Component\String\UnicodeString; use TheCodingMachine\GraphQLite\Types\ID; @@ -18,116 +18,121 @@ class ModuleSettingRepositoryTest extends UnitTestCase { public function testGetModuleSettingInteger(): void { - $serviceIntegerSetting = $this->getIntegerSetting(); - - $moduleSettingService = $this->getModuleSettingServiceMock(); - $moduleSettingService->expects($this->once()) - ->method('getInteger') - ->willReturn(123); - - $moduleRepository = $this->getModuleSettingRepository( - $moduleSettingService, - $this->getModuleConfigurationDaoMock() + $name = 'integerSetting'; + $moduleId = 'awesomeModule'; + + $shopServiceReturn = 123; + $moduleRepository = $this->getSut( + moduleSettingService: $this->getShopModuleSettingServiceMock( + 'getInteger', + $name, + $moduleId, + $shopServiceReturn + ) ); - $name = new ID('integerSetting'); - $integerSetting = $moduleRepository->getIntegerSetting($name, 'awesomeModule'); - - $this->assertEquals($serviceIntegerSetting, $integerSetting); + $this->assertEquals( + $shopServiceReturn, + $moduleRepository->getIntegerSetting($name, $moduleId) + ); } public function testGetModuleSettingFloat(): void { - $serviceFloatSetting = $this->getFloatSetting(); - - $moduleSettingService = $this->getModuleSettingServiceMock(); - $moduleSettingService->expects($this->once()) - ->method('getFloat') - ->willReturn(1.23); - - $moduleRepository = $this->getModuleSettingRepository( - $moduleSettingService, - $this->getModuleConfigurationDaoMock() + $name = 'floatSetting'; + $shopServiceReturn = 1.23; + $moduleId = 'awesomeModule'; + + $moduleRepository = $this->getSut( + moduleSettingService: $this->getShopModuleSettingServiceMock( + 'getFloat', + $name, + $moduleId, + $shopServiceReturn + ), ); - $name = new ID('floatSetting'); - $floatSetting = $moduleRepository->getFloatSetting($name, 'awesomeModule'); - - $this->assertEquals($serviceFloatSetting, $floatSetting); + $this->assertEquals( + $shopServiceReturn, + $moduleRepository->getFloatSetting($name, $moduleId) + ); } public function testGetModuleSettingBoolean(): void { - $serviceBooleanSetting = $this->getNegativeBooleanSetting(); - - $moduleSettingService = $this->getModuleSettingServiceMock(); - $moduleSettingService->expects($this->once()) - ->method('getBoolean') - ->willReturn(false); - - $moduleRepository = $this->getModuleSettingRepository( - $moduleSettingService, - $this->getModuleConfigurationDaoMock() + $name = 'booleanSetting'; + $shopServiceReturn = false; + $moduleId = 'awesomeModule'; + + $moduleRepository = $this->getSut( + moduleSettingService: $this->getShopModuleSettingServiceMock( + 'getBoolean', + $name, + $moduleId, + $shopServiceReturn + ), ); - $name = new ID('booleanSetting'); - $booleanSetting = $moduleRepository->getBooleanSetting($name, 'awesomeModule'); - - $this->assertEquals($serviceBooleanSetting, $booleanSetting); + $this->assertEquals( + $shopServiceReturn, + $moduleRepository->getBooleanSetting($name, $moduleId) + ); } public function testGetModuleSettingString(): void { - $serviceStringSetting = $this->getStringSetting(); - - $moduleSettingService = $this->getModuleSettingServiceMock(); - $moduleSettingService->expects($this->once()) - ->method('getString') - ->willReturn(new UnicodeString('default')); - - $moduleRepository = $this->getModuleSettingRepository( - $moduleSettingService, - $this->getModuleConfigurationDaoMock() + $name = 'stringSetting'; + $moduleId = 'awesomeModule'; + $repositoryReturn = 'default'; + + $moduleRepository = $this->getSut( + moduleSettingService: $this->getShopModuleSettingServiceMock( + 'getString', + $name, + $moduleId, + new UnicodeString($repositoryReturn) + ), ); - $name = new ID('stringSetting'); - $stringSetting = $moduleRepository->getStringSetting($name, 'awesomeModule'); - - $this->assertEquals($serviceStringSetting, $stringSetting); + $this->assertEquals( + $repositoryReturn, + $moduleRepository->getStringSetting($name, $moduleId) + ); } public function testGetModuleSettingCollection(): void { - $serviceCollectionSetting = $this->getCollectionSetting(); - - $moduleSettingService = $this->getModuleSettingServiceMock(); - $moduleSettingService->expects($this->once()) - ->method('getCollection') - ->willReturn(['nice', 'values']); - - $moduleRepository = $this->getModuleSettingRepository( - $moduleSettingService, - $this->getModuleConfigurationDaoMock() + $name = 'arraySetting'; + $moduleId = 'awesomeModule'; + $repositoryReturn = ['nice', 'values']; + + $moduleRepository = $this->getSut( + moduleSettingService: $this->getShopModuleSettingServiceMock( + 'getCollection', + $name, + $moduleId, + $repositoryReturn + ), ); - $name = new ID('arraySetting'); - $collectionSetting = $moduleRepository->getCollectionSetting($name, 'awesomeModule'); - - $this->assertEquals($serviceCollectionSetting, $collectionSetting); + $this->assertEquals( + $repositoryReturn, + $moduleRepository->getCollectionSetting($name, $moduleId) + ); } public function testChangeModuleSettingInteger(): void { $name = new ID('intSetting'); - $moduleSettingService = $this->getModuleSettingServiceMock(); + $moduleSettingService = $this->createMock(ModuleSettingServiceInterface::class); $moduleSettingService->expects($this->once()) ->method('saveInteger') ->with($name->val(), 123, 'awesomeModule'); - $moduleRepository = $this->getModuleSettingRepository( + $moduleRepository = $this->getSut( $moduleSettingService, - $this->getModuleConfigurationDaoMock() + $this->createMock(ModuleConfigurationDaoInterface::class) ); $moduleRepository->saveIntegerSetting($name, 123, 'awesomeModule'); @@ -137,14 +142,14 @@ public function testChangeModuleSettingFloat(): void { $name = new ID('floatSetting'); - $moduleSettingService = $this->getModuleSettingServiceMock(); + $moduleSettingService = $this->createMock(ModuleSettingServiceInterface::class); $moduleSettingService->expects($this->once()) ->method('saveFloat') ->with($name->val(), 1.23, 'awesomeModule'); - $moduleRepository = $this->getModuleSettingRepository( + $moduleRepository = $this->getSut( $moduleSettingService, - $this->getModuleConfigurationDaoMock() + $this->createMock(ModuleConfigurationDaoInterface::class) ); $moduleRepository->saveFloatSetting($name, 1.23, 'awesomeModule'); @@ -155,14 +160,14 @@ public function testChangeModuleSettingBoolean(): void $name = new ID('boolSetting'); $value = false; - $moduleSettingService = $this->getModuleSettingServiceMock(); + $moduleSettingService = $this->createMock(ModuleSettingServiceInterface::class); $moduleSettingService->expects($this->once()) ->method('saveBoolean') ->with($name->val(), $value, 'awesomeModule'); - $moduleRepository = $this->getModuleSettingRepository( + $moduleRepository = $this->getSut( $moduleSettingService, - $this->getModuleConfigurationDaoMock() + $this->createMock(ModuleConfigurationDaoInterface::class) ); $moduleRepository->saveBooleanSetting($name, $value, 'awesomeModule'); @@ -173,14 +178,14 @@ public function testChangeModuleSettingString(): void $name = new ID('stringSetting'); $value = 'default'; - $moduleSettingService = $this->getModuleSettingServiceMock(); + $moduleSettingService = $this->createMock(ModuleSettingServiceInterface::class); $moduleSettingService->expects($this->once()) ->method('saveString') ->with($name->val(), $value, 'awesomeModule'); - $moduleRepository = $this->getModuleSettingRepository( + $moduleRepository = $this->getSut( $moduleSettingService, - $this->getModuleConfigurationDaoMock() + $this->createMock(ModuleConfigurationDaoInterface::class) ); $moduleRepository->saveStringSetting($name, $value, 'awesomeModule'); @@ -191,14 +196,14 @@ public function testChangeModuleSettingCollection(): void $name = new ID('boolSetting'); $value = [3, 'interesting', 'values']; - $moduleSettingService = $this->getModuleSettingServiceMock(); + $moduleSettingService = $this->createMock(ModuleSettingServiceInterface::class); $moduleSettingService->expects($this->once()) ->method('saveCollection') ->with($name->val(), $value, 'awesomeModule'); - $moduleRepository = $this->getModuleSettingRepository( + $moduleRepository = $this->getSut( $moduleSettingService, - $this->getModuleConfigurationDaoMock() + $this->createMock(ModuleConfigurationDaoInterface::class) ); $moduleRepository->saveCollectionSetting($name, $value, 'awesomeModule'); @@ -214,43 +219,44 @@ public function testGetSettingsList(): void $moduleConfiguration->expects($this->once()) ->method('getModuleSettings') ->willReturn([$intSetting, $stringSetting, $arraySetting]); - $moduleConfigurationDao = $this->getModuleConfigurationDaoMock(); + $moduleConfigurationDao = $this->createMock(ModuleConfigurationDaoInterface::class); $moduleConfigurationDao->expects($this->once()) ->method('get') ->willReturn($moduleConfiguration); - $moduleRepository = $this->getModuleSettingRepository( - $this->getModuleSettingServiceMock(), + $moduleRepository = $this->getSut( + $this->createMock(ModuleSettingServiceInterface::class), $moduleConfigurationDao ); $settingsList = $moduleRepository->getSettingsList('awesomeModule'); $this->assertEquals([$intSetting, $stringSetting, $arraySetting], $settingsList); } - /** - * @return ModuleConfigurationDaoInterface|(ModuleConfigurationDaoInterface&MockObject)|MockObject - */ - public function getModuleConfigurationDaoMock(): ModuleConfigurationDaoInterface|MockObject - { - return $this->createMock(ModuleConfigurationDaoInterface::class); - } + public function getSut( + ?ModuleSettingServiceInterface $moduleSettingService = null, + ?ModuleConfigurationDaoInterface $moduleConfigurationDao = null, + ?BasicContextInterface $basicContext = null, + ): ModuleSettingRepository { + $moduleConfigurationDao = $moduleConfigurationDao ?? $this->createStub(ModuleConfigurationDaoInterface::class); - /** - * @return ModuleSettingServiceInterface|(ModuleSettingServiceInterface&MockObject)|MockObject - */ - public function getModuleSettingServiceMock(): MockObject|ModuleSettingServiceInterface - { - return $this->createMock(ModuleSettingServiceInterface::class); + return new ModuleSettingRepository( + moduleSettingService: $moduleSettingService ?? $this->createStub(ModuleSettingServiceInterface::class), + moduleConfigurationDao: $moduleConfigurationDao, + basicContext: $basicContext ?? $this->createStub(BasicContextInterface::class) + ); } - /** - * @return ModuleSettingRepository - */ - public function getModuleSettingRepository( - ModuleSettingServiceInterface $moduleSettingService, - ModuleConfigurationDaoInterface|MockObject $moduleConfigurationDao - ): ModuleSettingRepository { - $basicContext = $this->createMock(BasicContextInterface::class); - return new ModuleSettingRepository($moduleSettingService, $moduleConfigurationDao, $basicContext); + private function getShopModuleSettingServiceMock( + string $methodName, + string $name, + string $moduleId, + $shopServiceReturn + ): ModuleSettingServiceInterface { + $moduleSettingService = $this->createMock(ModuleSettingServiceInterface::class); + $moduleSettingService->expects($this->once()) + ->method($methodName) + ->with($name, $moduleId) + ->willReturn($shopServiceReturn); + return $moduleSettingService; } } diff --git a/tests/Unit/Service/ModuleSettingServiceTest.php b/tests/Unit/Service/ModuleSettingServiceTest.php index 9229b02..6722bbb 100644 --- a/tests/Unit/Service/ModuleSettingServiceTest.php +++ b/tests/Unit/Service/ModuleSettingServiceTest.php @@ -3,6 +3,10 @@ namespace OxidEsales\GraphQL\ConfigurationAccess\Tests\Unit\Service; use OxidEsales\EshopCommunity\Internal\Framework\Module\Setting\Setting; +use OxidEsales\GraphQL\ConfigurationAccess\Setting\DataType\BooleanSetting; +use OxidEsales\GraphQL\ConfigurationAccess\Setting\DataType\FloatSetting; +use OxidEsales\GraphQL\ConfigurationAccess\Setting\DataType\IntegerSetting; +use OxidEsales\GraphQL\ConfigurationAccess\Setting\DataType\StringSetting; use OxidEsales\GraphQL\ConfigurationAccess\Setting\Enum\FieldType; use OxidEsales\GraphQL\ConfigurationAccess\Setting\Exception\InvalidCollection; use OxidEsales\GraphQL\ConfigurationAccess\Setting\Infrastructure\ModuleSettingRepositoryInterface; @@ -14,87 +18,107 @@ class ModuleSettingServiceTest extends UnitTestCase { public function testGetModuleSettingInteger(): void { - $serviceIntegerSetting = $this->getIntegerSetting(); + $name = 'integerSetting'; + $moduleId = 'awesomeModule'; + $repositoryResponse = 123; $repository = $this->createMock(ModuleSettingRepositoryInterface::class); $repository->expects($this->once()) ->method('getIntegerSetting') - ->willReturn($serviceIntegerSetting); - - $settingService = new ModuleSettingService($repository); + ->with($name, $moduleId) + ->willReturn($repositoryResponse); - $nameID = new ID('integerSetting'); - $integerSetting = $settingService->getIntegerSetting($nameID, 'awesomeModule'); + $sut = new ModuleSettingService($repository); - $this->assertSame($serviceIntegerSetting, $integerSetting); + $nameID = new ID($name); + $this->assertEquals( + new IntegerSetting($nameID, $repositoryResponse), + $sut->getIntegerSetting($nameID, $moduleId) + ); } public function testGetModuleSettingFloat(): void { - $serviceFloatSetting = $this->getFloatSetting(); + $name = 'floatSetting'; + $moduleId = 'awesomeModule'; + $repositoryResponse = 1.23; $repository = $this->createMock(ModuleSettingRepositoryInterface::class); $repository->expects($this->once()) ->method('getFloatSetting') - ->willReturn($serviceFloatSetting); + ->with($name, $moduleId) + ->willReturn($repositoryResponse); - $settingService = new ModuleSettingService($repository); - - $nameID = new ID('floatSetting'); - $floatSetting = $settingService->getFloatSetting($nameID, 'awesomeModule'); + $sut = new ModuleSettingService($repository); - $this->assertSame($serviceFloatSetting, $floatSetting); + $nameID = new ID($name); + $this->assertEquals( + new FloatSetting($nameID, $repositoryResponse), + $sut->getFloatSetting($nameID, $moduleId) + ); } public function testGetModuleSettingBoolean(): void { - $serviceBooleanSetting = $this->getNegativeBooleanSetting(); + $name = 'booleanSetting'; + $moduleId = 'awesomeModule'; + $repositoryResponse = false; $repository = $this->createMock(ModuleSettingRepositoryInterface::class); $repository->expects($this->once()) ->method('getBooleanSetting') - ->willReturn($serviceBooleanSetting); - - $settingService = new ModuleSettingService($repository); + ->with($name, $moduleId) + ->willReturn($repositoryResponse); - $nameID = new ID('booleanSetting'); - $booleanSetting = $settingService->getBooleanSetting($nameID, 'awesomeModule'); + $sut = new ModuleSettingService($repository); - $this->assertSame($serviceBooleanSetting, $booleanSetting); + $nameID = new ID($name); + $this->assertEquals( + new BooleanSetting($nameID, $repositoryResponse), + $sut->getBooleanSetting($nameID, $moduleId) + ); } public function testGetModuleSettingString(): void { - $serviceStringSetting = $this->getStringSetting(); + $name = 'stringSetting'; + $moduleId = 'awesomeModule'; + $repositoryResponse = 'default'; $repository = $this->createMock(ModuleSettingRepositoryInterface::class); $repository->expects($this->once()) ->method('getStringSetting') - ->willReturn($serviceStringSetting); + ->with($name, $moduleId) + ->willReturn($repositoryResponse); - $settingService = new ModuleSettingService($repository); - - $nameID = new ID('stringSetting'); - $stringSetting = $settingService->getStringSetting($nameID, 'awesomeModule'); + $sut = new ModuleSettingService($repository); - $this->assertSame($serviceStringSetting, $stringSetting); + $nameID = new ID($name); + $this->assertEquals( + new StringSetting($nameID, $repositoryResponse), + $sut->getStringSetting($nameID, $moduleId) + ); } public function testGetModuleSettingCollection(): void { - $serviceCollectionSetting = $this->getCollectionSetting(); + $name = 'arraySetting'; + $moduleId = 'awesomeModule'; + $repositoryResponse = ['nice', 'values']; $repository = $this->createMock(ModuleSettingRepositoryInterface::class); $repository->expects($this->once()) ->method('getCollectionSetting') - ->willReturn($serviceCollectionSetting); + ->with($name, $moduleId) + ->willReturn($repositoryResponse); - $settingService = new ModuleSettingService($repository); - - $nameID = new ID('arraySetting'); - $collectionSetting = $settingService->getCollectionSetting($nameID, 'awesomeModule'); + $sut = new ModuleSettingService($repository); - $this->assertSame($serviceCollectionSetting, $collectionSetting); + $nameID = new ID($name); + $this->assertEquals( + new StringSetting($nameID, json_encode($repositoryResponse)), + $sut->getCollectionSetting($nameID, $moduleId) + ); } public function testChangeModuleSettingInteger(): void