From 870c76ce77d3452391b0247d30cc439bb98d8d98 Mon Sep 17 00:00:00 2001 From: Anton Fedurtsya Date: Wed, 6 Dec 2023 07:53:10 +0200 Subject: [PATCH] OXDEV-7557 Rename JsonServiceInterface As JsonServiceInterface is too specific name for the action. There could be different implementations for this, and one of them is Json Signed-off-by: Anton Fedurtsya --- .../CollectionEncodingServiceInterface.php | 15 +++++++++++++ ....php => JsonCollectionEncodingService.php} | 6 ++--- src/Setting/Service/JsonServiceInterface.php | 15 ------------- src/Setting/Service/ModuleSettingService.php | 6 ++--- src/Setting/Service/ShopSettingService.php | 10 ++++----- src/Setting/Service/ThemeSettingService.php | 6 ++--- src/Setting/services.yaml | 4 ++-- ... => JsonCollectionEncodingServiceTest.php} | 22 +++++++++---------- .../Unit/Service/ModuleSettingServiceTest.php | 16 +++++++------- tests/Unit/Service/ShopSettingServiceTest.php | 18 +++++++-------- .../Unit/Service/ThemeSettingServiceTest.php | 6 ++--- tests/Unit/UnitTestCase.php | 8 +++---- 12 files changed, 66 insertions(+), 66 deletions(-) create mode 100644 src/Setting/Service/CollectionEncodingServiceInterface.php rename src/Setting/Service/{JsonService.php => JsonCollectionEncodingService.php} (81%) delete mode 100644 src/Setting/Service/JsonServiceInterface.php rename tests/Unit/Service/{JsonServiceTest.php => JsonCollectionEncodingServiceTest.php} (69%) diff --git a/src/Setting/Service/CollectionEncodingServiceInterface.php b/src/Setting/Service/CollectionEncodingServiceInterface.php new file mode 100644 index 0000000..5a141a2 --- /dev/null +++ b/src/Setting/Service/CollectionEncodingServiceInterface.php @@ -0,0 +1,15 @@ +jsonService->jsonEncodeArray($collection) + $this->jsonService->encodeArrayToString($collection) ); } @@ -105,7 +105,7 @@ public function changeCollectionSetting(string $name, string $value, string $mod { $this->moduleSettingService->saveCollection( $name, - $this->jsonService->jsonDecodeCollection($value), + $this->jsonService->decodeStringCollectionToArray($value), $moduleId ); diff --git a/src/Setting/Service/ShopSettingService.php b/src/Setting/Service/ShopSettingService.php index 243eaed..e245262 100644 --- a/src/Setting/Service/ShopSettingService.php +++ b/src/Setting/Service/ShopSettingService.php @@ -20,7 +20,7 @@ final class ShopSettingService implements ShopSettingServiceInterface { public function __construct( private ShopSettingRepositoryInterface $shopSettingRepository, - private JsonServiceInterface $jsonService, + private CollectionEncodingServiceInterface $jsonService, ) { } @@ -57,7 +57,7 @@ public function getSelectSetting(string $name): StringSetting public function getCollectionSetting(string $name): StringSetting { $collectionString = $this->shopSettingRepository->getCollection($name); - $collectionEncodingResult = $this->jsonService->jsonEncodeArray($collectionString); + $collectionEncodingResult = $this->jsonService->encodeArrayToString($collectionString); return new StringSetting($name, $collectionEncodingResult); } @@ -65,7 +65,7 @@ public function getCollectionSetting(string $name): StringSetting public function getAssocCollectionSetting(string $name): StringSetting { $assocCollectionString = $this->shopSettingRepository->getAssocCollection($name); - $assocCollectionEncodingResult = $this->jsonService->jsonEncodeArray($assocCollectionString); + $assocCollectionEncodingResult = $this->jsonService->encodeArrayToString($assocCollectionString); return new StringSetting($name, $assocCollectionEncodingResult); } @@ -123,7 +123,7 @@ public function changeCollectionSetting(string $name, string $value): StringSett { $this->shopSettingRepository->saveCollectionSetting( $name, - $this->jsonService->jsonDecodeCollection($value) + $this->jsonService->decodeStringCollectionToArray($value) ); return $this->getCollectionSetting($name); @@ -133,7 +133,7 @@ public function changeAssocCollectionSetting(string $name, string $value): Strin { $this->shopSettingRepository->saveAssocCollectionSetting( $name, - $this->jsonService->jsonDecodeCollection($value) + $this->jsonService->decodeStringCollectionToArray($value) ); return $this->getAssocCollectionSetting($name); diff --git a/src/Setting/Service/ThemeSettingService.php b/src/Setting/Service/ThemeSettingService.php index 2b088e9..6a742fe 100644 --- a/src/Setting/Service/ThemeSettingService.php +++ b/src/Setting/Service/ThemeSettingService.php @@ -21,7 +21,7 @@ final class ThemeSettingService implements ThemeSettingServiceInterface { public function __construct( private ThemeSettingRepositoryInterface $themeSettingRepository, - private JsonServiceInterface $jsonService, + private CollectionEncodingServiceInterface $jsonService, ) { } @@ -58,7 +58,7 @@ public function getSelectSetting(string $name, string $themeId): StringSetting public function getCollectionSetting(string $name, string $themeId): StringSetting { $collection = $this->themeSettingRepository->getCollection($name, $themeId); - $collectionEncodingResult = $this->jsonService->jsonEncodeArray($collection); + $collectionEncodingResult = $this->jsonService->encodeArrayToString($collection); return new StringSetting($name, $collectionEncodingResult); } @@ -66,7 +66,7 @@ public function getCollectionSetting(string $name, string $themeId): StringSetti public function getAssocCollectionSetting(string $name, string $themeId): StringSetting { $assocCollection = $this->themeSettingRepository->getAssocCollection($name, $themeId); - $collectionEncodingResult = $this->jsonService->jsonEncodeArray($assocCollection); + $collectionEncodingResult = $this->jsonService->encodeArrayToString($assocCollection); return new StringSetting($name, $collectionEncodingResult); } diff --git a/src/Setting/services.yaml b/src/Setting/services.yaml index efcba98..30807f4 100644 --- a/src/Setting/services.yaml +++ b/src/Setting/services.yaml @@ -22,5 +22,5 @@ services: OxidEsales\GraphQL\ConfigurationAccess\Setting\Infrastructure\ShopSettingRepositoryInterface: class: OxidEsales\GraphQL\ConfigurationAccess\Setting\Infrastructure\ShopSettingRepository - OxidEsales\GraphQL\ConfigurationAccess\Setting\Service\JsonServiceInterface: - class: OxidEsales\GraphQL\ConfigurationAccess\Setting\Service\JsonService + OxidEsales\GraphQL\ConfigurationAccess\Setting\Service\CollectionEncodingServiceInterface: + class: OxidEsales\GraphQL\ConfigurationAccess\Setting\Service\JsonCollectionEncodingService diff --git a/tests/Unit/Service/JsonServiceTest.php b/tests/Unit/Service/JsonCollectionEncodingServiceTest.php similarity index 69% rename from tests/Unit/Service/JsonServiceTest.php rename to tests/Unit/Service/JsonCollectionEncodingServiceTest.php index 938a05a..8d25bd6 100644 --- a/tests/Unit/Service/JsonServiceTest.php +++ b/tests/Unit/Service/JsonCollectionEncodingServiceTest.php @@ -11,37 +11,37 @@ use OxidEsales\GraphQL\ConfigurationAccess\Setting\Exception\CollectionEncodingException; use OxidEsales\GraphQL\ConfigurationAccess\Setting\Exception\InvalidCollectionException; -use OxidEsales\GraphQL\ConfigurationAccess\Setting\Service\JsonService; +use OxidEsales\GraphQL\ConfigurationAccess\Setting\Service\JsonCollectionEncodingService; use PHPUnit\Framework\TestCase; /** - * @covers \OxidEsales\GraphQL\ConfigurationAccess\Setting\Service\JsonService + * @covers \OxidEsales\GraphQL\ConfigurationAccess\Setting\Service\JsonCollectionEncodingService */ -class JsonServiceTest extends TestCase +class JsonCollectionEncodingServiceTest extends TestCase { public function testJsonEncodeArray(): void { - $sut = new JsonService(); + $sut = new JsonCollectionEncodingService(); $value = ['some' => 'value']; - $this->assertSame('{"some":"value"}', $sut->jsonEncodeArray($value)); + $this->assertSame('{"some":"value"}', $sut->encodeArrayToString($value)); } public function testJsonEncodeArrayException(): void { - $sut = new JsonService(); + $sut = new JsonCollectionEncodingService(); $value = [&$value]; $this->expectException(CollectionEncodingException::class); - $sut->jsonEncodeArray($value); + $sut->encodeArrayToString($value); } /** @dataProvider jsonDecodeCollectionDataProvider */ public function testJsonDecodeCollection(string $value, array $expectedResult): void { - $sut = new JsonService(); + $sut = new JsonCollectionEncodingService(); - $this->assertEquals($expectedResult, $sut->jsonDecodeCollection($value)); + $this->assertEquals($expectedResult, $sut->decodeStringCollectionToArray($value)); } public function jsonDecodeCollectionDataProvider(): \Generator @@ -64,10 +64,10 @@ public function jsonDecodeCollectionDataProvider(): \Generator public function testJsonDecodeCollectionException(): void { - $sut = new JsonService(); + $sut = new JsonCollectionEncodingService(); $value = '[2, "values"'; $this->expectException(InvalidCollectionException::class); - $sut->jsonDecodeCollection($value); + $sut->decodeStringCollectionToArray($value); } } diff --git a/tests/Unit/Service/ModuleSettingServiceTest.php b/tests/Unit/Service/ModuleSettingServiceTest.php index 0be0214..cfa12fe 100644 --- a/tests/Unit/Service/ModuleSettingServiceTest.php +++ b/tests/Unit/Service/ModuleSettingServiceTest.php @@ -20,7 +20,7 @@ use OxidEsales\GraphQL\ConfigurationAccess\Setting\DataType\StringSetting; use OxidEsales\GraphQL\ConfigurationAccess\Setting\Enum\FieldType; use OxidEsales\GraphQL\ConfigurationAccess\Setting\Infrastructure\ModuleSettingRepositoryInterface; -use OxidEsales\GraphQL\ConfigurationAccess\Setting\Service\JsonServiceInterface; +use OxidEsales\GraphQL\ConfigurationAccess\Setting\Service\CollectionEncodingServiceInterface; use OxidEsales\GraphQL\ConfigurationAccess\Setting\Service\ModuleSettingService; use OxidEsales\GraphQL\ConfigurationAccess\Tests\Unit\UnitTestCase; use Symfony\Component\String\UnicodeString; @@ -121,8 +121,8 @@ public function testGetModuleSettingCollection(): void $shopServiceReturn = ['nice', 'values']; $encoderResponse = 'encoderResponse'; - $encoder = $this->createMock(JsonServiceInterface::class); - $encoder->method('jsonEncodeArray') + $encoder = $this->createMock(CollectionEncodingServiceInterface::class); + $encoder->method('encodeArrayToString') ->with($shopServiceReturn) ->willReturn($encoderResponse); @@ -257,11 +257,11 @@ public function testChangeModuleSettingCollection(): void $decodedValue = ['decodedCollectionValue']; $encoderResponse = 'encoderResponse'; - $encoder = $this->createMock(JsonServiceInterface::class); - $encoder->method('jsonEncodeArray') + $encoder = $this->createMock(CollectionEncodingServiceInterface::class); + $encoder->method('encodeArrayToString') ->with($repositoryValue) ->willReturn($encoderResponse); - $encoder->method('jsonDecodeCollection') + $encoder->method('decodeStringCollectionToArray') ->with($callValue) ->willReturn($decodedValue); @@ -314,13 +314,13 @@ public function testListModuleSettings(): void } private function getSut( - ?JsonServiceInterface $jsonService = null, + ?CollectionEncodingServiceInterface $jsonService = null, ?ModuleSettingServiceInterface $moduleSettingService = null, ?ModuleConfigurationDaoInterface $moduleConfigDao = null, ?BasicContextInterface $basicContext = null, ): ModuleSettingService { return new ModuleSettingService( - jsonService: $jsonService ?? $this->createStub(JsonServiceInterface::class), + jsonService: $jsonService ?? $this->createStub(CollectionEncodingServiceInterface::class), moduleSettingService: $moduleSettingService ?? $this->createStub(ModuleSettingServiceInterface::class), moduleConfigurationDao: $moduleConfigDao ?? $this->createStub(ModuleConfigurationDaoInterface::class), basicContext: $basicContext ?? $this->createStub(BasicContextInterface::class), diff --git a/tests/Unit/Service/ShopSettingServiceTest.php b/tests/Unit/Service/ShopSettingServiceTest.php index 81c9e6f..0af1f4d 100644 --- a/tests/Unit/Service/ShopSettingServiceTest.php +++ b/tests/Unit/Service/ShopSettingServiceTest.php @@ -15,7 +15,7 @@ use OxidEsales\GraphQL\ConfigurationAccess\Setting\DataType\StringSetting; use OxidEsales\GraphQL\ConfigurationAccess\Setting\Enum\FieldType; use OxidEsales\GraphQL\ConfigurationAccess\Setting\Infrastructure\ShopSettingRepositoryInterface; -use OxidEsales\GraphQL\ConfigurationAccess\Setting\Service\JsonServiceInterface; +use OxidEsales\GraphQL\ConfigurationAccess\Setting\Service\CollectionEncodingServiceInterface; use OxidEsales\GraphQL\ConfigurationAccess\Setting\Service\ShopSettingService; use OxidEsales\GraphQL\ConfigurationAccess\Tests\Unit\UnitTestCase; @@ -283,11 +283,11 @@ public function testChangeModuleSettingCollection(): void ->willReturn($repositoryValue); $encoderResponse = 'encoderResponse'; - $encoder = $this->createMock(JsonServiceInterface::class); - $encoder->method('jsonEncodeArray') + $encoder = $this->createMock(CollectionEncodingServiceInterface::class); + $encoder->method('encodeArrayToString') ->with($repositoryValue) ->willReturn($encoderResponse); - $encoder->method('jsonDecodeCollection') + $encoder->method('decodeStringCollectionToArray') ->with($callValue) ->willReturn($decodedValue); @@ -319,11 +319,11 @@ public function testChangeModuleSettingAssocCollection(): void ->willReturn($repositoryValue); $encoderResponse = 'encoderResponse'; - $encoder = $this->createMock(JsonServiceInterface::class); - $encoder->method('jsonEncodeArray') + $encoder = $this->createMock(CollectionEncodingServiceInterface::class); + $encoder->method('encodeArrayToString') ->with($repositoryValue) ->willReturn($encoderResponse); - $encoder->method('jsonDecodeCollection') + $encoder->method('decodeStringCollectionToArray') ->with($callValue) ->willReturn($decodedValue); @@ -358,12 +358,12 @@ public function testListShopSettings(): void private function getSut( ?ShopSettingRepositoryInterface $shopSettingRepository = null, - ?JsonServiceInterface $jsonService = null, + ?CollectionEncodingServiceInterface $jsonService = null, ): ShopSettingService { $shopSettingRepository = $shopSettingRepository ?? $this->createStub(ShopSettingRepositoryInterface::class); return new ShopSettingService( shopSettingRepository: $shopSettingRepository, - jsonService: $jsonService ?? $this->createStub(JsonServiceInterface::class) + jsonService: $jsonService ?? $this->createStub(CollectionEncodingServiceInterface::class) ); } } diff --git a/tests/Unit/Service/ThemeSettingServiceTest.php b/tests/Unit/Service/ThemeSettingServiceTest.php index 9880411..54e5b7d 100644 --- a/tests/Unit/Service/ThemeSettingServiceTest.php +++ b/tests/Unit/Service/ThemeSettingServiceTest.php @@ -16,7 +16,7 @@ use OxidEsales\GraphQL\ConfigurationAccess\Setting\Enum\FieldType; use OxidEsales\GraphQL\ConfigurationAccess\Setting\Exception\InvalidCollectionException; use OxidEsales\GraphQL\ConfigurationAccess\Setting\Infrastructure\ThemeSettingRepositoryInterface; -use OxidEsales\GraphQL\ConfigurationAccess\Setting\Service\JsonServiceInterface; +use OxidEsales\GraphQL\ConfigurationAccess\Setting\Service\CollectionEncodingServiceInterface; use OxidEsales\GraphQL\ConfigurationAccess\Setting\Service\ThemeSettingService; use OxidEsales\GraphQL\ConfigurationAccess\Tests\Unit\UnitTestCase; use PHPUnit\Framework\MockObject\MockObject; @@ -432,12 +432,12 @@ public function testChangeThemeSettingAssocCollection(): void private function getSut( ?ThemeSettingRepositoryInterface $themeSettingRepository = null, - ?JsonServiceInterface $jsonService = null, + ?CollectionEncodingServiceInterface $jsonService = null, ): ThemeSettingService { $themeSettingRepository = $themeSettingRepository ?? $this->createStub(ThemeSettingRepositoryInterface::class); return new ThemeSettingService( themeSettingRepository: $themeSettingRepository, - jsonService: $jsonService ?? $this->createStub(JsonServiceInterface::class) + jsonService: $jsonService ?? $this->createStub(CollectionEncodingServiceInterface::class) ); } } diff --git a/tests/Unit/UnitTestCase.php b/tests/Unit/UnitTestCase.php index e07125a..293f19a 100644 --- a/tests/Unit/UnitTestCase.php +++ b/tests/Unit/UnitTestCase.php @@ -16,7 +16,7 @@ use OxidEsales\GraphQL\ConfigurationAccess\Setting\DataType\SettingType; use OxidEsales\GraphQL\ConfigurationAccess\Setting\DataType\StringSetting; use OxidEsales\GraphQL\ConfigurationAccess\Setting\Enum\FieldType; -use OxidEsales\GraphQL\ConfigurationAccess\Setting\Service\JsonServiceInterface; +use OxidEsales\GraphQL\ConfigurationAccess\Setting\Service\CollectionEncodingServiceInterface; use PHPUnit\Framework\TestCase; use TheCodingMachine\GraphQLite\Types\ID; @@ -44,9 +44,9 @@ protected function getBasicContextMock(int $shopId = 1): BasicContextInterface protected function getJsonEncodeServiceMock( array $repositoryResult, string $collectionEncodingResult - ): JsonServiceInterface { - $jsonService = $this->createMock(JsonServiceInterface::class); - $jsonService->method('jsonEncodeArray') + ): CollectionEncodingServiceInterface { + $jsonService = $this->createMock(CollectionEncodingServiceInterface::class); + $jsonService->method('encodeArrayToString') ->with($repositoryResult) ->willReturn($collectionEncodingResult); return $jsonService;