diff --git a/src/Downloading/Exception/CouldNotFindReleaseAsset.php b/src/Downloading/Exception/CouldNotFindReleaseAsset.php index 528529d5..9eb4e536 100644 --- a/src/Downloading/Exception/CouldNotFindReleaseAsset.php +++ b/src/Downloading/Exception/CouldNotFindReleaseAsset.php @@ -5,6 +5,7 @@ namespace Php\Pie\Downloading\Exception; use Php\Pie\DependencyResolver\Package; +use Php\Pie\Downloading\DownloadUrlMethod; use Php\Pie\Platform\TargetPlatform; use RuntimeException; @@ -14,8 +15,19 @@ class CouldNotFindReleaseAsset extends RuntimeException { /** @param non-empty-list $expectedAssetNames */ - public static function forPackage(Package $package, array $expectedAssetNames): self + public static function forPackage(TargetPlatform $targetPlatform, Package $package, array $expectedAssetNames): self { + $downloadUrlMethod = DownloadUrlMethod::fromPackage($package, $targetPlatform); + + if ($downloadUrlMethod === DownloadUrlMethod::WindowsBinaryDownload) { + return new self(sprintf( + 'Windows archive with prebuilt extension for %s was not attached on release %s - looked for one of "%s"', + $package->name(), + $package->version(), + implode(', ', $expectedAssetNames), + )); + } + return new self(sprintf( 'Could not find release asset for %s named one of "%s"', $package->prettyNameAndVersion(), diff --git a/src/Downloading/GithubPackageReleaseAssets.php b/src/Downloading/GithubPackageReleaseAssets.php index 8eb891c4..89b26c9a 100644 --- a/src/Downloading/GithubPackageReleaseAssets.php +++ b/src/Downloading/GithubPackageReleaseAssets.php @@ -37,6 +37,7 @@ public function findMatchingReleaseAssetUrl( array $possibleReleaseAssetNames, ): string { $releaseAsset = $this->selectMatchingReleaseAsset( + $targetPlatform, $package, $this->getReleaseAssetsForPackage($package, $authHelper, $httpDownloader), $possibleReleaseAssetNames, @@ -55,6 +56,7 @@ public function findMatchingReleaseAssetUrl( */ // phpcs:enable private function selectMatchingReleaseAsset( + TargetPlatform $targetPlatform, Package $package, array $releaseAssets, array $possibleReleaseAssetNames, @@ -65,7 +67,7 @@ private function selectMatchingReleaseAsset( } } - throw Exception\CouldNotFindReleaseAsset::forPackage($package, $possibleReleaseAssetNames); + throw Exception\CouldNotFindReleaseAsset::forPackage($targetPlatform, $package, $possibleReleaseAssetNames); } /** @return list */ diff --git a/test/unit/Downloading/Exception/CouldNotFindReleaseAssetTest.php b/test/unit/Downloading/Exception/CouldNotFindReleaseAssetTest.php index 86718a89..83bc674d 100644 --- a/test/unit/Downloading/Exception/CouldNotFindReleaseAssetTest.php +++ b/test/unit/Downloading/Exception/CouldNotFindReleaseAssetTest.php @@ -15,13 +15,14 @@ use Php\Pie\Platform\TargetPhp\PhpBinaryPath; use Php\Pie\Platform\TargetPlatform; use Php\Pie\Platform\ThreadSafetyMode; +use Php\Pie\Platform\WindowsCompiler; use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\TestCase; #[CoversClass(CouldNotFindReleaseAsset::class)] final class CouldNotFindReleaseAssetTest extends TestCase { - public function testForPackage(): void + public function testForPackageWithRegularPackage(): void { $package = new Package( $this->createMock(CompletePackage::class), @@ -32,11 +33,51 @@ public function testForPackage(): void null, ); - $exception = CouldNotFindReleaseAsset::forPackage($package, ['something.zip', 'something2.zip']); + $exception = CouldNotFindReleaseAsset::forPackage( + new TargetPlatform( + OperatingSystem::NonWindows, + OperatingSystemFamily::Linux, + PhpBinaryPath::fromCurrentProcess(), + Architecture::x86_64, + ThreadSafetyMode::NonThreadSafe, + 1, + null, + ), + $package, + ['something.zip', 'something2.zip'], + ); self::assertSame('Could not find release asset for foo/bar:1.2.3 named one of "something.zip, something2.zip"', $exception->getMessage()); } + public function testForPackageWithWindowsPackage(): void + { + $package = new Package( + $this->createMock(CompletePackage::class), + ExtensionType::PhpModule, + ExtensionName::normaliseFromString('foo'), + 'foo/bar', + '1.2.3', + null, + ); + + $exception = CouldNotFindReleaseAsset::forPackage( + new TargetPlatform( + OperatingSystem::Windows, + OperatingSystemFamily::Windows, + PhpBinaryPath::fromCurrentProcess(), + Architecture::x86_64, + ThreadSafetyMode::NonThreadSafe, + 1, + WindowsCompiler::VS17, + ), + $package, + ['something.zip', 'something2.zip'], + ); + + self::assertSame('Windows archive with prebuilt extension for foo/bar was not attached on release 1.2.3 - looked for one of "something.zip, something2.zip"', $exception->getMessage()); + } + public function testForPackageWithMissingTag(): void { $package = new Package(