diff --git a/CHANGELOG.md b/CHANGELOG.md index f872149..1001219 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added - New `parentTheme` and `parentVersions` fields in the `ThemeDataType` +### Changed +- Move ModuleDataType generation to Infrastructure +- Move ThemeDataType generation to Infrastructure + ## [1.2.0] - 2024-11-27 This is the stable release of v1.2.0. No changes have been made since v1.2.0-rc.1. @@ -40,6 +44,7 @@ This is stable release for v1.1.0. No changes have been made since v1.1.0-rc.1. - Initial release +[2.0.0]: https://github.com/OXID-eSales/graphql-configuration-access/compare/v1.2.0...b-7.2.x [1.2.0]: https://github.com/OXID-eSales/graphql-configuration-access/compare/v1.2.0-rc.1...v1.2.0 [1.2.0-rc.1]: https://github.com/OXID-eSales/graphql-configuration-access/compare/v1.1.0...v1.2.0-rc.1 [1.1.0]: https://github.com/OXID-eSales/graphql-configuration-access/compare/v1.1.0-rc.1...v1.1.0 diff --git a/src/Module/Infrastructure/ModuleListInfrastructure.php b/src/Module/Infrastructure/ModuleListInfrastructure.php index 4693784..37c984a 100644 --- a/src/Module/Infrastructure/ModuleListInfrastructure.php +++ b/src/Module/Infrastructure/ModuleListInfrastructure.php @@ -10,16 +10,18 @@ namespace OxidEsales\GraphQL\ConfigurationAccess\Module\Infrastructure; use OxidEsales\EshopCommunity\Internal\Framework\Module\Configuration\Bridge\ShopConfigurationDaoBridgeInterface; +use OxidEsales\GraphQL\ConfigurationAccess\Module\DataType\ModuleDataTypeFactoryInterface; use OxidEsales\GraphQL\ConfigurationAccess\Module\Exception\ModulesNotFoundException; class ModuleListInfrastructure implements ModuleListInfrastructureInterface { public function __construct( - private readonly ShopConfigurationDaoBridgeInterface $shopConfigurationDaoBridge + private readonly ShopConfigurationDaoBridgeInterface $shopConfigurationDaoBridge, + private readonly ModuleDataTypeFactoryInterface $moduleDataTypeFactory ) { } - public function getModuleConfigurations(): array + public function getModuleList(): array { $shopConfiguration = $this->shopConfigurationDaoBridge->get(); $moduleConfigurations = $shopConfiguration->getModuleConfigurations(); @@ -28,6 +30,10 @@ public function getModuleConfigurations(): array throw new ModulesNotFoundException(); } - return $moduleConfigurations; + $moduleDatatypes = []; + foreach ($moduleConfigurations as $moduleConfig) { + $moduleDatatypes[] = $this->moduleDataTypeFactory->createFromModuleConfiguration($moduleConfig); + } + return $moduleDatatypes; } } diff --git a/src/Module/Infrastructure/ModuleListInfrastructureInterface.php b/src/Module/Infrastructure/ModuleListInfrastructureInterface.php index 8855519..7d35074 100644 --- a/src/Module/Infrastructure/ModuleListInfrastructureInterface.php +++ b/src/Module/Infrastructure/ModuleListInfrastructureInterface.php @@ -7,14 +7,14 @@ namespace OxidEsales\GraphQL\ConfigurationAccess\Module\Infrastructure; +use OxidEsales\GraphQL\ConfigurationAccess\Module\DataType\ModuleDataTypeInterface; use OxidEsales\GraphQL\ConfigurationAccess\Module\Exception\ModulesNotFoundException; -use OxidEsales\EshopCommunity\Internal\Framework\Module\Configuration\DataObject\ModuleConfiguration; interface ModuleListInfrastructureInterface { /** - * @return array * @throws ModulesNotFoundException + * @return array */ - public function getModuleConfigurations(): array; + public function getModuleList(): array; } diff --git a/src/Module/Service/ModuleListService.php b/src/Module/Service/ModuleListService.php index 9fb5b46..e0ef919 100644 --- a/src/Module/Service/ModuleListService.php +++ b/src/Module/Service/ModuleListService.php @@ -9,7 +9,6 @@ namespace OxidEsales\GraphQL\ConfigurationAccess\Module\Service; -use OxidEsales\GraphQL\ConfigurationAccess\Module\DataType\ModuleDataTypeFactoryInterface; use OxidEsales\GraphQL\ConfigurationAccess\Module\Infrastructure\ModuleListInfrastructureInterface; use OxidEsales\GraphQL\ConfigurationAccess\Shared\DataType\ComponentFiltersInterface; use OxidEsales\GraphQL\ConfigurationAccess\Shared\Service\ComponentFilterServiceInterface; @@ -19,18 +18,13 @@ final class ModuleListService implements ModuleListServiceInterface public function __construct( private readonly ModuleListInfrastructureInterface $moduleListInfrastructure, private readonly ComponentFilterServiceInterface $componentFilterService, - private readonly ModuleDataTypeFactoryInterface $moduleDataTypeFactory ) { } public function getModuleList(ComponentFiltersInterface $filters): array { - $modulesArray = []; - $moduleConfigurations = $this->moduleListInfrastructure->getModuleConfigurations(); - foreach ($moduleConfigurations as $moduleConfig) { - $modulesArray[] = $this->moduleDataTypeFactory->createFromModuleConfiguration($moduleConfig); - } + $moduleConfigurations = $this->moduleListInfrastructure->getModuleList(); - return $this->componentFilterService->filterComponents($modulesArray, $filters); + return $this->componentFilterService->filterComponents($moduleConfigurations, $filters); } } diff --git a/src/Shared/Subscriber/BeforeModuleDeactivation.php b/src/Shared/Subscriber/BeforeModuleDeactivation.php index 2d5cf78..1ccfd1c 100644 --- a/src/Shared/Subscriber/BeforeModuleDeactivation.php +++ b/src/Shared/Subscriber/BeforeModuleDeactivation.php @@ -16,6 +16,9 @@ final class BeforeModuleDeactivation implements EventSubscriberInterface { + /** + * @param string[] $dependencies + */ public function __construct( private array $dependencies ) { diff --git a/src/Theme/Infrastructure/ThemeListInfrastructure.php b/src/Theme/Infrastructure/ThemeListInfrastructure.php index 0ad5f73..a2c1e6e 100644 --- a/src/Theme/Infrastructure/ThemeListInfrastructure.php +++ b/src/Theme/Infrastructure/ThemeListInfrastructure.php @@ -9,15 +9,20 @@ namespace OxidEsales\GraphQL\ConfigurationAccess\Theme\Infrastructure; +use OxidEsales\GraphQL\ConfigurationAccess\Theme\DataType\ThemeDataTypeFactoryInterface; use OxidEsales\GraphQL\ConfigurationAccess\Theme\Exception\ThemesNotFound; final class ThemeListInfrastructure implements ThemeListInfrastructureInterface { public function __construct( - private readonly CoreThemeFactoryInterface $coreThemeFactory + private readonly CoreThemeFactoryInterface $coreThemeFactory, + private readonly ThemeDataTypeFactoryInterface $themeDataTypeFactory ) { } + /** + * @inheritDoc + */ public function getThemes(): array { $coreThemeService = $this->coreThemeFactory->create(); @@ -27,6 +32,11 @@ public function getThemes(): array throw new ThemesNotFound(); } - return $themesList; + $themeDataTypes = []; + foreach ($themesList as $theme) { + $themeDataTypes[] = $this->themeDataTypeFactory->createFromCoreTheme(theme: $theme); + } + + return $themeDataTypes; } } diff --git a/src/Theme/Infrastructure/ThemeListInfrastructureInterface.php b/src/Theme/Infrastructure/ThemeListInfrastructureInterface.php index a7c85e5..918d3dc 100644 --- a/src/Theme/Infrastructure/ThemeListInfrastructureInterface.php +++ b/src/Theme/Infrastructure/ThemeListInfrastructureInterface.php @@ -7,13 +7,13 @@ namespace OxidEsales\GraphQL\ConfigurationAccess\Theme\Infrastructure; -use OxidEsales\Eshop\Core\Theme; +use OxidEsales\GraphQL\ConfigurationAccess\Theme\DataType\ThemeDataTypeInterface; use OxidEsales\GraphQL\ConfigurationAccess\Theme\Exception\ThemesNotFound; interface ThemeListInfrastructureInterface { /** - * @return array + * @return ThemeDataTypeInterface[] * @throws ThemesNotFound */ public function getThemes(): array; diff --git a/src/Theme/Service/ThemeListService.php b/src/Theme/Service/ThemeListService.php index 29f8716..6f84cef 100644 --- a/src/Theme/Service/ThemeListService.php +++ b/src/Theme/Service/ThemeListService.php @@ -11,26 +11,20 @@ use OxidEsales\GraphQL\ConfigurationAccess\Shared\DataType\ComponentFiltersInterface; use OxidEsales\GraphQL\ConfigurationAccess\Shared\Service\ComponentFilterServiceInterface; -use OxidEsales\GraphQL\ConfigurationAccess\Theme\DataType\ThemeDataTypeFactoryInterface; use OxidEsales\GraphQL\ConfigurationAccess\Theme\Infrastructure\ThemeListInfrastructureInterface; final class ThemeListService implements ThemeListServiceInterface { public function __construct( private readonly ThemeListInfrastructureInterface $themeListInfrastructure, - private readonly ComponentFilterServiceInterface $componentFilterService, - private readonly ThemeDataTypeFactoryInterface $themeDataTypeFactory + private readonly ComponentFilterServiceInterface $componentFilterService ) { } public function getThemeList(ComponentFiltersInterface $filters): array { - $themesArray = []; - $themesList = $this->themeListInfrastructure->getThemes(); - foreach ($themesList as $theme) { - $themesArray[] = $this->themeDataTypeFactory->createFromCoreTheme(theme: $theme); - } + $themeDataTypes = $this->themeListInfrastructure->getThemes(); - return $this->componentFilterService->filterComponents($themesArray, $filters); + return $this->componentFilterService->filterComponents($themeDataTypes, $filters); } } diff --git a/tests/Integration/Infrastructure/ModuleListInfrastructureTest.php b/tests/Integration/Infrastructure/ModuleListInfrastructureTest.php index 423f01b..e6f8881 100644 --- a/tests/Integration/Infrastructure/ModuleListInfrastructureTest.php +++ b/tests/Integration/Infrastructure/ModuleListInfrastructureTest.php @@ -12,6 +12,8 @@ use OxidEsales\EshopCommunity\Internal\Framework\Module\Configuration\Bridge\ShopConfigurationDaoBridgeInterface; use OxidEsales\EshopCommunity\Internal\Framework\Module\Configuration\DataObject\ModuleConfiguration; use OxidEsales\EshopCommunity\Tests\Integration\IntegrationTestCase; +use OxidEsales\GraphQL\ConfigurationAccess\Module\DataType\ModuleDataTypeFactoryInterface; +use OxidEsales\GraphQL\ConfigurationAccess\Module\DataType\ModuleDataTypeInterface; use OxidEsales\GraphQL\ConfigurationAccess\Module\Infrastructure\ModuleListInfrastructure; class ModuleListInfrastructureTest extends IntegrationTestCase @@ -24,10 +26,16 @@ public function testGetModuleList() $moduleConfiguration1 = new ModuleConfiguration(); $moduleConfiguration1->setId('firstModule'); + $moduleConfiguration1->setTitle(['en' => 'Module 1']); + $moduleConfiguration1->setDescription(['en' => 'Module 1 description']); + $moduleConfiguration1->setLang('en'); $moduleConfiguration1->setModuleSource('test'); $moduleConfiguration2 = new ModuleConfiguration(); $moduleConfiguration2->setId('secondModule'); + $moduleConfiguration2->setTitle(['en' => 'Module 2']); + $moduleConfiguration2->setDescription(['en' => 'Module 2 description']); + $moduleConfiguration2->setLang('en'); $moduleConfiguration2->setModuleSource('test1'); $shopConfiguration @@ -35,20 +43,20 @@ public function testGetModuleList() ->addModuleConfiguration($moduleConfiguration2); $shopConfigurationDaoBridge->save($shopConfiguration); - $sut = new ModuleListInfrastructure( - $shopConfigurationDaoBridge - ); - $modulesList = $sut->getModuleConfigurations(); - $this->assertEquals([ - $moduleConfiguration1->getId() => $moduleConfiguration1, - $moduleConfiguration2->getId() => $moduleConfiguration2 - ], $modulesList); + $sut = $this->getSut(); + $modulesList = $sut->getModuleList(); + $this->assertCount(2, $modulesList); + $this->assertInstanceOf(ModuleDataTypeInterface::class, $modulesList[0]); + $this->assertInstanceOf(ModuleDataTypeInterface::class, $modulesList[1]); + $this->assertSame($modulesList[0]->getId(), $moduleConfiguration1->getId()); + $this->assertSame($modulesList[1]->getId(), $moduleConfiguration2->getId()); } public function getSut(): ModuleListInfrastructure { return new ModuleListInfrastructure( - $this->get(ShopConfigurationDaoBridgeInterface::class) + $this->get(ShopConfigurationDaoBridgeInterface::class), + $this->get(ModuleDataTypeFactoryInterface::class) ); } } diff --git a/tests/Integration/Infrastructure/ThemeListInfrastructureTest.php b/tests/Integration/Infrastructure/ThemeListInfrastructureTest.php index c42f600..058aa7f 100644 --- a/tests/Integration/Infrastructure/ThemeListInfrastructureTest.php +++ b/tests/Integration/Infrastructure/ThemeListInfrastructureTest.php @@ -9,8 +9,9 @@ namespace OxidEsales\GraphQL\ConfigurationAccess\Tests\Integration\Infrastructure; -use OxidEsales\Eshop\Core\Theme; use OxidEsales\EshopCommunity\Tests\Integration\IntegrationTestCase; +use OxidEsales\GraphQL\ConfigurationAccess\Theme\DataType\ThemeDataTypeFactoryInterface; +use OxidEsales\GraphQL\ConfigurationAccess\Theme\DataType\ThemeDataTypeInterface; use OxidEsales\GraphQL\ConfigurationAccess\Theme\Infrastructure\CoreThemeFactoryInterface; use OxidEsales\GraphQL\ConfigurationAccess\Theme\Infrastructure\ThemeListInfrastructure; @@ -28,7 +29,7 @@ public function testGetThemesValidData(): void $this->assertIsArray($themesArray); foreach ($themesArray as $theme) { - $this->assertInstanceOf(Theme::class, $theme); + $this->assertInstanceOf(ThemeDataTypeInterface::class, $theme); } } @@ -36,6 +37,7 @@ public function getSut(): ThemeListInfrastructure { return new ThemeListInfrastructure( $this->get(CoreThemeFactoryInterface::class), + $this->get(ThemeDataTypeFactoryInterface::class) ); } } diff --git a/tests/Unit/Module/Infrastructure/ModuleListInfrastructureTest.php b/tests/Unit/Module/Infrastructure/ModuleListInfrastructureTest.php index c13d780..b2ab731 100644 --- a/tests/Unit/Module/Infrastructure/ModuleListInfrastructureTest.php +++ b/tests/Unit/Module/Infrastructure/ModuleListInfrastructureTest.php @@ -11,6 +11,8 @@ use OxidEsales\EshopCommunity\Internal\Framework\Module\Configuration\Bridge\ShopConfigurationDaoBridgeInterface; use OxidEsales\EshopCommunity\Internal\Framework\Module\Configuration\DataObject\ShopConfiguration; +use OxidEsales\GraphQL\ConfigurationAccess\Module\DataType\ModuleDataTypeFactoryInterface; +use OxidEsales\GraphQL\ConfigurationAccess\Module\DataType\ModuleDataTypeInterface; use OxidEsales\GraphQL\ConfigurationAccess\Module\Infrastructure\ModuleListInfrastructure; use OxidEsales\GraphQL\ConfigurationAccess\Tests\Unit\UnitTestCase; use OxidEsales\EshopCommunity\Internal\Framework\Module\Configuration\DataObject\ModuleConfiguration; @@ -23,32 +25,37 @@ class ModuleListInfrastructureTest extends UnitTestCase { public function testGetModuleList() { - $moduleConfigurationMock = $this->createMock(ModuleConfiguration::class); + $moduleConfigurationStub = $this->createStub(ModuleConfiguration::class); + $moduleDataType = $this->createStub(ModuleDataTypeInterface::class); $shopConfigurationMock = $this->createMock(ShopConfiguration::class); $shopConfigurationMock ->method('getModuleConfigurations') - ->willReturn([$moduleConfigurationMock]); + ->willReturn([$moduleConfigurationStub]); $shopConfigurationDaoBridgeMock = $this->createMock(ShopConfigurationDaoBridgeInterface::class); - $shopConfigurationDaoBridgeMock - ->method('get') + $shopConfigurationDaoBridgeMock->method('get') ->willReturn($shopConfigurationMock); + $moduleDataTypeFactoryMock = $this->createMock(ModuleDataTypeFactoryInterface::class); + $moduleDataTypeFactoryMock->method('createFromModuleConfiguration') + ->with($moduleConfigurationStub) + ->willReturn($moduleDataType); + $sut = $this->getSut( - shopConfigurationDaoBridgeMock: $shopConfigurationDaoBridgeMock + shopConfigurationDaoBridgeMock: $shopConfigurationDaoBridgeMock, + moduleDataTypeFactory: $moduleDataTypeFactoryMock ); - $result = $sut->getModuleConfigurations(); + $result = $sut->getModuleList(); - $this->assertSame([$moduleConfigurationMock], $result); + $this->assertSame([$moduleDataType], $result); } public function testGetModuleListThrowsException() { $shopConfigurationDaoBridgeMock = $this->createMock(ShopConfigurationDaoBridgeInterface::class); - $shopConfigurationDaoBridgeMock - ->method('get') + $shopConfigurationDaoBridgeMock->method('get') ->willReturn($this->createMock(ShopConfiguration::class)); $this->expectException(ModulesNotFoundException::class); @@ -57,14 +64,17 @@ public function testGetModuleListThrowsException() shopConfigurationDaoBridgeMock: $shopConfigurationDaoBridgeMock ); - $sut->getModuleConfigurations(); + $sut->getModuleList(); } public function getSut( - ?ShopConfigurationDaoBridgeInterface $shopConfigurationDaoBridgeMock = null + ?ShopConfigurationDaoBridgeInterface $shopConfigurationDaoBridgeMock = null, + ?ModuleDataTypeFactoryInterface $moduleDataTypeFactory = null ): ModuleListInfrastructure { return new ModuleListInfrastructure( - $shopConfigurationDaoBridgeMock ?? $this->createMock(ShopConfigurationDaoBridgeInterface::class) + shopConfigurationDaoBridge: $shopConfigurationDaoBridgeMock ?? + $this->createStub(ShopConfigurationDaoBridgeInterface::class), + moduleDataTypeFactory: $moduleDataTypeFactory ?? $this->createStub(ModuleDataTypeFactoryInterface::class) ); } } diff --git a/tests/Unit/Module/Service/ModuleListServiceTest.php b/tests/Unit/Module/Service/ModuleListServiceTest.php index 19e4865..52b5742 100644 --- a/tests/Unit/Module/Service/ModuleListServiceTest.php +++ b/tests/Unit/Module/Service/ModuleListServiceTest.php @@ -30,32 +30,20 @@ public function testGetModuleListWithFilters(): void $moduleStub2 = $this->createStub(ModuleDataTypeInterface::class); $filteredModules = [$moduleStub1]; - $moduleConfigStub1 = $this->createStub(ModuleConfiguration::class); - $moduleConfigStub2 = $this->createStub(ModuleConfiguration::class); - $modulesConfigurations = [$moduleConfigStub1, $moduleConfigStub2]; + $modulesConfigurations = [$moduleStub1, $moduleStub2]; $moduleListInfrastructureMock = $this->createMock(ModuleListInfrastructureInterface::class); - $moduleListInfrastructureMock->method('getModuleConfigurations') + $moduleListInfrastructureMock->method('getModuleList') ->willReturn($modulesConfigurations); $componentFilterServiceMock = $this->createMock(ComponentFilterServiceInterface::class); $componentFilterServiceMock->method('filterComponents') - ->with([$moduleStub1, $moduleStub2], $filtersStub) + ->with($modulesConfigurations, $filtersStub) ->willReturn($filteredModules); - $moduleDataTypeFactoryMock = $this->createMock(ModuleDataTypeFactoryInterface::class); - $moduleDataTypeFactoryMock - ->expects($this->exactly(2)) - ->method('createFromModuleConfiguration') - ->willReturnMap([ - [$moduleConfigStub1, $moduleStub1], - [$moduleConfigStub2, $moduleStub2] - ]); - $sut = new ModuleListService( moduleListInfrastructure: $moduleListInfrastructureMock, componentFilterService: $componentFilterServiceMock, - moduleDataTypeFactory: $moduleDataTypeFactoryMock ); $actualModules = $sut->getModuleList($filtersStub); diff --git a/tests/Unit/Shared/Exception/CollectionEncodingExceptionTest.php b/tests/Unit/Shared/Exception/CollectionEncodingExceptionTest.php new file mode 100644 index 0000000..33d3de0 --- /dev/null +++ b/tests/Unit/Shared/Exception/CollectionEncodingExceptionTest.php @@ -0,0 +1,25 @@ +assertSame('Error encountered while encoding collection data', $sut->getMessage()); + } +} diff --git a/tests/Unit/Shared/Exception/InvalidCollectionExceptionTest.php b/tests/Unit/Shared/Exception/InvalidCollectionExceptionTest.php new file mode 100644 index 0000000..4b8b783 --- /dev/null +++ b/tests/Unit/Shared/Exception/InvalidCollectionExceptionTest.php @@ -0,0 +1,26 @@ +assertSame(sprintf('%s is not a valid collection string.', $value), $sut->getMessage()); + } +} diff --git a/tests/Unit/Shared/Exception/WrongSettingValueExceptionTest.php b/tests/Unit/Shared/Exception/WrongSettingValueExceptionTest.php new file mode 100644 index 0000000..d401dbf --- /dev/null +++ b/tests/Unit/Shared/Exception/WrongSettingValueExceptionTest.php @@ -0,0 +1,25 @@ +assertSame('Wrong setting value', $sut->getMessage()); + } +} diff --git a/tests/Unit/Shared/Subscriber/BeforeModuleDeactivationTest.php b/tests/Unit/Shared/Subscriber/BeforeModuleDeactivationTest.php new file mode 100644 index 0000000..22ae8d6 --- /dev/null +++ b/tests/Unit/Shared/Subscriber/BeforeModuleDeactivationTest.php @@ -0,0 +1,57 @@ +createConfiguredStub(BeforeModuleDeactivationEvent::class, [ + 'getModuleId' => uniqid('module') + ]); + + $sut = new BeforeModuleDeactivation($dependencies); + $returnEvent = $sut->handle($beforeModuleDeactivationEvent); + $this->assertSame($beforeModuleDeactivationEvent, $returnEvent); + } + + public function testHandleThrowsModuleSetupValidationException() + { + $dependencies = []; + $dependencies[] = uniqid(); + $dependencies[] = uniqid(); + + $dependenciesKey = array_rand($dependencies); + $dependency = $dependencies[$dependenciesKey]; + + $beforeModuleDeactivationEvent = $this->createConfiguredStub(BeforeModuleDeactivationEvent::class, [ + 'getModuleId' => $dependency + ]); + + $this->expectException(ModuleSetupValidationException::class); + $this->expectExceptionMessage((new ModuleSetupValidationException('Module with id "' . $dependency . + '" cannot be deactivated while GraphQL Configuration Access module is active.'))->getMessage()); + + $sut = new BeforeModuleDeactivation($dependencies); + $sut->handle($beforeModuleDeactivationEvent); + } +} diff --git a/tests/Unit/Shared/Exception/NoSettingsFoundForShopExceptionTest.php b/tests/Unit/Shop/Exception/NoSettingsFoundForShopExceptionTest.php similarity index 78% rename from tests/Unit/Shared/Exception/NoSettingsFoundForShopExceptionTest.php rename to tests/Unit/Shop/Exception/NoSettingsFoundForShopExceptionTest.php index 7120cf4..2aaa9f9 100644 --- a/tests/Unit/Shared/Exception/NoSettingsFoundForShopExceptionTest.php +++ b/tests/Unit/Shop/Exception/NoSettingsFoundForShopExceptionTest.php @@ -7,13 +7,14 @@ declare(strict_types=1); -namespace OxidEsales\GraphQL\ConfigurationAccess\Tests\Unit\Shared\Exception; +namespace OxidEsales\GraphQL\ConfigurationAccess\Tests\Unit\Shop\Exception; use OxidEsales\GraphQL\ConfigurationAccess\Shop\Exception\NoSettingsFoundForShopException; use PHPUnit\Framework\TestCase; /** * @covers \OxidEsales\GraphQL\ConfigurationAccess\Shop\Exception\NoSettingsFoundForShopException + * @covers \OxidEsales\GraphQL\ConfigurationAccess\Shared\Exception\NoSettingsFoundException */ class NoSettingsFoundForShopExceptionTest extends TestCase { diff --git a/tests/Unit/Shop/Exception/WrongSettingTypeExceptionTest.php b/tests/Unit/Shop/Exception/WrongSettingTypeExceptionTest.php new file mode 100644 index 0000000..12becb9 --- /dev/null +++ b/tests/Unit/Shop/Exception/WrongSettingTypeExceptionTest.php @@ -0,0 +1,26 @@ +assertSame('Wrong setting type', $sut->getMessage()); + } +} diff --git a/tests/Unit/Shared/Exception/NoSettingsFoundForThemeExceptionTest.php b/tests/Unit/Theme/Exception/NoSettingsFoundForThemeExceptionTest.php similarity index 79% rename from tests/Unit/Shared/Exception/NoSettingsFoundForThemeExceptionTest.php rename to tests/Unit/Theme/Exception/NoSettingsFoundForThemeExceptionTest.php index e43d69b..e830599 100644 --- a/tests/Unit/Shared/Exception/NoSettingsFoundForThemeExceptionTest.php +++ b/tests/Unit/Theme/Exception/NoSettingsFoundForThemeExceptionTest.php @@ -7,13 +7,14 @@ declare(strict_types=1); -namespace OxidEsales\GraphQL\ConfigurationAccess\Tests\Unit\Shared\Exception; +namespace OxidEsales\GraphQL\ConfigurationAccess\Tests\Unit\Theme\Exception; use OxidEsales\GraphQL\ConfigurationAccess\Theme\Exception\NoSettingsFoundForThemeException; use PHPUnit\Framework\TestCase; /** * @covers \OxidEsales\GraphQL\ConfigurationAccess\Theme\Exception\NoSettingsFoundForThemeException + * @covers \OxidEsales\GraphQL\ConfigurationAccess\Shared\Exception\NoSettingsFoundException */ class NoSettingsFoundForThemeExceptionTest extends TestCase { diff --git a/tests/Unit/Theme/Infrastructure/ThemeListInfrastructureTest.php b/tests/Unit/Theme/Infrastructure/ThemeListInfrastructureTest.php index ee28867..be764be 100644 --- a/tests/Unit/Theme/Infrastructure/ThemeListInfrastructureTest.php +++ b/tests/Unit/Theme/Infrastructure/ThemeListInfrastructureTest.php @@ -10,6 +10,8 @@ namespace OxidEsales\GraphQL\ConfigurationAccess\Tests\Unit\Theme\Infrastructure; use OxidEsales\Eshop\Core\Theme; +use OxidEsales\GraphQL\ConfigurationAccess\Theme\DataType\ThemeDataType; +use OxidEsales\GraphQL\ConfigurationAccess\Theme\DataType\ThemeDataTypeFactoryInterface; use OxidEsales\GraphQL\ConfigurationAccess\Theme\Infrastructure\CoreThemeFactoryInterface; use OxidEsales\GraphQL\ConfigurationAccess\Theme\Exception\ThemesNotFound; use OxidEsales\GraphQL\ConfigurationAccess\Theme\Infrastructure\ThemeListInfrastructure; @@ -24,14 +26,22 @@ public function testGetThemes(): void { $theme1 = $this->createStub(Theme::class); $theme2 = $this->createStub(Theme::class); + $themeDataType1 = $this->createStub(ThemeDataType::class); + $themeDataType2 = $this->createStub(ThemeDataType::class); $coreThemeMock = $this->createMock(Theme::class); $coreThemeMock->method('getList')->willReturn([$theme1, $theme2]); $coreThemeFactoryMock = $this->getCoreThemeFactoryMock(returnValue: $coreThemeMock); - $sut = $this->getSut(coreThemeFactory: $coreThemeFactoryMock); + $themeDataTypeFactory = $this->createMock(ThemeDataTypeFactoryInterface::class); + $themeDataTypeFactory->method('createFromCoreTheme')->willReturnMap([ + [$theme1, $themeDataType1], + [$theme2, $themeDataType2] + ]); + + $sut = $this->getSut(coreThemeFactory: $coreThemeFactoryMock, themeDataTypeFactory: $themeDataTypeFactory); $actualThemesArray = $sut->getThemes(); - $this->assertSame([$theme1, $theme2], $actualThemesArray); + $this->assertSame([$themeDataType1, $themeDataType2], $actualThemesArray); } public function testGetThemesThrowsException(): void @@ -47,10 +57,12 @@ public function testGetThemesThrowsException(): void } private function getSut( - CoreThemeFactoryInterface $coreThemeFactory + CoreThemeFactoryInterface $coreThemeFactory = null, + ThemeDataTypeFactoryInterface $themeDataTypeFactory = null ): ThemeListInfrastructure { return new ThemeListInfrastructure( - coreThemeFactory: $coreThemeFactory + coreThemeFactory: $coreThemeFactory ?? $this->createStub(CoreThemeFactoryInterface::class), + themeDataTypeFactory: $themeDataTypeFactory ?? $this->createStub(ThemeDataTypeFactoryInterface::class) ); } diff --git a/tests/Unit/Theme/Service/ThemeListServiceTest.php b/tests/Unit/Theme/Service/ThemeListServiceTest.php index e729e47..f5b3329 100644 --- a/tests/Unit/Theme/Service/ThemeListServiceTest.php +++ b/tests/Unit/Theme/Service/ThemeListServiceTest.php @@ -25,37 +25,24 @@ class ThemeListServiceTest extends TestCase { public function testGetThemeListWithFilters(): void { - $theme1 = $this->createStub(Theme::class); - $theme2 = $this->createStub(Theme::class); - $themes = [$theme1, $theme2]; $themeDataType1 = $this->createStub(ThemeDataTypeInterface::class); $themeDataType2 = $this->createStub(ThemeDataTypeInterface::class); - $themeList = [$themeDataType1, $themeDataType2]; + $themes = [$themeDataType1, $themeDataType2]; $filteredThemeList = [$themeDataType1]; $themeListInfrastructureMock = $this->createMock(ThemeListInfrastructureInterface::class); $themeListInfrastructureMock->method('getThemes')->willReturn($themes); - $themeDataTypeFactoryMock = $this->createMock(ThemeDataTypeFactoryInterface::class); - $themeDataTypeFactoryMock - ->expects($this->exactly(2)) - ->method('createFromCoreTheme') - ->willReturnMap([ - [$theme1, $themeDataType1], - [$theme2, $themeDataType2] - ]); - $componentFiltersStub = $this->createStub(ComponentFiltersInterface::class); $componentFilterServiceMock = $this->createMock(ComponentFilterServiceInterface::class); $componentFilterServiceMock->method('filterComponents') - ->with($themeList, $componentFiltersStub) + ->with($themes, $componentFiltersStub) ->willReturn($filteredThemeList); $themeListService = new ThemeListService( themeListInfrastructure: $themeListInfrastructureMock, componentFilterService: $componentFilterServiceMock, - themeDataTypeFactory: $themeDataTypeFactoryMock ); $actualThemes = $themeListService->getThemeList($componentFiltersStub); $this->assertSame($filteredThemeList, $actualThemes);