Skip to content

Commit

Permalink
Merge branch 'b-7.2.x-code-coverage-OXDEV-8952' into b-7.2.x
Browse files Browse the repository at this point in the history
  • Loading branch information
tkcreateit committed Dec 20, 2024
2 parents bf2f233 + 91f5515 commit 640c891
Show file tree
Hide file tree
Showing 22 changed files with 272 additions and 90 deletions.
8 changes: 4 additions & 4 deletions .github/oxid-esales/graphql-configuration-access_light.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,10 @@ sonarcloud:
project_key: 'OXID-eSales_graphql-configuration-access'
project_name: 'oxid-esales/graphql-configuration-access'
parameters: |
-Dsonar.language=php
-Dsonar.scm.provider=git
-Dsonar.sources=src
-Dsonar.tests=tests
-Dsonar.language=php \
-Dsonar.scm.provider=git \
-Dsonar.sources=src \
-Dsonar.tests=tests \
-Dsonar.php.phpstan.reportPaths=coverage-reports/phpstan.report.json
finish:
Expand Down
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [2.0.0] - unreleased

### Changed
- Move ModuleDataType generation to Infrastructure
- Move ThemeDataType generation to Infrastructure

## [1.2.0] - 2024-11-27
This is the stable release of v1.2.0. No changes have been made since v1.2.0-rc.1.

Expand Down Expand Up @@ -35,6 +41,7 @@ This is stable release for v1.1.0. No changes have been made since v1.1.0-rc.1.

- Initial release

[2.0.0]: https://github.com/OXID-eSales/graphql-configuration-access/compare/v1.2.0...b-7.2.x
[1.2.0]: https://github.com/OXID-eSales/graphql-configuration-access/compare/v1.2.0-rc.1...v1.2.0
[1.2.0-rc.1]: https://github.com/OXID-eSales/graphql-configuration-access/compare/v1.1.0...v1.2.0-rc.1
[1.1.0]: https://github.com/OXID-eSales/graphql-configuration-access/compare/v1.1.0-rc.1...v1.1.0
Expand Down
12 changes: 9 additions & 3 deletions src/Module/Infrastructure/ModuleListInfrastructure.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,18 @@
namespace OxidEsales\GraphQL\ConfigurationAccess\Module\Infrastructure;

use OxidEsales\EshopCommunity\Internal\Framework\Module\Configuration\Bridge\ShopConfigurationDaoBridgeInterface;
use OxidEsales\GraphQL\ConfigurationAccess\Module\DataType\ModuleDataTypeFactoryInterface;
use OxidEsales\GraphQL\ConfigurationAccess\Module\Exception\ModulesNotFoundException;

class ModuleListInfrastructure implements ModuleListInfrastructureInterface
{
public function __construct(
private readonly ShopConfigurationDaoBridgeInterface $shopConfigurationDaoBridge
private readonly ShopConfigurationDaoBridgeInterface $shopConfigurationDaoBridge,
private readonly ModuleDataTypeFactoryInterface $moduleDataTypeFactory
) {
}

public function getModuleConfigurations(): array
public function getModuleList(): array
{
$shopConfiguration = $this->shopConfigurationDaoBridge->get();
$moduleConfigurations = $shopConfiguration->getModuleConfigurations();
Expand All @@ -28,6 +30,10 @@ public function getModuleConfigurations(): array
throw new ModulesNotFoundException();
}

return $moduleConfigurations;
$moduleDatatypes = [];
foreach ($moduleConfigurations as $moduleConfig) {
$moduleDatatypes[] = $this->moduleDataTypeFactory->createFromModuleConfiguration($moduleConfig);
}
return $moduleDatatypes;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@

namespace OxidEsales\GraphQL\ConfigurationAccess\Module\Infrastructure;

use OxidEsales\GraphQL\ConfigurationAccess\Module\DataType\ModuleDataTypeInterface;
use OxidEsales\GraphQL\ConfigurationAccess\Module\Exception\ModulesNotFoundException;
use OxidEsales\EshopCommunity\Internal\Framework\Module\Configuration\DataObject\ModuleConfiguration;

interface ModuleListInfrastructureInterface
{
/**
* @return array<ModuleConfiguration>
* @throws ModulesNotFoundException
* @return array<ModuleDataTypeInterface>
*/
public function getModuleConfigurations(): array;
public function getModuleList(): array;
}
10 changes: 2 additions & 8 deletions src/Module/Service/ModuleListService.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

namespace OxidEsales\GraphQL\ConfigurationAccess\Module\Service;

use OxidEsales\GraphQL\ConfigurationAccess\Module\DataType\ModuleDataTypeFactoryInterface;
use OxidEsales\GraphQL\ConfigurationAccess\Module\Infrastructure\ModuleListInfrastructureInterface;
use OxidEsales\GraphQL\ConfigurationAccess\Shared\DataType\ComponentFiltersInterface;
use OxidEsales\GraphQL\ConfigurationAccess\Shared\Service\ComponentFilterServiceInterface;
Expand All @@ -19,18 +18,13 @@ final class ModuleListService implements ModuleListServiceInterface
public function __construct(
private readonly ModuleListInfrastructureInterface $moduleListInfrastructure,
private readonly ComponentFilterServiceInterface $componentFilterService,
private readonly ModuleDataTypeFactoryInterface $moduleDataTypeFactory
) {
}

public function getModuleList(ComponentFiltersInterface $filters): array
{
$modulesArray = [];
$moduleConfigurations = $this->moduleListInfrastructure->getModuleConfigurations();
foreach ($moduleConfigurations as $moduleConfig) {
$modulesArray[] = $this->moduleDataTypeFactory->createFromModuleConfiguration($moduleConfig);
}
$moduleConfigurations = $this->moduleListInfrastructure->getModuleList();

return $this->componentFilterService->filterComponents($modulesArray, $filters);
return $this->componentFilterService->filterComponents($moduleConfigurations, $filters);
}
}
3 changes: 3 additions & 0 deletions src/Shared/Subscriber/BeforeModuleDeactivation.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@

