-
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-8489 Prepared & Consumed ModuleBlocklistService
Prepared this service ModuleBlocklistService Consumed above service in ModuleSwitchService
- Loading branch information
1 parent
7d0e0eb
commit eda1e03
Showing
12 changed files
with
238 additions
and
6 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,3 @@ | ||
modules: | ||
- oe_graphql_base | ||
- oe_graphql_configuration_access |
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,22 @@ | ||
<?php | ||
|
||
/** | ||
* Copyright © OXID eSales AG. All rights reserved. | ||
* See LICENSE file for license details. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace OxidEsales\GraphQL\ConfigurationAccess\Module\Exception; | ||
|
||
use OxidEsales\GraphQL\Base\Exception\NotFound; | ||
|
||
final class ModuleBlockListException extends NotFound | ||
{ | ||
public const EXCEPTION_MESSAGE = "Failed to load module blocklist from YAML file."; | ||
|
||
public function __construct() | ||
{ | ||
parent::__construct(self::EXCEPTION_MESSAGE); | ||
} | ||
} |
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
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,37 @@ | ||
<?php | ||
|
||
/** | ||
* Copyright © OXID eSales AG. All rights reserved. | ||
* See LICENSE file for license details. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace OxidEsales\GraphQL\ConfigurationAccess\Module\Service; | ||
|
||
use OxidEsales\GraphQL\ConfigurationAccess\Module\Exception\ModuleBlockListException; | ||
use OxidEsales\GraphQL\ConfigurationAccess\Module\Infrastructure\YamlFileLoaderInfrastructureInterface; | ||
|
||
class ModuleBlocklistService implements ModuleBlocklistServiceInterface | ||
{ | ||
public function __construct( | ||
private readonly string $moduleBlocklist, | ||
private readonly YamlFileLoaderInfrastructureInterface $yamlFileLoader | ||
) { | ||
} | ||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
public function isModuleBlocked(string $moduleId): bool | ||
{ | ||
try { | ||
$resolvedPath = dirname(__FILE__) . '/' . $this->moduleBlocklist; | ||
$blocklistData = $this->yamlFileLoader->load($resolvedPath); | ||
|
||
return in_array($moduleId, $blocklistData['modules'], true); | ||
} catch (\Exception $e) { | ||
throw new ModuleBlockListException(); | ||
} | ||
} | ||
} |
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,18 @@ | ||
<?php | ||
|
||
/** | ||
* Copyright © OXID eSales AG. All rights reserved. | ||
* See LICENSE file for license details. | ||
*/ | ||
|
||
namespace OxidEsales\GraphQL\ConfigurationAccess\Module\Service; | ||
|
||
use OxidEsales\GraphQL\ConfigurationAccess\Module\Exception\ModuleBlockListException; | ||
|
||
interface ModuleBlocklistServiceInterface | ||
{ | ||
/** | ||
* @throws ModuleBlockListException | ||
*/ | ||
public function isModuleBlocked(string $moduleId): bool; | ||
} |
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
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
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
27 changes: 27 additions & 0 deletions
27
tests/Unit/Module/Exception/ModuleBlockListExceptionTest.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,27 @@ | ||
<?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\Exception; | ||
|
||
use OxidEsales\GraphQL\ConfigurationAccess\Module\Exception\ModuleBlockListException; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
/** | ||
* @covers \OxidEsales\GraphQL\ConfigurationAccess\Module\Exception\ModuleBlockListException | ||
*/ | ||
final class ModuleBlockListExceptionTest extends TestCase | ||
{ | ||
public function testException(): void | ||
{ | ||
$exception = new ModuleBlockListException(); | ||
|
||
$this->assertInstanceOf(ModuleBlockListException::class, $exception); | ||
$this->assertSame(ModuleBlockListException::EXCEPTION_MESSAGE, $exception->getMessage()); | ||
} | ||
} |
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
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,82 @@ | ||
<?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\Service; | ||
|
||
use OxidEsales\GraphQL\ConfigurationAccess\Module\Exception\ModuleBlockListException; | ||
use OxidEsales\GraphQL\ConfigurationAccess\Module\Infrastructure\YamlFileLoaderInfrastructureInterface; | ||
use OxidEsales\GraphQL\ConfigurationAccess\Module\Service\ModuleBlocklistService; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
/** | ||
* @covers \OxidEsales\GraphQL\ConfigurationAccess\Module\Service\ModuleBlocklistService | ||
*/ | ||
class ModuleBlocklistServiceTest extends TestCase | ||
{ | ||
/** | ||
* @dataProvider blockListDataProvider | ||
*/ | ||
public function testIsModuleBlocked( | ||
string $moduleId, | ||
bool $expectedResult | ||
): void { | ||
$filePath = 'testFilePath.yaml'; | ||
$expectedData = ['modules' => ['module1', 'module2']]; | ||
|
||
$yamlFileLoaderMock = $this->createMock(YamlFileLoaderInfrastructureInterface::class); | ||
$yamlFileLoaderMock | ||
->method('load') | ||
->with($this->stringContains($filePath)) | ||
->willReturn($expectedData); | ||
|
||
$sut = $this->getSut(moduleBlockList: $filePath, yamlFileLoader: $yamlFileLoaderMock); | ||
$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 | ||
]; | ||
} | ||
|
||
public function testGetModuleBlocklistThrowsExceptionOnFailure(): void | ||
{ | ||
$moduleId = uniqid(); | ||
$yamlFileLoaderMock = $this->createMock(YamlFileLoaderInfrastructureInterface::class); | ||
$yamlFileLoaderMock | ||
->method('load') | ||
->will($this->throwException(new \Exception('Failed to load YAML file'))); | ||
|
||
$this->expectException(ModuleBlockListException::class); | ||
|
||
$sut = $this->getSut(yamlFileLoader: $yamlFileLoaderMock); | ||
$sut->isModuleBlocked(moduleId: $moduleId); | ||
} | ||
|
||
private function getSut( | ||
string $moduleBlockList = null, | ||
YamlFileLoaderInfrastructureInterface $yamlFileLoader = null | ||
): ModuleBlocklistService { | ||
return new ModuleBlocklistService( | ||
moduleBlocklist: $moduleBlockList | ||
?? 'testFilePath.yaml', | ||
yamlFileLoader: $yamlFileLoader | ||
?? $this->createStub(YamlFileLoaderInfrastructureInterface::class) | ||
); | ||
} | ||
} |
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