Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion src/Downloading/Exception/CouldNotFindReleaseAsset.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -14,8 +15,19 @@
class CouldNotFindReleaseAsset extends RuntimeException
{
/** @param non-empty-list<non-empty-string> $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(),
Expand Down
4 changes: 3 additions & 1 deletion src/Downloading/GithubPackageReleaseAssets.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public function findMatchingReleaseAssetUrl(
array $possibleReleaseAssetNames,
): string {
$releaseAsset = $this->selectMatchingReleaseAsset(
$targetPlatform,
$package,
$this->getReleaseAssetsForPackage($package, $authHelper, $httpDownloader),
$possibleReleaseAssetNames,
Expand All @@ -55,6 +56,7 @@ public function findMatchingReleaseAssetUrl(
*/
// phpcs:enable
private function selectMatchingReleaseAsset(
TargetPlatform $targetPlatform,
Package $package,
array $releaseAssets,
array $possibleReleaseAssetNames,
Expand All @@ -65,7 +67,7 @@ private function selectMatchingReleaseAsset(
}
}

throw Exception\CouldNotFindReleaseAsset::forPackage($package, $possibleReleaseAssetNames);
throw Exception\CouldNotFindReleaseAsset::forPackage($targetPlatform, $package, $possibleReleaseAssetNames);
}

/** @return list<array{name: non-empty-string, browser_download_url: non-empty-string, ...}> */
Expand Down
45 changes: 43 additions & 2 deletions test/unit/Downloading/Exception/CouldNotFindReleaseAssetTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -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(
Expand Down