Skip to content

Commit

Permalink
Use Version::id() instead of Version::series() to check extension com…
Browse files Browse the repository at this point in the history
…patibility

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.
  • Loading branch information
sebastianbergmann committed May 31, 2023
1 parent 8eae9e1 commit 284eedd
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion src/Runner/Extension/PharLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@
*/
namespace PHPUnit\Runner\Extension;

use function count;
use function explode;
use function implode;
use function is_file;
use function strpos;
use PharIo\Manifest\ApplicationName;
use PharIo\Manifest\Exception as ManifestException;
use PharIo\Manifest\ManifestLoader;
Expand Down Expand Up @@ -39,7 +43,7 @@ public function loadPharExtensionsInDirectory(string $directory): array

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

if (!$manifest->isExtensionFor($applicationName)) {
Expand Down Expand Up @@ -74,4 +78,21 @@ public function loadPharExtensionsInDirectory(string $directory): array
'notLoadedExtensions' => $notLoadedExtensions,
];
}

private function phpunitVersion(): string
{
$version = Version::id();

if (strpos($version, '-') === false) {
return $version;
}

$parts = explode('.', explode('-', $version)[0]);

if (count($parts) === 2) {
$parts[] = 0;
}

return implode('.', $parts);
}
}

0 comments on commit 284eedd

Please sign in to comment.