Skip to content

Commit

Permalink
OXDEV-7557 Rename JsonServiceInterface
Browse files Browse the repository at this point in the history
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 <anton@fedurtsya.com>
  • Loading branch information
Sieg committed Dec 6, 2023
1 parent 019c7ca commit 870c76c
Show file tree
Hide file tree
Showing 12 changed files with 66 additions and 66 deletions.
15 changes: 15 additions & 0 deletions src/Setting/Service/CollectionEncodingServiceInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

/**
* Copyright © OXID eSales AG. All rights reserved.
* See LICENSE file for license details.
*/

namespace OxidEsales\GraphQL\ConfigurationAccess\Setting\Service;

interface CollectionEncodingServiceInterface
{
public function encodeArrayToString(array $collection): string;

public function decodeStringCollectionToArray(string $value): array;
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@
use OxidEsales\GraphQL\ConfigurationAccess\Setting\Exception\CollectionEncodingException;
use OxidEsales\GraphQL\ConfigurationAccess\Setting\Exception\InvalidCollectionException;

class JsonService implements JsonServiceInterface
class JsonCollectionEncodingService implements CollectionEncodingServiceInterface
{
/**
* @throws CollectionEncodingException
*/
public function jsonEncodeArray(array $collection): string
public function encodeArrayToString(array $collection): string
{
$jsonValue = json_encode($collection);

Expand All @@ -30,7 +30,7 @@ public function jsonEncodeArray(array $collection): string
/**
* @throws InvalidCollectionException
*/
public function jsonDecodeCollection(string $value): array
public function decodeStringCollectionToArray(string $value): array
{
if ($value === '') {
return [];
Expand Down
15 changes: 0 additions & 15 deletions src/Setting/Service/JsonServiceInterface.php

This file was deleted.

6 changes: 3 additions & 3 deletions src/Setting/Service/ModuleSettingService.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
final class ModuleSettingService implements ModuleSettingServiceInterface
{
public function __construct(
private JsonServiceInterface $jsonService,
private CollectionEncodingServiceInterface $jsonService,
private ShopModuleSettingServiceInterface $moduleSettingService,
private ModuleConfigurationDaoInterface $moduleConfigurationDao,
private BasicContextInterface $basicContext,
Expand Down Expand Up @@ -69,7 +69,7 @@ public function getCollectionSetting(string $name, string $moduleId): StringSett

return new StringSetting(
$name,
$this->jsonService->jsonEncodeArray($collection)
$this->jsonService->encodeArrayToString($collection)
);
}

Expand Down Expand Up @@ -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
);

Expand Down
10 changes: 5 additions & 5 deletions src/Setting/Service/ShopSettingService.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ final class ShopSettingService implements ShopSettingServiceInterface
{
public function __construct(
private ShopSettingRepositoryInterface $shopSettingRepository,
private JsonServiceInterface $jsonService,
private CollectionEncodingServiceInterface $jsonService,
) {
}

Expand Down Expand Up @@ -57,15 +57,15 @@ 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);
}

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);
}
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand Down
6 changes: 3 additions & 3 deletions src/Setting/Service/ThemeSettingService.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ final class ThemeSettingService implements ThemeSettingServiceInterface
{
public function __construct(
private ThemeSettingRepositoryInterface $themeSettingRepository,
private JsonServiceInterface $jsonService,
private CollectionEncodingServiceInterface $jsonService,
) {
}

Expand Down Expand Up @@ -58,15 +58,15 @@ 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);
}

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);
}
Expand Down
4 changes: 2 additions & 2 deletions src/Setting/services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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);
}
}
16 changes: 8 additions & 8 deletions tests/Unit/Service/ModuleSettingServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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),
Expand Down
18 changes: 9 additions & 9 deletions tests/Unit/Service/ShopSettingServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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)
);
}
}
6 changes: 3 additions & 3 deletions tests/Unit/Service/ThemeSettingServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)
);
}
}
8 changes: 4 additions & 4 deletions tests/Unit/UnitTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 870c76c

Please sign in to comment.