Skip to content

Commit

Permalink
OXDEV-8216 Prepared ModuleSwitchController
Browse files Browse the repository at this point in the history
  • Loading branch information
RahatHameed committed Jul 10, 2024
1 parent 4cef311 commit d410c45
Show file tree
Hide file tree
Showing 2 changed files with 110 additions and 0 deletions.
49 changes: 49 additions & 0 deletions src/Module/Controller/ModuleSwitchController.php
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 tests/Unit/Module/Controller/ModuleSwitchControllerTest.php
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)
);
}
}

0 comments on commit d410c45

Please sign in to comment.