diff --git a/CHANGELOG.md b/CHANGELOG.md index 3a3de70..7b4e628 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,17 +10,16 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Theme list and filtering option on basis of theme name and status - Module list and filtering option on basis of module name and status - Activation of given theme by themeId -- Mutations to activate and deactive a module. +- Mutations to de/activate a module. +- Prevention of de/activation of certain modules mentioned in modules_blocklist.yaml. ## [1.1.0] - 2024-07-05 This is stable release for v1.1.0. No changes have been made since v1.1.0-rc.1. ## [1.1.0-rc.1] - 2024-05-30 -[.gitignore](.gitignore) ### Added - PHP 8.2 support - Module activation dependency on GraphQL Base module -- Activate a given theme by themeId. ### Changed - PHPUnit upgraded to version 10.x @@ -33,6 +32,7 @@ This is stable release for v1.1.0. No changes have been made since v1.1.0-rc.1. - Initial release +[1.2.0]: https://github.com/OXID-eSales/graphql-configuration-access/compare/v1.1.0...v1.2.0 [1.1.0]: https://github.com/OXID-eSales/graphql-configuration-access/compare/v1.1.0-rc.1...v1.1.0 [1.1.0-rc.1]: https://github.com/OXID-eSales/graphql-configuration-access/compare/v1.0.0...v1.1.0-rc.1 [1.0.0]: https://github.com/OXID-eSales/graphql-configuration-access/releases/tag/v1.0.0 diff --git a/README.md b/README.md index fa08a17..0d4aa83 100644 --- a/README.md +++ b/README.md @@ -64,6 +64,12 @@ $ vendor/bin/oe-console oe:module:activate oe_graphql_configuration_access A good starting point is to check the [How to use section in the GraphQL Base Module](https://github.com/OXID-eSales/graphql-base-module/#how-to-use) +## Blocking modules from de/activation via GraphQL + +The file module_blockilst.yaml contains a list of modules which are necessary to handle configurations or de/activate +modules via GraphQL or should be blocked for de/activation via GraphQL in general. Modules like ``oe_graphql_base`` and +``oe_graphql_configuration_access`` are listed there. + ## Testing ### Linting, syntax check, static analysis diff --git a/module_blocklist.yaml b/module_blocklist.yaml new file mode 100644 index 0000000..80ae9ad --- /dev/null +++ b/module_blocklist.yaml @@ -0,0 +1,3 @@ +modules: + - oe_graphql_base + - oe_graphql_configuration_access diff --git a/src/Module/Exception/ModuleActivationBlockedException.php b/src/Module/Exception/ModuleActivationBlockedException.php new file mode 100644 index 0000000..a2dc549 --- /dev/null +++ b/src/Module/Exception/ModuleActivationBlockedException.php @@ -0,0 +1,22 @@ +moduleBlocklistService->isModuleBlocked($moduleId)) { + throw new ModuleActivationBlockedException($moduleId); + } + $shopId = $this->context->getCurrentShopId(); try { @@ -43,6 +50,10 @@ public function activateModule(string $moduleId): bool */ public function deactivateModule(string $moduleId): bool { + if ($this->moduleBlocklistService->isModuleBlocked($moduleId)) { + throw new ModuleDeactivationBlockedException($moduleId); + } + $shopId = $this->context->getCurrentShopId(); try { diff --git a/src/Module/Service/ModuleActivationServiceInterface.php b/src/Module/Service/ModuleActivationServiceInterface.php index 1181e9c..0ae22b9 100644 --- a/src/Module/Service/ModuleActivationServiceInterface.php +++ b/src/Module/Service/ModuleActivationServiceInterface.php @@ -9,6 +9,7 @@ use OxidEsales\GraphQL\ConfigurationAccess\Module\Exception\ModuleActivationException; use OxidEsales\GraphQL\ConfigurationAccess\Module\Exception\ModuleDeactivationException; +use OxidEsales\GraphQL\ConfigurationAccess\Module\Exception\ModuleDeactivationBlockedException; interface ModuleActivationServiceInterface { @@ -19,6 +20,7 @@ public function activateModule(string $moduleId): bool; /** * @throws ModuleDeactivationException + * @throws ModuleDeactivationBlockedException */ public function deactivateModule(string $moduleId): bool; } diff --git a/src/Module/Service/ModuleBlocklistService.php b/src/Module/Service/ModuleBlocklistService.php new file mode 100644 index 0000000..57d9a43 --- /dev/null +++ b/src/Module/Service/ModuleBlocklistService.php @@ -0,0 +1,30 @@ +moduleBlocklistPath; + $configWrapper = $this->projectYamlDao->loadDIConfigFile($resolvedPath); + $blocklistData = $configWrapper->getConfigAsArray(); + + return in_array($moduleId, $blocklistData['modules'], true); + } +} diff --git a/src/Module/Service/ModuleBlocklistServiceInterface.php b/src/Module/Service/ModuleBlocklistServiceInterface.php new file mode 100644 index 0000000..c86b34b --- /dev/null +++ b/src/Module/Service/ModuleBlocklistServiceInterface.php @@ -0,0 +1,13 @@ +themeSwitchService->switchTheme($identifier); + return $this->themeSwitchService->switchTheme($themeId); } } diff --git a/src/Theme/DataType/ThemeDataType.php b/src/Theme/DataType/ThemeDataType.php index 77f37c6..07cda0f 100644 --- a/src/Theme/DataType/ThemeDataType.php +++ b/src/Theme/DataType/ThemeDataType.php @@ -15,13 +15,4 @@ #[Type] class ThemeDataType extends AbstractComponentDataType implements ThemeDataTypeInterface { - public function __construct( - string $id, - string $title, - string $version, - string $description, - bool $active - ) { - parent::__construct($id, $title, $version, $description, $active); - } } diff --git a/src/Theme/Infrastructure/ThemeSwitchInfrastructure.php b/src/Theme/Infrastructure/ThemeSwitchInfrastructure.php index 1386c00..87efcc4 100644 --- a/src/Theme/Infrastructure/ThemeSwitchInfrastructure.php +++ b/src/Theme/Infrastructure/ThemeSwitchInfrastructure.php @@ -21,11 +21,11 @@ public function __construct( ) { } - public function switchTheme(string $identifier): bool + public function switchTheme(string $themeId): bool { try { $coreThemeService = $this->coreThemeFactory->create(); - if (!$coreThemeService->load($identifier)) { + if (!$coreThemeService->load($themeId)) { throw new ThemeActivationException(self::THEME_NOT_EXIST); } $coreThemeService->activate(); diff --git a/src/Theme/Infrastructure/ThemeSwitchInfrastructureInterface.php b/src/Theme/Infrastructure/ThemeSwitchInfrastructureInterface.php index f27daa0..6f782ed 100644 --- a/src/Theme/Infrastructure/ThemeSwitchInfrastructureInterface.php +++ b/src/Theme/Infrastructure/ThemeSwitchInfrastructureInterface.php @@ -14,5 +14,5 @@ interface ThemeSwitchInfrastructureInterface /** *@throws ThemeActivationException */ - public function switchTheme(string $identifier): bool; + public function switchTheme(string $themeId): bool; } diff --git a/src/Theme/Service/ThemeSwitchService.php b/src/Theme/Service/ThemeSwitchService.php index da6a065..ba742b1 100644 --- a/src/Theme/Service/ThemeSwitchService.php +++ b/src/Theme/Service/ThemeSwitchService.php @@ -17,8 +17,8 @@ public function __construct( private readonly ThemeSwitchInfrastructureInterface $themeSwitchInfrastructure ) { } - public function switchTheme(string $identifier): bool + public function switchTheme(string $themeId): bool { - return $this->themeSwitchInfrastructure->switchTheme(identifier: $identifier); + return $this->themeSwitchInfrastructure->switchTheme(themeId: $themeId); } } diff --git a/src/Theme/Service/ThemeSwitchServiceInterface.php b/src/Theme/Service/ThemeSwitchServiceInterface.php index 041a7ca..3cfb462 100644 --- a/src/Theme/Service/ThemeSwitchServiceInterface.php +++ b/src/Theme/Service/ThemeSwitchServiceInterface.php @@ -9,5 +9,5 @@ interface ThemeSwitchServiceInterface { - public function switchTheme(string $identifier): bool; + public function switchTheme(string $themeId): bool; } diff --git a/tests/Codeception/Acceptance/Module/ModuleSettingBaseCest.php b/tests/Codeception/Acceptance/Module/ModuleSettingBaseCest.php index 2991ac6..cbb63cf 100644 --- a/tests/Codeception/Acceptance/Module/ModuleSettingBaseCest.php +++ b/tests/Codeception/Acceptance/Module/ModuleSettingBaseCest.php @@ -96,6 +96,8 @@ protected function removeConfiguration(string $moduleId): void { $shopConfiguration = $this->getShopConfiguration(); $shopConfiguration->deleteModuleConfiguration($moduleId); + $shopConfigurationDao = $this->getShopConfigurationDao(); + $shopConfigurationDao->save($shopConfiguration, 1); } protected function getShopConfigurationDao(): ShopConfigurationDao diff --git a/tests/Codeception/Acceptance/Module/ModuleSwitchCest.php b/tests/Codeception/Acceptance/Module/ModuleSwitchCest.php new file mode 100644 index 0000000..f4b1d61 --- /dev/null +++ b/tests/Codeception/Acceptance/Module/ModuleSwitchCest.php @@ -0,0 +1,60 @@ +login($this->getAdminUsername(), $this->getAdminPassword()); + + $result = $this->runModuleMutation( + I: $I, + queryName: $example['queryName'], + field: $example['field'] + ); + + $I->assertArrayNotHasKey('errors', $result); + $response = $result['data'][$example['queryName']]; + $I->assertTrue($response); + } + + private function runModuleMutation( + AcceptanceTester $I, + string $queryName, + string $field + ): array { + $I->login($this->getAdminUsername(), $this->getAdminPassword()); + $I->sendGQLQuery( + 'mutation { + ' . $queryName . '(' . $field . ': "' . self::TEST_MODULE_ID . '") + }' + ); + + $I->seeResponseIsJson(); + return $I->grabJsonResponseAsArray(); + } + + protected function moduleSwitchDataProvider(): \Generator + { + yield ['queryName' => 'activateModule', 'field' => 'moduleId']; + yield ['queryName' => 'deactivateModule', 'field' => 'moduleId']; + } +} diff --git a/tests/Codeception/Acceptance/Theme/ThemeSwitchCest.php b/tests/Codeception/Acceptance/Theme/ThemeSwitchCest.php index 89b3c10..b15f3d3 100644 --- a/tests/Codeception/Acceptance/Theme/ThemeSwitchCest.php +++ b/tests/Codeception/Acceptance/Theme/ThemeSwitchCest.php @@ -34,7 +34,7 @@ private function runThemeSwitchMutation(AcceptanceTester $I): array $I->sendGQLQuery( 'mutation switchThemeCest{ - switchTheme(identifier: "' . $themeId . '") + switchTheme(themeId: "' . $themeId . '") }' ); diff --git a/tests/Integration/Service/ModuleBlockListServiceTest.php b/tests/Integration/Service/ModuleBlockListServiceTest.php new file mode 100644 index 0000000..9027215 --- /dev/null +++ b/tests/Integration/Service/ModuleBlockListServiceTest.php @@ -0,0 +1,33 @@ +get(ProjectYamlDaoInterface::class) + ); + + $this->assertTrue($sut->isModuleBlocked('oe_graphql_base')); + $this->assertTrue($sut->isModuleBlocked('oe_graphql_configuration_access')); + } +} diff --git a/tests/Unit/Module/Exception/ModuleActivationBlockedExceptionTest.php b/tests/Unit/Module/Exception/ModuleActivationBlockedExceptionTest.php new file mode 100644 index 0000000..2275215 --- /dev/null +++ b/tests/Unit/Module/Exception/ModuleActivationBlockedExceptionTest.php @@ -0,0 +1,31 @@ +assertInstanceOf(ModuleActivationBlockedException::class, $exception); + $this->assertSame( + sprintf('Module "%s" is in the blocklist and cannot be activated.', $moduleId), + $exception->getMessage() + ); + } +} diff --git a/tests/Unit/Module/Exception/ModuleActivationExceptionTest.php b/tests/Unit/Module/Exception/ModuleActivationExceptionTest.php index ca9f973..554366e 100644 --- a/tests/Unit/Module/Exception/ModuleActivationExceptionTest.php +++ b/tests/Unit/Module/Exception/ModuleActivationExceptionTest.php @@ -10,7 +10,6 @@ namespace OxidEsales\GraphQL\ConfigurationAccess\Tests\Unit\Module\Exception; use OxidEsales\GraphQL\ConfigurationAccess\Module\Exception\ModuleActivationException; -use OxidEsales\GraphQL\ConfigurationAccess\Module\Exception\ModuleDeactivationException; use PHPUnit\Framework\TestCase; /** @@ -18,7 +17,7 @@ */ final class ModuleActivationExceptionTest extends TestCase { - public function testActivationException(): void + public function testException(): void { $exception = new ModuleActivationException(); diff --git a/tests/Unit/Module/Exception/ModuleDeactivationBlockedExceptionTest.php b/tests/Unit/Module/Exception/ModuleDeactivationBlockedExceptionTest.php new file mode 100644 index 0000000..fc08ba7 --- /dev/null +++ b/tests/Unit/Module/Exception/ModuleDeactivationBlockedExceptionTest.php @@ -0,0 +1,31 @@ +assertInstanceOf(ModuleDeactivationBlockedException::class, $exception); + $this->assertSame( + sprintf('Module "%s" is in the blocklist and cannot be deactivated.', $moduleId), + $exception->getMessage() + ); + } +} diff --git a/tests/Unit/Module/Exception/ModuleDeactivationExceptionTest.php b/tests/Unit/Module/Exception/ModuleDeactivationExceptionTest.php index fed0a35..0a7d536 100644 --- a/tests/Unit/Module/Exception/ModuleDeactivationExceptionTest.php +++ b/tests/Unit/Module/Exception/ModuleDeactivationExceptionTest.php @@ -17,7 +17,7 @@ */ final class ModuleDeactivationExceptionTest extends TestCase { - public function testDeactivationException(): void + public function testException(): void { $exception = new ModuleDeactivationException(); diff --git a/tests/Unit/Module/Service/ModuleListInfrastructureTest.php b/tests/Unit/Module/Infrastructure/ModuleListInfrastructureTest.php similarity index 93% rename from tests/Unit/Module/Service/ModuleListInfrastructureTest.php rename to tests/Unit/Module/Infrastructure/ModuleListInfrastructureTest.php index f7d3a83..c13d780 100644 --- a/tests/Unit/Module/Service/ModuleListInfrastructureTest.php +++ b/tests/Unit/Module/Infrastructure/ModuleListInfrastructureTest.php @@ -11,10 +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\Infrastructure\ModuleListInfrastructure; use OxidEsales\GraphQL\ConfigurationAccess\Tests\Unit\UnitTestCase; -use OxidEsales\GraphQL\ConfigurationAccess\Module\DataType\ModuleDataTypeInterface; use OxidEsales\EshopCommunity\Internal\Framework\Module\Configuration\DataObject\ModuleConfiguration; use OxidEsales\GraphQL\ConfigurationAccess\Module\Exception\ModulesNotFoundException; diff --git a/tests/Unit/Module/Service/ModuleActivationsServiceTest.php b/tests/Unit/Module/Service/ModuleActivationsServiceTest.php index 68a2e2e..f5a8b14 100644 --- a/tests/Unit/Module/Service/ModuleActivationsServiceTest.php +++ b/tests/Unit/Module/Service/ModuleActivationsServiceTest.php @@ -12,8 +12,11 @@ use OxidEsales\EshopCommunity\Internal\Transition\Utility\ContextInterface; use OxidEsales\EshopCommunity\Internal\Framework\Module\Setup\Bridge\ModuleActivationBridgeInterface; use OxidEsales\GraphQL\ConfigurationAccess\Module\Exception\ModuleActivationException; +use OxidEsales\GraphQL\ConfigurationAccess\Module\Exception\ModuleActivationBlockedException; +use OxidEsales\GraphQL\ConfigurationAccess\Module\Exception\ModuleDeactivationBlockedException; use OxidEsales\GraphQL\ConfigurationAccess\Module\Exception\ModuleDeactivationException; use OxidEsales\GraphQL\ConfigurationAccess\Module\Service\ModuleActivationService; +use OxidEsales\GraphQL\ConfigurationAccess\Module\Service\ModuleBlocklistServiceInterface; use OxidEsales\GraphQL\ConfigurationAccess\Tests\Unit\UnitTestCase; /** @@ -24,7 +27,7 @@ class ModuleActivationsServiceTest extends UnitTestCase /** * @dataProvider activationDataProvider */ - public function testModuleActivationAndDeactivation( + public function testModuleActivationAndDeactivationSuccess( string $method, ): void { $shopId = 1; @@ -34,6 +37,12 @@ public function testModuleActivationAndDeactivation( ->method($method) ->with($moduleId, $shopId); + $moduleBlocklistServiceMock = $this->createMock(ModuleBlocklistServiceInterface::class); + $moduleBlocklistServiceMock + ->method('isModuleBlocked') + ->with($moduleId) + ->willReturn(false); + $sut = $this->getSut( context: $this->getContextMock($shopId), moduleActivationBridge: $moduleActivationBridgeMock @@ -47,7 +56,7 @@ public function testModuleActivationAndDeactivation( /** * @dataProvider exceptionDataProvider */ - public function testModuleActivationAndDeactivationExceptions( + public function testModuleActivationAndDeactivationThrowsExceptions( string $method, mixed $exceptionClass ): void { @@ -55,17 +64,56 @@ public function testModuleActivationAndDeactivationExceptions( $moduleActivationBridgeMock = $this->createMock(ModuleActivationBridgeInterface::class); $moduleActivationBridgeMock ->method($method) + ->with($moduleId, 1) ->willThrowException(new \Exception()); $this->expectException($exceptionClass); $sut = $this->getSut( + $this->getContextMock(), moduleActivationBridge: $moduleActivationBridgeMock ); ($method === 'activate') ? $sut->activateModule($moduleId) : $sut->deactivateModule($moduleId); } + /** + * @dataProvider moduleBlockedExceptionDataProvider + */ + public function testModuleActivationAndDeactivationBlockedException( + string $method, + mixed $exceptionClass + ) { + $moduleId = uniqid(); + $moduleBlockListServiceMock = $this->createMock(ModuleBlocklistServiceInterface::class); + $moduleBlockListServiceMock + ->method('isModuleBlocked') + ->with($moduleId) + ->willReturn(true); + + $sut = $this->getSut( + moduleBlocklistService: $moduleBlockListServiceMock + ); + + $this->expectException($exceptionClass); + ($method === 'activate') ? $sut->activateModule($moduleId) : $sut->deactivateModule($moduleId); + } + + public static function moduleBlockedExceptionDataProvider(): \Generator + { + yield 'test activate module blocked exception' => [ + 'method' => 'activate', + 'exceptionClass' => ModuleActivationBlockedException::class + + ]; + + yield 'test deactivate module blocked exception' => [ + 'method' => 'deactivate', + 'exceptionClass' => ModuleDeactivationBlockedException::class + + ]; + } + public static function activationDataProvider(): \Generator { yield 'test activate module' => [ @@ -94,13 +142,16 @@ public static function exceptionDataProvider(): \Generator public function getSut( ContextInterface $context = null, - ModuleActivationBridgeInterface $moduleActivationBridge = null + ModuleActivationBridgeInterface $moduleActivationBridge = null, + ModuleBlocklistServiceInterface $moduleBlocklistService = null ): ModuleActivationService { return new ModuleActivationService( context: $context ?? $this->createStub(ContextInterface::class), moduleActivationBridge: $moduleActivationBridge - ?? $this->createStub(ModuleActivationBridgeInterface::class) + ?? $this->createStub(ModuleActivationBridgeInterface::class), + moduleBlocklistService: $moduleBlocklistService + ?? $this->createStub(ModuleBlocklistServiceInterface::class) ); } } diff --git a/tests/Unit/Module/Service/ModuleBlocklistServiceTest.php b/tests/Unit/Module/Service/ModuleBlocklistServiceTest.php new file mode 100644 index 0000000..8026f29 --- /dev/null +++ b/tests/Unit/Module/Service/ModuleBlocklistServiceTest.php @@ -0,0 +1,73 @@ +getFileName())['dirname']; + $filePath = 'testFilePath.yaml'; + $expectedData = ['modules' => ['module1', 'module2']]; + + $configWrapperMock = $this->createMock(DIConfigWrapper::class); + $configWrapperMock + ->method('getConfigAsArray') + ->willReturn($expectedData); + + $projectYamlDaoMock = $this->createMock(ProjectYamlDaoInterface::class); + $projectYamlDaoMock + ->method('loadDIConfigFile') + ->with($classFilePath . '/../' . $filePath) + ->willReturn($configWrapperMock); + + $sut = $this->getSut(moduleBlockListPath: $filePath, projectYamlDao: $projectYamlDaoMock); + $actualResult = $sut->isModuleBlocked(moduleId: $moduleId); + + $this->assertSame($expectedResult, $actualResult); + } + + public static function blockListDataProvider(): \Generator + { + yield 'isModuleBlocked returns true if Module is in the BlockList' => [ + 'moduleId' => 'module1', + 'expectedResult' => true + ]; + + yield 'isModuleBlocked returns false if Module is not in the BlockList' => [ + 'moduleId' => 'unknownModuleId', + 'expectedResult' => false + ]; + } + + private function getSut( + string $moduleBlockListPath, + ProjectYamlDaoInterface $projectYamlDao + ): ModuleBlocklistService { + return new ModuleBlocklistService( + moduleBlocklistPath: $moduleBlockListPath, + projectYamlDao: $projectYamlDao + ); + } +} diff --git a/tests/Unit/Theme/Controller/ThemeSwitchControllerTest.php b/tests/Unit/Theme/Controller/ThemeSwitchControllerTest.php index eb6eb9f..9bc7aee 100644 --- a/tests/Unit/Theme/Controller/ThemeSwitchControllerTest.php +++ b/tests/Unit/Theme/Controller/ThemeSwitchControllerTest.php @@ -20,17 +20,17 @@ class ThemeSwitchControllerTest extends TestCase { /** @dataProvider switchThemeProvider */ public function testSwitchTheme( - string $identifier, + string $themeId, bool $expectedResult ): void { $themeSwitchServiceMock = $this->createMock(ThemeSwitchServiceInterface::class); $themeSwitchServiceMock ->method('switchTheme') - ->with($identifier) + ->with($themeId) ->willReturn($expectedResult); $themeSwitchController = new ThemeSwitchController($themeSwitchServiceMock); - $response = $themeSwitchController->switchTheme($identifier); + $response = $themeSwitchController->switchTheme($themeId); $this->assertSame($expectedResult, $response); } @@ -38,12 +38,12 @@ public function testSwitchTheme( public static function switchThemeProvider(): \Generator { yield 'test switch theme successful case' => [ - 'identifier' => 'validThemeId', + 'themeId' => 'validThemeId', 'expectedResult' => true ]; yield 'test switch theme failure case' => [ - 'identifier' => 'invalidThemeId', + 'themeId' => 'invalidThemeId', 'expectedResult' => false ]; } diff --git a/tests/Unit/Theme/Infrastructure/ThemeSwitchInfrastructureTest.php b/tests/Unit/Theme/Infrastructure/ThemeSwitchInfrastructureTest.php index 2714167..467fbf7 100644 --- a/tests/Unit/Theme/Infrastructure/ThemeSwitchInfrastructureTest.php +++ b/tests/Unit/Theme/Infrastructure/ThemeSwitchInfrastructureTest.php @@ -25,23 +25,23 @@ class ThemeSwitchInfrastructureTest extends TestCase private const THEME_NOT_EXIST = "The specified theme doesn't exist."; public function testSwitchTheme(): void { - $identifier = 'apex'; + $themeId = 'apex'; $coreThemeMock = $this->createMock(Theme::class); - $coreThemeMock->expects($this->once())->method('load')->with($identifier)->willReturn(true); + $coreThemeMock->expects($this->once())->method('load')->with($themeId)->willReturn(true); $coreThemeMock->expects($this->once())->method('activate'); $coreThemeFactoryMock = $this->getCoreThemeFactoryMock(coreThemeMock: $coreThemeMock); $sut = $this->getSut(coreThemeFactory: $coreThemeFactoryMock); - $serviceResponse = $sut->switchTheme($identifier); + $serviceResponse = $sut->switchTheme($themeId); $this->assertTrue($serviceResponse); } public function testThemeNotActivatedException(): void { - $identifier = 'apex'; + $themeId = 'apex'; $coreThemeMock = $this->createMock(Theme::class); - $coreThemeMock->expects($this->once())->method('load')->with($identifier)->willReturn(true); + $coreThemeMock->expects($this->once())->method('load')->with($themeId)->willReturn(true); $coreThemeMock->expects($this->once())->method('activate') ->will($this->throwException( new StandardException(self::THEME_NOT_ACTIVATED) @@ -52,7 +52,7 @@ public function testThemeNotActivatedException(): void $this->expectException(ThemeActivationException::class); $this->expectExceptionMessage(self::THEME_NOT_ACTIVATED); - $sut->switchTheme($identifier); + $sut->switchTheme($themeId); } public function testThemeNotFoundException(): void diff --git a/tests/Unit/Theme/Service/ThemeSwitchServiceTest.php b/tests/Unit/Theme/Service/ThemeSwitchServiceTest.php index 02fcab2..70cb8d0 100644 --- a/tests/Unit/Theme/Service/ThemeSwitchServiceTest.php +++ b/tests/Unit/Theme/Service/ThemeSwitchServiceTest.php @@ -22,15 +22,15 @@ class ThemeSwitchServiceTest extends TestCase public function testSwitchTheme( bool $expectedResult ): void { - $identifier = uniqid(); + $themeId = uniqid(); $themeSwitchInfrastructureMock = $this->createMock(ThemeSwitchInfrastructureInterface::class); $themeSwitchInfrastructureMock ->method('switchTheme') - ->with($identifier) + ->with($themeId) ->willReturn($expectedResult); $themeSwitchInfrastructure = new ThemeSwitchService($themeSwitchInfrastructureMock); - $response = $themeSwitchInfrastructure->switchTheme($identifier); + $response = $themeSwitchInfrastructure->switchTheme($themeId); $this->assertSame($expectedResult, $response); }