final class BeforeModuleDeactivation implements EventSubscriberInterface
{
/**
* @param string[] $dependencies
*/
public function __construct(
private array $dependencies
) {
Expand Down
14 changes: 12 additions & 2 deletions src/Theme/Infrastructure/ThemeListInfrastructure.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,20 @@

namespace OxidEsales\GraphQL\ConfigurationAccess\Theme\Infrastructure;

use OxidEsales\GraphQL\ConfigurationAccess\Theme\DataType\ThemeDataTypeFactoryInterface;
use OxidEsales\GraphQL\ConfigurationAccess\Theme\Exception\ThemesNotFound;

final class ThemeListInfrastructure implements ThemeListInfrastructureInterface
{
public function __construct(
private readonly CoreThemeFactoryInterface $coreThemeFactory
private readonly CoreThemeFactoryInterface $coreThemeFactory,
private readonly ThemeDataTypeFactoryInterface $themeDataTypeFactory
) {
}

/**
* @inheritDoc
*/
public function getThemes(): array
{
$coreThemeService = $this->coreThemeFactory->create();
Expand All @@ -27,6 +32,11 @@ public function getThemes(): array
throw new ThemesNotFound();
}

return $themesList;
$themeDataTypes = [];
foreach ($themesList as $theme) {
$themeDataTypes[] = $this->themeDataTypeFactory->createFromCoreTheme(theme: $theme);
}

return $themeDataTypes;
}
}
4 changes: 2 additions & 2 deletions src/Theme/Infrastructure/ThemeListInfrastructureInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@

namespace OxidEsales\GraphQL\ConfigurationAccess\Theme\Infrastructure;

use OxidEsales\Eshop\Core\Theme;
use OxidEsales\GraphQL\ConfigurationAccess\Theme\DataType\ThemeDataTypeInterface;
use OxidEsales\GraphQL\ConfigurationAccess\Theme\Exception\ThemesNotFound;

interface ThemeListInfrastructureInterface
{
/**
* @return array<Theme>
* @return ThemeDataTypeInterface[]
* @throws ThemesNotFound
*/
public function getThemes(): array;
Expand Down
12 changes: 3 additions & 9 deletions src/Theme/Service/ThemeListService.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,26 +11,20 @@

use OxidEsales\GraphQL\ConfigurationAccess\Shared\DataType\ComponentFiltersInterface;
use OxidEsales\GraphQL\ConfigurationAccess\Shared\Service\ComponentFilterServiceInterface;
use OxidEsales\GraphQL\ConfigurationAccess\Theme\DataType\ThemeDataTypeFactoryInterface;
use OxidEsales\GraphQL\ConfigurationAccess\Theme\Infrastructure\ThemeListInfrastructureInterface;

final class ThemeListService implements ThemeListServiceInterface
{
public function __construct(
private readonly ThemeListInfrastructureInterface $themeListInfrastructure,
private readonly ComponentFilterServiceInterface $componentFilterService,
private readonly ThemeDataTypeFactoryInterface $themeDataTypeFactory
private readonly ComponentFilterServiceInterface $componentFilterService
) {
}

public function getThemeList(ComponentFiltersInterface $filters): array
{
$themesArray = [];
$themesList = $this->themeListInfrastructure->getThemes();
foreach ($themesList as $theme) {
$themesArray[] = $this->themeDataTypeFactory->createFromCoreTheme(theme: $theme);
}
$themeDataTypes = $this->themeListInfrastructure->getThemes();

return $this->componentFilterService->filterComponents($themesArray, $filters);
return $this->componentFilterService->filterComponents($themeDataTypes, $filters);
}
}
26 changes: 17 additions & 9 deletions tests/Integration/Infrastructure/ModuleListInfrastructureTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
use OxidEsales\EshopCommunity\Internal\Framework\Module\Configuration\Bridge\ShopConfigurationDaoBridgeInterface;
use OxidEsales\EshopCommunity\Internal\Framework\Module\Configuration\DataObject\ModuleConfiguration;
use OxidEsales\EshopCommunity\Tests\Integration\IntegrationTestCase;
use OxidEsales\GraphQL\ConfigurationAccess\Module\DataType\ModuleDataTypeFactoryInterface;
use OxidEsales\GraphQL\ConfigurationAccess\Module\DataType\ModuleDataTypeInterface;
use OxidEsales\GraphQL\ConfigurationAccess\Module\Infrastructure\ModuleListInfrastructure;

class ModuleListInfrastructureTest extends IntegrationTestCase
Expand All @@ -24,31 +26,37 @@ public function testGetModuleList()

$moduleConfiguration1 = new ModuleConfiguration();
$moduleConfiguration1->setId('firstModule');
$moduleConfiguration1->setTitle(['en' => 'Module 1']);
$moduleConfiguration1->setDescription(['en' => 'Module 1 description']);
$moduleConfiguration1->setLang('en');
$moduleConfiguration1->setModuleSource('test');

$moduleConfiguration2 = new ModuleConfiguration();
$moduleConfiguration2->setId('secondModule');
$moduleConfiguration2->setTitle(['en' => 'Module 2']);
$moduleConfiguration2->setDescription(['en' => 'Module 2 description']);
$moduleConfiguration2->setLang('en');
$moduleConfiguration2->setModuleSource('test1');

$shopConfiguration
->addModuleConfiguration($moduleConfiguration1)
->addModuleConfiguration($moduleConfiguration2);
$shopConfigurationDaoBridge->save($shopConfiguration);

$sut = new ModuleListInfrastructure(
$shopConfigurationDaoBridge
);
$modulesList = $sut->getModuleConfigurations();
$this->assertEquals([
$moduleConfiguration1->getId() => $moduleConfiguration1,
$moduleConfiguration2->getId() => $moduleConfiguration2
], $modulesList);
$sut = $this->getSut();
$modulesList = $sut->getModuleList();
$this->assertCount(2, $modulesList);
$this->assertInstanceOf(ModuleDataTypeInterface::class, $modulesList[0]);
$this->assertInstanceOf(ModuleDataTypeInterface::class, $modulesList[1]);
$this->assertSame($modulesList[0]->getId(), $moduleConfiguration1->getId());
$this->assertSame($modulesList[1]->getId(), $moduleConfiguration2->getId());
}

public function getSut(): ModuleListInfrastructure
{
return new ModuleListInfrastructure(
$this->get(ShopConfigurationDaoBridgeInterface::class)
$this->get(ShopConfigurationDaoBridgeInterface::class),
$this->get(ModuleDataTypeFactoryInterface::class)
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@

namespace OxidEsales\GraphQL\ConfigurationAccess\Tests\Integration\Infrastructure;

use OxidEsales\Eshop\Core\Theme;
use OxidEsales\EshopCommunity\Tests\Integration\IntegrationTestCase;
use OxidEsales\GraphQL\ConfigurationAccess\Theme\DataType\ThemeDataTypeFactoryInterface;
use OxidEsales\GraphQL\ConfigurationAccess\Theme\DataType\ThemeDataTypeInterface;
use OxidEsales\GraphQL\ConfigurationAccess\Theme\Infrastructure\CoreThemeFactoryInterface;
use OxidEsales\GraphQL\ConfigurationAccess\Theme\Infrastructure\ThemeListInfrastructure;

Expand All @@ -28,14 +29,15 @@ public function testGetThemesValidData(): void
$this->assertIsArray($themesArray);

foreach ($themesArray as $theme) {
$this->assertInstanceOf(Theme::class, $theme);
$this->assertInstanceOf(ThemeDataTypeInterface::class, $theme);
}
}

public function getSut(): ThemeListInfrastructure
{
return new ThemeListInfrastructure(
$this->get(CoreThemeFactoryInterface::class),
$this->get(ThemeDataTypeFactoryInterface::class)
);
}
}
34 changes: 22 additions & 12 deletions tests/Unit/Module/Infrastructure/ModuleListInfrastructureTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +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\DataType\ModuleDataTypeInterface;
use OxidEsales\GraphQL\ConfigurationAccess\Module\Infrastructure\ModuleListInfrastructure;
use OxidEsales\GraphQL\ConfigurationAccess\Tests\Unit\UnitTestCase;
use OxidEsales\EshopCommunity\Internal\Framework\Module\Configuration\DataObject\ModuleConfiguration;
Expand All @@ -23,32 +25,37 @@ class ModuleListInfrastructureTest extends UnitTestCase
{
public function testGetModuleList()
{
$moduleConfigurationMock = $this->createMock(ModuleConfiguration::class);
$moduleConfigurationStub = $this->createStub(ModuleConfiguration::class);
$moduleDataType = $this->createStub(ModuleDataTypeInterface::class);

$shopConfigurationMock = $this->createMock(ShopConfiguration::class);
$shopConfigurationMock
->method('getModuleConfigurations')
->willReturn([$moduleConfigurationMock]);
->willReturn([$moduleConfigurationStub]);

$shopConfigurationDaoBridgeMock = $this->createMock(ShopConfigurationDaoBridgeInterface::class);
$shopConfigurationDaoBridgeMock
->method('get')
$shopConfigurationDaoBridgeMock->method('get')
->willReturn($shopConfigurationMock);

$moduleDataTypeFactoryMock = $this->createMock(ModuleDataTypeFactoryInterface::class);
$moduleDataTypeFactoryMock->method('createFromModuleConfiguration')
->with($moduleConfigurationStub)
->willReturn($moduleDataType);

$sut = $this->getSut(
shopConfigurationDaoBridgeMock: $shopConfigurationDaoBridgeMock
shopConfigurationDaoBridgeMock: $shopConfigurationDaoBridgeMock,
moduleDataTypeFactory: $moduleDataTypeFactoryMock
);

$result = $sut->getModuleConfigurations();
$result = $sut->getModuleList();

$this->assertSame([$moduleConfigurationMock], $result);
$this->assertSame([$moduleDataType], $result);
}

public function testGetModuleListThrowsException()
{
$shopConfigurationDaoBridgeMock = $this->createMock(ShopConfigurationDaoBridgeInterface::class);
$shopConfigurationDaoBridgeMock
->method('get')
$shopConfigurationDaoBridgeMock->method('get')
->willReturn($this->createMock(ShopConfiguration::class));

$this->expectException(ModulesNotFoundException::class);
Expand All @@ -57,14 +64,17 @@ public function testGetModuleListThrowsException()
shopConfigurationDaoBridgeMock: $shopConfigurationDaoBridgeMock
);

$sut->getModuleConfigurations();
$sut->getModuleList();
}

public function getSut(
?ShopConfigurationDaoBridgeInterface $shopConfigurationDaoBridgeMock = null
?ShopConfigurationDaoBridgeInterface $shopConfigurationDaoBridgeMock = null,
?ModuleDataTypeFactoryInterface $moduleDataTypeFactory = null
): ModuleListInfrastructure {
return new ModuleListInfrastructure(
$shopConfigurationDaoBridgeMock ?? $this->createMock(ShopConfigurationDaoBridgeInterface::class)
shopConfigurationDaoBridge: $shopConfigurationDaoBridgeMock ??
$this->createStub(ShopConfigurationDaoBridgeInterface::class),
moduleDataTypeFactory: $moduleDataTypeFactory ?? $this->createStub(ModuleDataTypeFactoryInterface::class)
);
}
}
Loading

0 comments on commit 640c891

Please sign in to comment.