Skip to content

Commit

Permalink
OXDEV-8489: Move Infrastructure code to service and remove exception
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcelOxid committed Aug 14, 2024
1 parent 06112e1 commit 0f3f2c2
Show file tree
Hide file tree
Showing 10 changed files with 27 additions and 222 deletions.
22 changes: 0 additions & 22 deletions src/Module/Exception/ModuleBlockListException.php

This file was deleted.

33 changes: 0 additions & 33 deletions src/Module/Infrastructure/YamlFileLoaderInfrastructure.php

This file was deleted.

This file was deleted.

21 changes: 7 additions & 14 deletions src/Module/Service/ModuleBlocklistService.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,29 +9,22 @@

namespace OxidEsales\GraphQL\ConfigurationAccess\Module\Service;

use OxidEsales\GraphQL\ConfigurationAccess\Module\Exception\ModuleBlockListException;
use OxidEsales\GraphQL\ConfigurationAccess\Module\Infrastructure\YamlFileLoaderInfrastructureInterface;
use OxidEsales\EshopCommunity\Internal\Framework\DIContainer\Dao\ProjectYamlDaoInterface;

class ModuleBlocklistService implements ModuleBlocklistServiceInterface
{
public function __construct(
private readonly string $moduleBlocklist,
private readonly YamlFileLoaderInfrastructureInterface $yamlFileLoader
private readonly string $moduleBlocklistPath,
private readonly ProjectYamlDaoInterface $projectYamlDao
) {
}

/**
* @inheritDoc
*/
public function isModuleBlocked(string $moduleId): bool
{
try {
$resolvedPath = dirname(__FILE__) . '/' . $this->moduleBlocklist;
$blocklistData = $this->yamlFileLoader->load($resolvedPath);
$resolvedPath = dirname(__FILE__) . '/../' . $this->moduleBlocklistPath;
$configWrapper = $this->projectYamlDao->loadDIConfigFile($resolvedPath);
$blocklistData = $configWrapper->getConfigAsArray();

return in_array($moduleId, $blocklistData['modules'], true);
} catch (\Exception $e) {
throw new ModuleBlockListException();
}
return in_array($moduleId, $blocklistData['modules'], true);
}
}
5 changes: 0 additions & 5 deletions src/Module/Service/ModuleBlocklistServiceInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,7 @@

namespace OxidEsales\GraphQL\ConfigurationAccess\Module\Service;

use OxidEsales\GraphQL\ConfigurationAccess\Module\Exception\ModuleBlockListException;

interface ModuleBlocklistServiceInterface
{
/**
* @throws ModuleBlockListException
*/
public function isModuleBlocked(string $moduleId): bool;
}
7 changes: 2 additions & 5 deletions src/Module/services.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
parameters:
oxidesales.graphqlconfigurationaccess.modules_block_list: '../../../module_blocklist.yaml'
oxidesales.graphqlconfigurationaccess.modules_block_list_path: '../../module_blocklist.yaml'

services:
_defaults:
Expand All @@ -25,10 +25,7 @@ services:
OxidEsales\GraphQL\ConfigurationAccess\Module\Service\ModuleActivationServiceInterface:
class: OxidEsales\GraphQL\ConfigurationAccess\Module\Service\ModuleActivationService

OxidEsales\GraphQL\ConfigurationAccess\Module\Infrastructure\YamlFileLoaderInfrastructureInterface:
class: OxidEsales\GraphQL\ConfigurationAccess\Module\Infrastructure\YamlFileLoaderInfrastructure

OxidEsales\GraphQL\ConfigurationAccess\Module\Service\ModuleBlocklistServiceInterface:
class: OxidEsales\GraphQL\ConfigurationAccess\Module\Service\ModuleBlocklistService
arguments:
$moduleBlocklist: '%oxidesales.graphqlconfigurationaccess.modules_block_list%'
$moduleBlocklistPath: '%oxidesales.graphqlconfigurationaccess.modules_block_list_path%'
27 changes: 0 additions & 27 deletions tests/Unit/Module/Exception/ModuleBlockListExceptionTest.php

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,8 @@

