From 0c7606851b0bbd088e2ab067eff6ff199c24bcd9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9o=20FIDRY?= <5175937+theofidry@users.noreply.github.com> Date: Sat, 4 Nov 2023 12:36:01 +0100 Subject: [PATCH] test: Fix the Composer orchestrator integration tests (#1143) In #1082 the test cases where incorrectly refactored making them share the same condition. --- ...seComposerOrchestratorComposerTestCase.php | 29 ++++++++++++------- ...ComposerOrchestratorComposer22TestCase.php | 9 ++++++ ...ComposerOrchestratorComposer23TestCase.php | 9 ++++++ ...ComposerOrchestratorComposer24TestCase.php | 8 +++++ 4 files changed, 44 insertions(+), 11 deletions(-) diff --git a/tests/Composer/BaseComposerOrchestratorComposerTestCase.php b/tests/Composer/BaseComposerOrchestratorComposerTestCase.php index 750c87a75..a085de04a 100644 --- a/tests/Composer/BaseComposerOrchestratorComposerTestCase.php +++ b/tests/Composer/BaseComposerOrchestratorComposerTestCase.php @@ -21,7 +21,6 @@ use function file_exists; use function iterator_to_array; use function sprintf; -use function version_compare; abstract class BaseComposerOrchestratorComposerTestCase extends FileSystemTestCase { @@ -29,31 +28,39 @@ abstract class BaseComposerOrchestratorComposerTestCase extends FileSystemTestCa protected const COMPOSER_AUTOLOADER_NAME = 'ComposerAutoloaderInit80c62b20a4a44fb21e8e102ccb92ff05'; protected ComposerOrchestrator $composerOrchestrator; - protected string $composerVersion; + protected bool $skip; + protected string $skipReason; protected function setUp(): void { $this->composerOrchestrator = ComposerOrchestrator::create(); - if (!isset($this->skip)) { - $this->composerVersion = $this->composerOrchestrator->getVersion(); + if (!isset($this->skip, $this->skipReason)) { + $composerVersion = $this->composerOrchestrator->getVersion(); + + [$skip, $supportedConstraint] = $this->shouldSkip($composerVersion); - $this->skip = version_compare($this->composerVersion, '2.3.0', '>='); + $this->skip = $skip; + $this->skipReason = sprintf( + 'Can only be executed with Composer %s. Got "%s".', + $supportedConstraint, + $composerVersion, + ); } if ($this->skip) { - self::markTestSkipped( - sprintf( - 'Can only be executed with Composer ~2.2.0. Got "%s".', - $this->composerVersion, - ), - ); + self::markTestSkipped($this->skipReason); } parent::setUp(); } + /** + * @return array{bool, string} + */ + abstract protected function shouldSkip(string $composerVersion): array; + /** * @param array $recordedClasses * @param array $recordedFunctions diff --git a/tests/Composer/ComposerOrchestratorComposer22TestCase.php b/tests/Composer/ComposerOrchestratorComposer22TestCase.php index 451dc7f07..235004b19 100644 --- a/tests/Composer/ComposerOrchestratorComposer22TestCase.php +++ b/tests/Composer/ComposerOrchestratorComposer22TestCase.php @@ -20,6 +20,7 @@ use RuntimeException; use function file_get_contents; use function preg_replace; +use function version_compare; /** * @covers \KevinGH\Box\Composer\AutoloadDumper @@ -30,6 +31,14 @@ */ class ComposerOrchestratorComposer22TestCase extends BaseComposerOrchestratorComposerTestCase { + protected function shouldSkip(string $composerVersion): array + { + return [ + version_compare($composerVersion, '2.3.0', '>='), + '~2.2.0', + ]; + } + /** * @dataProvider composerAutoloadProvider */ diff --git a/tests/Composer/ComposerOrchestratorComposer23TestCase.php b/tests/Composer/ComposerOrchestratorComposer23TestCase.php index bbcb30651..6ad8ee58d 100644 --- a/tests/Composer/ComposerOrchestratorComposer23TestCase.php +++ b/tests/Composer/ComposerOrchestratorComposer23TestCase.php @@ -30,6 +30,15 @@ */ class ComposerOrchestratorComposer23TestCase extends BaseComposerOrchestratorComposerTestCase { + protected function shouldSkip(string $composerVersion): array + { + return [ + version_compare($composerVersion, '2.3.0', '<') + || version_compare($composerVersion, '2.4.0', '>='), + '~2.3.0', + ]; + } + /** * @dataProvider composerAutoloadProvider */ diff --git a/tests/Composer/ComposerOrchestratorComposer24TestCase.php b/tests/Composer/ComposerOrchestratorComposer24TestCase.php index 98cbf8496..2b5686662 100644 --- a/tests/Composer/ComposerOrchestratorComposer24TestCase.php +++ b/tests/Composer/ComposerOrchestratorComposer24TestCase.php @@ -30,6 +30,14 @@ */ class ComposerOrchestratorComposer24TestCase extends BaseComposerOrchestratorComposerTestCase { + protected function shouldSkip(string $composerVersion): array + { + return [ + version_compare($composerVersion, '2.4.0', '<'), + '>=2.4.0', + ]; + } + /** * @dataProvider composerAutoloadProvider */