From 55452f959c62c1421a2e5a1fcc0d7860ee284791 Mon Sep 17 00:00:00 2001 From: Ryan Lee Date: Thu, 30 Jan 2025 16:26:58 +0000 Subject: [PATCH 1/2] feat(EZP-32460): Move call to SystemInfoCollector::collect to outside of constructor --- .../Collector/IbexaSystemInfoCollector.php | 25 +++++++++++++------ .../IbexaSystemInfoCollectorTest.php | 19 ++++++++++++++ 2 files changed, 36 insertions(+), 8 deletions(-) diff --git a/src/bundle/SystemInfo/Collector/IbexaSystemInfoCollector.php b/src/bundle/SystemInfo/Collector/IbexaSystemInfoCollector.php index 458e9e0..9a151ef 100644 --- a/src/bundle/SystemInfo/Collector/IbexaSystemInfoCollector.php +++ b/src/bundle/SystemInfo/Collector/IbexaSystemInfoCollector.php @@ -132,6 +132,11 @@ class IbexaSystemInfoCollector implements SystemInfoCollector 'ibexa/commerce', ]; + /** + * @var \Ibexa\Bundle\SystemInfo\SystemInfo\Collector\SystemInfoCollector + */ + private $systemInfoCollector; + /** * @var \Ibexa\Bundle\SystemInfo\SystemInfo\Value\ComposerSystemInfo|null */ @@ -150,15 +155,8 @@ public function __construct( string $kernelProjectDir, bool $debug = false ) { - try { - $composerInfo = $composerCollector->collect(); - if ($composerInfo instanceof ComposerSystemInfo) { - $this->composerInfo = $composerInfo; - } - } catch (ComposerLockFileNotFoundException | ComposerFileValidationException $e) { - // do nothing - } $this->debug = $debug; + $this->systemInfoCollector = $composerCollector; $this->kernelProjectDir = $kernelProjectDir; } @@ -171,6 +169,17 @@ public function __construct( */ public function collect(): IbexaSystemInfo { + if($this->composerInfo === null) { + try { + $composerInfo = $this->systemInfoCollector->collect(); + if ($composerInfo instanceof ComposerSystemInfo) { + $this->composerInfo = $composerInfo; + } + } catch (ComposerLockFileNotFoundException | ComposerFileValidationException $e) { + // do nothing + } + } + $vendorDir = sprintf('%s/vendor/', $this->kernelProjectDir); $ibexa = new IbexaSystemInfo([ diff --git a/tests/bundle/SystemInfo/Collector/IbexaSystemInfoCollectorTest.php b/tests/bundle/SystemInfo/Collector/IbexaSystemInfoCollectorTest.php index 2409316..b352a80 100644 --- a/tests/bundle/SystemInfo/Collector/IbexaSystemInfoCollectorTest.php +++ b/tests/bundle/SystemInfo/Collector/IbexaSystemInfoCollectorTest.php @@ -40,6 +40,25 @@ public function testCollect(): void $systemInfo = $systemInfoCollector->collect(); self::assertSame(IbexaSystemInfo::PRODUCT_NAME_OSS, $systemInfo->name); self::assertSame(Ibexa::VERSION, $systemInfo->release); + + // Test that information from the composer.json file is correctly extracted + self::assertSame('dev', $systemInfo->lowestStability); + } + + public function testCollectWithInvalidComposerJson(): void + { + $composerCollector = new JsonComposerLockSystemInfoCollector( + $this->versionStabilityChecker, + __DIR__ . '/_fixtures/corrupted_composer.lock', + __DIR__ . '/_fixtures/corrupted_composer.json' + ); + + $systemInfoCollector = new IbexaSystemInfoCollector( + $composerCollector, + dirname(__DIR__, 5) + ); + $systemInfo = $systemInfoCollector->collect(); + self::assertNull($systemInfo->lowestStability); } } From 918f9796708698aa5735598f32a11e49ea2c5bb0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adam=20W=C3=B3js?= Date: Sat, 1 Feb 2025 18:28:10 +0100 Subject: [PATCH 2/2] Fixed code style issues --- src/bundle/SystemInfo/Collector/IbexaSystemInfoCollector.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/bundle/SystemInfo/Collector/IbexaSystemInfoCollector.php b/src/bundle/SystemInfo/Collector/IbexaSystemInfoCollector.php index 9a151ef..631612f 100644 --- a/src/bundle/SystemInfo/Collector/IbexaSystemInfoCollector.php +++ b/src/bundle/SystemInfo/Collector/IbexaSystemInfoCollector.php @@ -169,14 +169,14 @@ public function __construct( */ public function collect(): IbexaSystemInfo { - if($this->composerInfo === null) { + if ($this->composerInfo === null) { try { $composerInfo = $this->systemInfoCollector->collect(); if ($composerInfo instanceof ComposerSystemInfo) { $this->composerInfo = $composerInfo; } } catch (ComposerLockFileNotFoundException | ComposerFileValidationException $e) { - // do nothing + // do nothing } }