use OxidEsales\EshopCommunity\Internal\Framework\Module\Configuration\Bridge\ShopConfigurationDaoBridgeInterface;
use OxidEsales\EshopCommunity\Internal\Framework\Module\Configuration\DataObject\ShopConfiguration;
use OxidEsales\GraphQL\ConfigurationAccess\Module\DataType\ModuleDataTypeFactoryInterface;
use OxidEsales\GraphQL\ConfigurationAccess\Module\Infrastructure\ModuleListInfrastructure;
use OxidEsales\GraphQL\ConfigurationAccess\Tests\Unit\UnitTestCase;
use OxidEsales\GraphQL\ConfigurationAccess\Module\DataType\ModuleDataTypeInterface;
use OxidEsales\EshopCommunity\Internal\Framework\Module\Configuration\DataObject\ModuleConfiguration;
use OxidEsales\GraphQL\ConfigurationAccess\Module\Exception\ModulesNotFoundException;

Expand Down

This file was deleted.

45 changes: 18 additions & 27 deletions tests/Unit/Module/Service/ModuleBlocklistServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@

namespace OxidEsales\GraphQL\ConfigurationAccess\Tests\Unit\Module\Service;

use OxidEsales\GraphQL\ConfigurationAccess\Module\Exception\ModuleBlockListException;
use OxidEsales\GraphQL\ConfigurationAccess\Module\Infrastructure\YamlFileLoaderInfrastructureInterface;
use OxidEsales\EshopCommunity\Internal\Framework\DIContainer\Dao\ProjectYamlDaoInterface;
use OxidEsales\EshopCommunity\Internal\Framework\DIContainer\DataObject\DIConfigWrapper;
use OxidEsales\GraphQL\ConfigurationAccess\Module\Service\ModuleBlocklistService;
use PHPUnit\Framework\TestCase;

Expand All @@ -26,16 +26,23 @@ public function testIsModuleBlocked(
string $moduleId,
bool $expectedResult
): void {
$reflector = new \ReflectionClass(ModuleBlocklistService::class);
$classFilePath = pathinfo($reflector->getFileName())['dirname'];
$filePath = 'testFilePath.yaml';
$expectedData = ['modules' => ['module1', 'module2']];

$yamlFileLoaderMock = $this->createMock(YamlFileLoaderInfrastructureInterface::class);
$yamlFileLoaderMock
->method('load')
->with($this->stringContains($filePath))
$configWrapperMock = $this->createMock(DIConfigWrapper::class);
$configWrapperMock
->method('getConfigAsArray')
->willReturn($expectedData);

$sut = $this->getSut(moduleBlockList: $filePath, yamlFileLoader: $yamlFileLoaderMock);
$projectYamlDaoMock = $this->createMock(ProjectYamlDaoInterface::class);
$projectYamlDaoMock
->method('loadDIConfigFile')
->with($classFilePath . '/../' . $filePath)
->willReturn($configWrapperMock);

$sut = $this->getSut(moduleBlockListPath: $filePath, projectYamlDao: $projectYamlDaoMock);
$actualResult = $sut->isModuleBlocked(moduleId: $moduleId);

$this->assertSame($expectedResult, $actualResult);
Expand All @@ -54,29 +61,13 @@ public static function blockListDataProvider(): \Generator
];
}

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
string $moduleBlockListPath,
ProjectYamlDaoInterface $projectYamlDao
): ModuleBlocklistService {
return new ModuleBlocklistService(
moduleBlocklist: $moduleBlockList
?? 'testFilePath.yaml',
yamlFileLoader: $yamlFileLoader
?? $this->createStub(YamlFileLoaderInfrastructureInterface::class)
moduleBlocklistPath: $moduleBlockListPath,
projectYamlDao: $projectYamlDao
);
}
}

0 comments on commit 0f3f2c2

Please sign in to comment.