-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
OXDEV-8216 Prepared ModuleSwitchController
- Loading branch information
1 parent
4cef311
commit d410c45
Showing
2 changed files
with
110 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
<?php | ||
|
||
/** | ||
* Copyright © OXID eSales AG. All rights reserved. | ||
* See LICENSE file for license details. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace OxidEsales\GraphQL\ConfigurationAccess\Module\Controller; | ||
|
||
use OxidEsales\GraphQL\ConfigurationAccess\Module\Service\ModuleSwitchServiceInterface; | ||
use TheCodingMachine\GraphQLite\Annotations\Logged; | ||
use TheCodingMachine\GraphQLite\Annotations\Mutation; | ||
use TheCodingMachine\GraphQLite\Annotations\Right; | ||
|
||
class ModuleSwitchController | ||
{ | ||
public function __construct( | ||
private readonly ModuleSwitchServiceInterface $moduleSwitchService | ||
) { | ||
} | ||
|
||
/** | ||
* Mutation of Configuration Access Module | ||
* @param string $moduleId | ||
* @return bool | ||
*/ | ||
#[Mutation] | ||
#[Logged] | ||
#[Right('CHANGE_CONFIGURATION')] | ||
public function activateModule(string $moduleId): bool | ||
{ | ||
return $this->moduleSwitchService->activateModule(moduleId: $moduleId); | ||
} | ||
|
||
/** | ||
* Mutation of Configuration Access Module | ||
* @param string $moduleId | ||
* @return bool | ||
*/ | ||
#[Mutation] | ||
#[Logged] | ||
#[Right('CHANGE_CONFIGURATION')] | ||
public function deactivateModule(string $moduleId): bool | ||
{ | ||
return $this->moduleSwitchService->deactivateModule(moduleId: $moduleId); | ||
} | ||
} |
61 changes: 61 additions & 0 deletions
61
tests/Unit/Module/Controller/ModuleSwitchControllerTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
<?php | ||
|
||
/** | ||
* Copyright © OXID eSales AG. All rights reserved. | ||
* See LICENSE file for license details. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace OxidEsales\GraphQL\ConfigurationAccess\Tests\Unit\Module\Controller; | ||
|
||
use OxidEsales\GraphQL\ConfigurationAccess\Module\Controller\ModuleSwitchController; | ||
use OxidEsales\GraphQL\ConfigurationAccess\Module\Service\ModuleSwitchServiceInterface; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
/** | ||
* @covers \OxidEsales\GraphQL\ConfigurationAccess\Module\Controller\ModuleSwitchController | ||
*/ | ||
class ModuleSwitchControllerTest extends TestCase | ||
{ | ||
public function testActivateModule(): void | ||
{ | ||
$moduleId = 'testModuleId'; | ||
|
||
$moduleSwitchServiceMock = $this->createMock(ModuleSwitchServiceInterface::class); | ||
$moduleSwitchServiceMock | ||
->method('activateModule') | ||
->with($moduleId) | ||
->willReturn(true); | ||
|
||
$sut = $this->getSut(moduleSwitchService: $moduleSwitchServiceMock); | ||
|
||
$result = $sut->activateModule($moduleId); | ||
$this->assertTrue($result); | ||
} | ||
|
||
public function testDeactivateModule(): void | ||
{ | ||
$moduleId = 'testModuleId'; | ||
|
||
$moduleSwitchServiceMock = $this->createMock(ModuleSwitchServiceInterface::class); | ||
$moduleSwitchServiceMock | ||
->method('deactivateModule') | ||
->with($moduleId) | ||
->willReturn(true); | ||
|
||
$sut = $this->getSut(moduleSwitchService: $moduleSwitchServiceMock); | ||
|
||
$result = $sut->deactivateModule($moduleId); | ||
$this->assertTrue($result); | ||
} | ||
|
||
public function getSut( | ||
ModuleSwitchServiceInterface $moduleSwitchService = null | ||
): ModuleSwitchController { | ||
return new ModuleSwitchController( | ||
moduleSwitchService: $moduleSwitchService | ||
?? $this->createStub(ModuleSwitchServiceInterface::class) | ||
); | ||
} | ||
} |