From 8d6fbc935de104c523542c39e847ef5510554600 Mon Sep 17 00:00:00 2001 From: Tomasz Kowalewski Date: Fri, 6 Dec 2024 13:55:35 +0100 Subject: [PATCH 1/4] OXDEV-8593 Added parentTheme and parentVersions fields to the ThemeDataType --- CHANGELOG.md | 5 ++++ src/Theme/DataType/ThemeDataType.php | 27 +++++++++++++++++++ src/Theme/DataType/ThemeDataTypeFactory.php | 4 ++- src/Theme/DataType/ThemeDataTypeInterface.php | 9 +++++++ .../Acceptance/Theme/ThemeListCest.php | 2 ++ .../DataType/ThemeDataTypeFactoryTest.php | 4 +++ .../Unit/Theme/DataType/ThemeDataTypeTest.php | 6 ++++- 7 files changed, 55 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d13feff..932d3a9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,11 @@ 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). +## [undecided] - Unreleased + +### Added +- New `parentTheme` and `parentVersions` fields in the `ThemeDataType` + ## [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. diff --git a/src/Theme/DataType/ThemeDataType.php b/src/Theme/DataType/ThemeDataType.php index 07cda0f..13e5bcb 100644 --- a/src/Theme/DataType/ThemeDataType.php +++ b/src/Theme/DataType/ThemeDataType.php @@ -10,9 +10,36 @@ namespace OxidEsales\GraphQL\ConfigurationAccess\Theme\DataType; use OxidEsales\GraphQL\ConfigurationAccess\Shared\DataType\AbstractComponentDataType; +use TheCodingMachine\GraphQLite\Annotations\Field; use TheCodingMachine\GraphQLite\Annotations\Type; #[Type] class ThemeDataType extends AbstractComponentDataType implements ThemeDataTypeInterface { + public function __construct( + string $id, + string $title, + string $version, + string $description, + bool $active, + private readonly ?string $parentTheme, + private readonly ?array $parentVersions, + ) { + parent::__construct($id, $title, $version, $description, $active); + } + + #[Field] + public function getParentTheme(): ?string + { + return $this->parentTheme; + } + + /** + * @return ?string[] + */ + #[Field] + public function getParentVersions(): ?array + { + return $this->parentVersions; + } } diff --git a/src/Theme/DataType/ThemeDataTypeFactory.php b/src/Theme/DataType/ThemeDataTypeFactory.php index 8809fbf..b9dd45e 100644 --- a/src/Theme/DataType/ThemeDataTypeFactory.php +++ b/src/Theme/DataType/ThemeDataTypeFactory.php @@ -21,7 +21,9 @@ public function createFromCoreTheme( title: $theme->getInfo('title'), version: $theme->getInfo('version'), description: $theme->getInfo('description'), - active: $theme->getInfo('active') + active: $theme->getInfo('active'), + parentTheme: $theme->getInfo('parentTheme'), + parentVersions: $theme->getInfo('parentVersions'), ); } } diff --git a/src/Theme/DataType/ThemeDataTypeInterface.php b/src/Theme/DataType/ThemeDataTypeInterface.php index 3aab3bf..86ddd03 100644 --- a/src/Theme/DataType/ThemeDataTypeInterface.php +++ b/src/Theme/DataType/ThemeDataTypeInterface.php @@ -3,9 +3,18 @@ namespace OxidEsales\GraphQL\ConfigurationAccess\Theme\DataType; use OxidEsales\GraphQL\ConfigurationAccess\Shared\DataType\ComponentDataTypeInterface; +use TheCodingMachine\GraphQLite\Annotations\Field; use TheCodingMachine\GraphQLite\Annotations\Type; #[Type] interface ThemeDataTypeInterface extends ComponentDataTypeInterface { + #[Field] + public function getParentTheme(): ?string; + + /** + * @return ?string[] + */ + #[Field] + public function getParentVersions(): ?array; } diff --git a/tests/Codeception/Acceptance/Theme/ThemeListCest.php b/tests/Codeception/Acceptance/Theme/ThemeListCest.php index 8786783..fcdb928 100644 --- a/tests/Codeception/Acceptance/Theme/ThemeListCest.php +++ b/tests/Codeception/Acceptance/Theme/ThemeListCest.php @@ -40,6 +40,8 @@ private function runThemeListQuery(AcceptanceTester $I): array version description active + parentTheme + parentVersions } }' ); diff --git a/tests/Unit/Theme/DataType/ThemeDataTypeFactoryTest.php b/tests/Unit/Theme/DataType/ThemeDataTypeFactoryTest.php index 011e35c..fe69093 100644 --- a/tests/Unit/Theme/DataType/ThemeDataTypeFactoryTest.php +++ b/tests/Unit/Theme/DataType/ThemeDataTypeFactoryTest.php @@ -28,6 +28,8 @@ public function testCreateThemeDataType(): void $expectedVersion = uniqid(); $expectedDescription = uniqid(); $expectedActive = true; + $expectedParentTheme = uniqid(); + $expectedParentVersions = [uniqid(), uniqid()]; $themeMock->method('getInfo') ->willReturnMap([ @@ -36,6 +38,8 @@ public function testCreateThemeDataType(): void ['version', $expectedVersion], ['description', $expectedDescription], ['active', $expectedActive], + ['parentTheme', $expectedParentTheme], + ['parentVersions', $expectedParentVersions], ]); $factory = new ThemeDataTypeFactory(); diff --git a/tests/Unit/Theme/DataType/ThemeDataTypeTest.php b/tests/Unit/Theme/DataType/ThemeDataTypeTest.php index cb8d7b9..058b63a 100644 --- a/tests/Unit/Theme/DataType/ThemeDataTypeTest.php +++ b/tests/Unit/Theme/DataType/ThemeDataTypeTest.php @@ -25,8 +25,10 @@ public function testThemeDataType(): void $version = uniqid(); $description = uniqid(); $active = (bool)random_int(0, 1); + $parentTheme = uniqid(); + $parentVersions = [uniqid(), uniqid()]; - $sut = new ThemeDataType($id, $name, $version, $description, $active); + $sut = new ThemeDataType($id, $name, $version, $description, $active, $parentTheme, $parentVersions); $this->assertInstanceOf(ComponentDataTypeInterface::class, $sut); $this->assertSame($name, $sut->getTitle()); @@ -34,5 +36,7 @@ public function testThemeDataType(): void $this->assertSame($version, $sut->getVersion()); $this->assertSame($description, $sut->getDescription()); $this->assertSame($active, $sut->isActive()); + $this->assertSame($parentTheme, $sut->getParentTheme()); + $this->assertSame($parentVersions, $sut->getParentVersions()); } } From 9caf5c07bc40d4452a2e7749e8544af2e3584fd7 Mon Sep 17 00:00:00 2001 From: marcelmanzel Date: Thu, 12 Dec 2024 11:39:35 +0100 Subject: [PATCH 2/4] OXDEV-8593: Add missing version number; Add tests for default values; --- CHANGELOG.md | 2 +- src/Theme/DataType/ThemeDataType.php | 2 +- .../Theme/DataType/ThemeDataTypeFactoryTest.php | 2 ++ tests/Unit/Theme/DataType/ThemeDataTypeTest.php | 16 ++++++++++++++++ 4 files changed, 20 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 932d3a9..f872149 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,7 +4,7 @@ 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). -## [undecided] - Unreleased +## [2.0.0] - Unreleased ### Added - New `parentTheme` and `parentVersions` fields in the `ThemeDataType` diff --git a/src/Theme/DataType/ThemeDataType.php b/src/Theme/DataType/ThemeDataType.php index 13e5bcb..f4f9a78 100644 --- a/src/Theme/DataType/ThemeDataType.php +++ b/src/Theme/DataType/ThemeDataType.php @@ -35,7 +35,7 @@ public function getParentTheme(): ?string } /** - * @return ?string[] + * @inheritDoc */ #[Field] public function getParentVersions(): ?array diff --git a/tests/Unit/Theme/DataType/ThemeDataTypeFactoryTest.php b/tests/Unit/Theme/DataType/ThemeDataTypeFactoryTest.php index fe69093..7a9b46e 100644 --- a/tests/Unit/Theme/DataType/ThemeDataTypeFactoryTest.php +++ b/tests/Unit/Theme/DataType/ThemeDataTypeFactoryTest.php @@ -51,5 +51,7 @@ public function testCreateThemeDataType(): void $this->assertEquals($expectedVersion, $themeDataType->getVersion()); $this->assertEquals($expectedDescription, $themeDataType->getDescription()); $this->assertTrue($themeDataType->isActive()); + $this->assertEquals($expectedParentTheme, $themeDataType->getParentTheme()); + $this->assertEquals($expectedParentVersions, $themeDataType->getParentVersions()); } } diff --git a/tests/Unit/Theme/DataType/ThemeDataTypeTest.php b/tests/Unit/Theme/DataType/ThemeDataTypeTest.php index 058b63a..a133cdb 100644 --- a/tests/Unit/Theme/DataType/ThemeDataTypeTest.php +++ b/tests/Unit/Theme/DataType/ThemeDataTypeTest.php @@ -39,4 +39,20 @@ public function testThemeDataType(): void $this->assertSame($parentTheme, $sut->getParentTheme()); $this->assertSame($parentVersions, $sut->getParentVersions()); } + + public function testThemeDataTypeWithNullableValues(): void + { + $name = uniqid(); + $id = uniqid(); + $version = uniqid(); + $description = uniqid(); + $active = (bool)random_int(0, 1); + $parentTheme = null; + $parentVersions = null; + + $sut = new ThemeDataType($id, $name, $version, $description, $active, $parentTheme, $parentVersions); + + $this->assertNull($sut->getParentTheme()); + $this->assertNull($sut->getParentVersions()); + } } From 1baee51f596d53385038435fdb9c46493e691c15 Mon Sep 17 00:00:00 2001 From: marcelmanzel Date: Thu, 12 Dec 2024 12:25:24 +0100 Subject: [PATCH 3/4] OXDEV-8593: Fix sonarcloud coverage --- .../oxid-esales/graphql-configuration-access_light.yaml | 8 ++++---- tests/Unit/Theme/DataType/ThemeDataTypeTest.php | 1 + 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/.github/oxid-esales/graphql-configuration-access_light.yaml b/.github/oxid-esales/graphql-configuration-access_light.yaml index 9ae5286..28c5798 100644 --- a/.github/oxid-esales/graphql-configuration-access_light.yaml +++ b/.github/oxid-esales/graphql-configuration-access_light.yaml @@ -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: diff --git a/tests/Unit/Theme/DataType/ThemeDataTypeTest.php b/tests/Unit/Theme/DataType/ThemeDataTypeTest.php index a133cdb..94a6c9d 100644 --- a/tests/Unit/Theme/DataType/ThemeDataTypeTest.php +++ b/tests/Unit/Theme/DataType/ThemeDataTypeTest.php @@ -15,6 +15,7 @@ /** * @covers \OxidEsales\GraphQL\ConfigurationAccess\Shared\DataType\AbstractComponentDataType + * @covers \OxidEsales\GraphQL\ConfigurationAccess\Theme\DataType\ThemeDataType */ class ThemeDataTypeTest extends TestCase { From 3b126da42b944e191e1dc731581c62e0c81d8684 Mon Sep 17 00:00:00 2001 From: marcelmanzel Date: Thu, 12 Dec 2024 12:33:13 +0100 Subject: [PATCH 4/4] OXDEV-8593: Fix return annotation of ThemeDataType::getParentVersions() --- src/Theme/DataType/ThemeDataType.php | 2 +- tests/Codeception/Acceptance/Theme/ThemeListCest.php | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/src/Theme/DataType/ThemeDataType.php b/src/Theme/DataType/ThemeDataType.php index f4f9a78..13e5bcb 100644 --- a/src/Theme/DataType/ThemeDataType.php +++ b/src/Theme/DataType/ThemeDataType.php @@ -35,7 +35,7 @@ public function getParentTheme(): ?string } /** - * @inheritDoc + * @return ?string[] */ #[Field] public function getParentVersions(): ?array diff --git a/tests/Codeception/Acceptance/Theme/ThemeListCest.php b/tests/Codeception/Acceptance/Theme/ThemeListCest.php index fcdb928..c1a8cde 100644 --- a/tests/Codeception/Acceptance/Theme/ThemeListCest.php +++ b/tests/Codeception/Acceptance/Theme/ThemeListCest.php @@ -9,7 +9,6 @@ namespace OxidEsales\GraphQL\ConfigurationAccess\Tests\Codeception\Acceptance\Theme; -use OxidEsales\GraphQL\ConfigurationAccess\Shared\Enum\FieldType; use OxidEsales\GraphQL\ConfigurationAccess\Tests\Codeception\Acceptance\BaseCest; use OxidEsales\GraphQL\ConfigurationAccess\Tests\Codeception\AcceptanceTester;