From 2d67fea9775b07726d29619a598d1813cfd38745 Mon Sep 17 00:00:00 2001 From: James Titcumb Date: Thu, 21 Nov 2024 21:06:11 +0000 Subject: [PATCH] Improve messaging when dependencies are not resolved and there is no Composer messaging --- src/ComposerIntegration/PieInstalledJsonMetadataKeys.php | 1 + src/DependencyResolver/UnableToResolveRequirement.php | 5 +++-- .../DependencyResolver/UnableToResolveRequirementTest.php | 4 ++-- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/ComposerIntegration/PieInstalledJsonMetadataKeys.php b/src/ComposerIntegration/PieInstalledJsonMetadataKeys.php index ceda8e5..0d7e606 100644 --- a/src/ComposerIntegration/PieInstalledJsonMetadataKeys.php +++ b/src/ComposerIntegration/PieInstalledJsonMetadataKeys.php @@ -4,6 +4,7 @@ namespace Php\Pie\ComposerIntegration; +/** @internal This is not public API for PIE, so should not be depended upon unless you accept the risk of BC breaks */ enum PieInstalledJsonMetadataKeys: string { case TargetPlatformPhpPath = 'pie-target-platform-php-path'; diff --git a/src/DependencyResolver/UnableToResolveRequirement.php b/src/DependencyResolver/UnableToResolveRequirement.php index 493e865..cdd9e41 100644 --- a/src/DependencyResolver/UnableToResolveRequirement.php +++ b/src/DependencyResolver/UnableToResolveRequirement.php @@ -23,9 +23,10 @@ public static function fromRequirement( $errors = $io->errors; return new self(sprintf( - 'Unable to find an installable package %s%s%s', + 'Unable to find an installable package %s for %s, with minimum stability %s.%s', $requestedPackageAndVersion->package, - $requestedPackageAndVersion->version !== null ? sprintf(' for version %s.', $requestedPackageAndVersion->version) : '.', + $requestedPackageAndVersion->version !== null ? sprintf('version %s', $requestedPackageAndVersion->version) : 'the latest compatible version', + DetermineMinimumStability::fromRequestedVersion($requestedPackageAndVersion->version), count($errors) ? "\n\n" . implode("\n\n", array_map(static fn ($e) => strip_tags($e), $errors)) : '', )); } diff --git a/test/unit/DependencyResolver/UnableToResolveRequirementTest.php b/test/unit/DependencyResolver/UnableToResolveRequirementTest.php index a211e42..5851ecf 100644 --- a/test/unit/DependencyResolver/UnableToResolveRequirementTest.php +++ b/test/unit/DependencyResolver/UnableToResolveRequirementTest.php @@ -50,7 +50,7 @@ public function testFromRequirementWithVersion(): void $exception = UnableToResolveRequirement::fromRequirement(new RequestedPackageAndVersion('foo/bar', '^1.2'), $io); - self::assertSame("Unable to find an installable package foo/bar for version ^1.2.\n\nmessage1\n\nmessage3\n\nmessage4", $exception->getMessage()); + self::assertSame("Unable to find an installable package foo/bar for version ^1.2, with minimum stability stable.\n\nmessage1\n\nmessage3\n\nmessage4", $exception->getMessage()); } public function testFromRequirementWithoutVersion(): void @@ -66,6 +66,6 @@ public function testFromRequirementWithoutVersion(): void $exception = UnableToResolveRequirement::fromRequirement(new RequestedPackageAndVersion('foo/bar', null), $io); - self::assertSame("Unable to find an installable package foo/bar.\n\nmessage1\n\nmessage3\n\nmessage4", $exception->getMessage()); + self::assertSame("Unable to find an installable package foo/bar for the latest compatible version, with minimum stability stable.\n\nmessage1\n\nmessage3\n\nmessage4", $exception->getMessage()); } }