Skip to content

Commit

Permalink
test: Fix the Composer orchestrator integration tests (#1143)
Browse files Browse the repository at this point in the history
In #1082 the test cases where incorrectly refactored making them share
the same condition.
  • Loading branch information
theofidry authored Nov 4, 2023
1 parent e0e31f2 commit 0c76068
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 11 deletions.
29 changes: 18 additions & 11 deletions tests/Composer/BaseComposerOrchestratorComposerTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,39 +21,46 @@
use function file_exists;
use function iterator_to_array;
use function sprintf;
use function version_compare;

abstract class BaseComposerOrchestratorComposerTestCase extends FileSystemTestCase
{
protected const FIXTURES = __DIR__.'/../../fixtures/composer-dump';
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<array{string, string}> $recordedClasses
* @param array<array{string, string}> $recordedFunctions
Expand Down
9 changes: 9 additions & 0 deletions tests/Composer/ComposerOrchestratorComposer22TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
use RuntimeException;
use function file_get_contents;
use function preg_replace;
use function version_compare;

/**
* @covers \KevinGH\Box\Composer\AutoloadDumper
Expand All @@ -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
*/
Expand Down
9 changes: 9 additions & 0 deletions tests/Composer/ComposerOrchestratorComposer23TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down
8 changes: 8 additions & 0 deletions tests/Composer/ComposerOrchestratorComposer24TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down

0 comments on commit 0c76068

Please sign in to comment.