From f34a8a6c801ee04c20a46560e5c8ec8744b334a4 Mon Sep 17 00:00:00 2001 From: marcelmanzel Date: Tue, 13 Aug 2024 14:36:39 +0200 Subject: [PATCH] OXDEV-8489: Cleanup rebase conflicts --- CHANGELOG.md | 8 +- .../ModuleSwitchInfrastructure.php | 54 -------- .../ModuleSwitchInfrastructureInterface.php | 24 ---- .../Service/ModuleActivationService.php | 9 +- src/Module/Service/ModuleSwitchService.php | 0 .../Service/ModuleSwitchServiceInterface.php | 0 .../ModuleSwitchInfrastructureTest.php | 115 ------------------ .../Service/ModuleActivationsServiceTest.php | 14 ++- 8 files changed, 21 insertions(+), 203 deletions(-) delete mode 100644 src/Module/Infrastructure/ModuleSwitchInfrastructure.php delete mode 100644 src/Module/Infrastructure/ModuleSwitchInfrastructureInterface.php delete mode 100644 src/Module/Service/ModuleSwitchService.php delete mode 100644 src/Module/Service/ModuleSwitchServiceInterface.php delete mode 100644 tests/Unit/Module/Infrastructure/ModuleSwitchInfrastructureTest.php diff --git a/CHANGELOG.md b/CHANGELOG.md index 0192790..36ce835 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,11 +3,6 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). -## [1.2.0] - Unreleased - -### Added -- Prevention of deactivation of certain modules mentioned in modules_blocklist.yaml. -- Mutations to activate and deactive a module. ## [1.2.0] - Unreleased @@ -16,16 +11,15 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - 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. +- Prevention of deactivation 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 diff --git a/src/Module/Infrastructure/ModuleSwitchInfrastructure.php b/src/Module/Infrastructure/ModuleSwitchInfrastructure.php deleted file mode 100644 index 5d55530..0000000 --- a/src/Module/Infrastructure/ModuleSwitchInfrastructure.php +++ /dev/null @@ -1,54 +0,0 @@ -context->getCurrentShopId(); - $this->moduleActivationBridge->activate(moduleId: $moduleId, shopId: $shopId); - } catch (\Exception $exception) { - throw new ModuleActivationException(); - } - - return true; - } - - /** - * @inheritDoc - */ - public function deactivateModule(string $moduleId): bool - { - try { - $shopId = $this->context->getCurrentShopId(); - $this->moduleActivationBridge->deactivate(moduleId: $moduleId, shopId: $shopId); - } catch (\Exception $exception) { - throw new ModuleDeactivationException(); - } - - return true; - } -} diff --git a/src/Module/Infrastructure/ModuleSwitchInfrastructureInterface.php b/src/Module/Infrastructure/ModuleSwitchInfrastructureInterface.php deleted file mode 100644 index 0558cbc..0000000 --- a/src/Module/Infrastructure/ModuleSwitchInfrastructureInterface.php +++ /dev/null @@ -1,24 +0,0 @@ -moduleBlocklistService->isModuleBlocked($moduleId)) { + throw new ModuleDeactivationException( + sprintf(ModuleDeactivationException::BLOCKED_MODULE_MESSAGE, $moduleId) + ); + } + $shopId = $this->context->getCurrentShopId(); try { diff --git a/src/Module/Service/ModuleSwitchService.php b/src/Module/Service/ModuleSwitchService.php deleted file mode 100644 index e69de29..0000000 diff --git a/src/Module/Service/ModuleSwitchServiceInterface.php b/src/Module/Service/ModuleSwitchServiceInterface.php deleted file mode 100644 index e69de29..0000000 diff --git a/tests/Unit/Module/Infrastructure/ModuleSwitchInfrastructureTest.php b/tests/Unit/Module/Infrastructure/ModuleSwitchInfrastructureTest.php deleted file mode 100644 index 06bbc0f..0000000 --- a/tests/Unit/Module/Infrastructure/ModuleSwitchInfrastructureTest.php +++ /dev/null @@ -1,115 +0,0 @@ -createMock(ModuleActivationBridgeInterface::class); - $moduleActivationBridgeMock - ->method($method) - ->with($moduleId, $shopId); - - $sut = $this->getSut( - context: $this->getContextMock(), - moduleActivationBridge: $moduleActivationBridgeMock - ); - - $result = ($method == 'activate') ? $sut->activateModule($moduleId) : $sut->deactivateModule($moduleId); - - $this->assertTrue($result); - } - - /** - * @dataProvider exceptionDataProvider - */ - public function testModuleActivationAndDeactivationExceptions( - string $method, - string $moduleId, - mixed $exceptionClass - ): void { - - $moduleActivationBridgeMock = $this->createMock(ModuleActivationBridgeInterface::class); - $moduleActivationBridgeMock - ->method($method) - ->willThrowException(new \Exception()); - - $this->expectException($exceptionClass); - $this->expectExceptionMessage($exceptionClass::EXCEPTION_MESSAGE); - - $sut = $this->getSut( - moduleActivationBridge: $moduleActivationBridgeMock - ); - - ($method === 'activate') ? $sut->activateModule($moduleId) : $sut->deactivateModule($moduleId); - } - - public static function activationDataProvider(): \Generator - { - yield 'test activate module' => [ - 'method' => 'activate', - 'moduleId' => uniqid(), - 'shopId' => 1 - ]; - - yield 'test deactivate module' => [ - 'method' => 'deactivate', - 'moduleId' => uniqid(), - 'shopId' => 1 - ]; - } - - public static function exceptionDataProvider(): \Generator - { - $moduleId = uniqid(); - yield 'test activate module throws exception' => [ - 'method' => 'activate', - 'moduleId' => $moduleId, - 'exceptionClass' => ModuleActivationException::class, - - ]; - - yield 'test deactivate module throws exception' => [ - 'method' => 'deactivate', - 'moduleId' => uniqid(), - 'exceptionClass' => ModuleDeactivationException::class, - - ]; - } - - public function getSut( - ContextInterface $context = null, - ModuleActivationBridgeInterface $moduleActivationBridge = null - ): ModuleSwitchInfrastructure { - return new ModuleSwitchInfrastructure( - context: $context - ?? $this->createStub(ContextInterface::class), - moduleActivationBridge: $moduleActivationBridge - ?? $this->createStub(ModuleActivationBridgeInterface::class) - ); - } -} diff --git a/tests/Unit/Module/Service/ModuleActivationsServiceTest.php b/tests/Unit/Module/Service/ModuleActivationsServiceTest.php index 68a2e2e..e4769ff 100644 --- a/tests/Unit/Module/Service/ModuleActivationsServiceTest.php +++ b/tests/Unit/Module/Service/ModuleActivationsServiceTest.php @@ -14,6 +14,7 @@ use OxidEsales\GraphQL\ConfigurationAccess\Module\Exception\ModuleActivationException; 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; /** @@ -34,6 +35,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 @@ -94,13 +101,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) ); } }