-
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 ModuleBlocklistService
- Loading branch information
1 parent
d7d3efd
commit ba6ff44
Showing
9 changed files
with
204 additions
and
9 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 = "An error occurred while getting module blocklist."; | ||
|
||
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,36 @@ | ||
<?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 Symfony\Component\Yaml\Yaml; | ||
|
||
class ModuleBlocklistService implements ModuleBlocklistServiceInterface | ||
{ | ||
public function __construct( | ||
private readonly string $moduleBlocklist | ||
) { | ||
} | ||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
public function getModuleBlocklist(): array | ||
{ | ||
try { | ||
$resolvedPath = dirname(__FILE__) . '/' . $this->moduleBlocklist; | ||
$blocklistData = Yaml::parseFile($resolvedPath); | ||
} catch (\Exception $e) { | ||
throw new ModuleBlockListException(); | ||
} | ||
|
||
return $blocklistData['modules']; | ||
} | ||
} |
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,19 @@ | ||
<?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 | ||
* @return array{int : string} | ||
*/ | ||
public function getModuleBlocklist(): array; | ||
} |
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,47 @@ | ||
<?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 org\bovigo\vfs\vfsStream; | ||
use org\bovigo\vfs\vfsStreamDirectory; | ||
use OxidEsales\GraphQL\ConfigurationAccess\Module\Service\ModuleBlocklistService; | ||
use PHPUnit\Framework\TestCase; | ||
use Symfony\Component\Yaml\Yaml; | ||
|
||
/** | ||
* @covers \OxidEsales\GraphQL\ConfigurationAccess\Module\Service\ModuleBlocklistService | ||
*/ | ||
class ModuleBlocklistServiceTest extends TestCase | ||
{ | ||
private vfsStreamDirectory|string $moduleBlocklist; | ||
|
||
protected function setUp(): void | ||
{ | ||
vfsStream::setup('root'); | ||
$this->moduleBlocklist = vfsStream::url('root/moduleBlocklist.yaml'); | ||
} | ||
|
||
public function testGetModuleBlocklist() | ||
{ | ||
$expectedBlocklist = [ | ||
'modules' => [ | ||
'blockedModuleId1', | ||
'blockedModuleId2', | ||
] | ||
]; | ||
|
||
file_put_contents($this->moduleBlocklist, Yaml::dump($expectedBlocklist)); | ||
|
||
$sut = new ModuleBlocklistService($this->moduleBlocklist); | ||
$actualBlocklist = $sut->getModuleBlocklist(); | ||
|
||
$this->assertSame($expectedBlocklist['modules'], $actualBlocklist); | ||
} | ||
} |