Skip to content

Commit 284eedd

Browse files
Use Version::id() instead of Version::series() to check extension compatibility
Version::id() returns X.Y.Z for release versions, which can be passed directly to PharIo\Version\Version. For unreleased versions, Version::id() returns X.Y.Z-n-hash (release branch) or X.Y-hash (main branch), which cannot be passed directly to PharIo\Version\Version. X.Y.Z-n-hash is passed to PharIo\Version\Version as X.Y.Z and X.Y-hash is passed to PharIo\Version\Version as X.Y.0.
1 parent 8eae9e1 commit 284eedd

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

src/Runner/Extension/PharLoader.php

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,11 @@
99
*/
1010
namespace PHPUnit\Runner\Extension;
1111

12+
use function count;
13+
use function explode;
14+
use function implode;
1215
use function is_file;
16+
use function strpos;
1317
use PharIo\Manifest\ApplicationName;
1418
use PharIo\Manifest\Exception as ManifestException;
1519
use PharIo\Manifest\ManifestLoader;
@@ -39,7 +43,7 @@ public function loadPharExtensionsInDirectory(string $directory): array
3943

4044
try {
4145
$applicationName = new ApplicationName('phpunit/phpunit');
42-
$version = new PharIoVersion(Version::series());
46+
$version = new PharIoVersion($this->phpunitVersion());
4347
$manifest = ManifestLoader::fromFile('phar://' . $file . '/manifest.xml');
4448

4549
if (!$manifest->isExtensionFor($applicationName)) {
@@ -74,4 +78,21 @@ public function loadPharExtensionsInDirectory(string $directory): array
7478
'notLoadedExtensions' => $notLoadedExtensions,
7579
];
7680
}
81+
82+
private function phpunitVersion(): string
83+
{
84+
$version = Version::id();
85+
86+
if (strpos($version, '-') === false) {
87+
return $version;
88+
}
89+
90+
$parts = explode('.', explode('-', $version)[0]);
91+
92+
if (count($parts) === 2) {
93+
$parts[] = 0;
94+
}
95+
96+
return implode('.', $parts);
97+
}
7798
}

0 commit comments

Comments
 (0)