From 284eedd0aafdb7213d2b8e67455f8fe4e1d2ae64 Mon Sep 17 00:00:00 2001 From: Sebastian Bergmann Date: Wed, 31 May 2023 17:21:53 +0200 Subject: [PATCH] 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. --- src/Runner/Extension/PharLoader.php | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/src/Runner/Extension/PharLoader.php b/src/Runner/Extension/PharLoader.php index e76e12ceb4e..c65b1948284 100644 --- a/src/Runner/Extension/PharLoader.php +++ b/src/Runner/Extension/PharLoader.php @@ -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; @@ -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)) { @@ -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); + } }