From 8a278adea493edea667770c3929a1aae2b3c1061 Mon Sep 17 00:00:00 2001 From: Bellangelo Date: Tue, 31 Dec 2024 06:33:28 +0200 Subject: [PATCH 01/17] Add --force option --- src/Command/CommandHelper.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/Command/CommandHelper.php b/src/Command/CommandHelper.php index 8e25165b..ca776832 100644 --- a/src/Command/CommandHelper.php +++ b/src/Command/CommandHelper.php @@ -39,6 +39,7 @@ final class CommandHelper private const OPTION_WITH_PHPIZE_PATH = 'with-phpize-path'; private const OPTION_MAKE_PARALLEL_JOBS = 'make-parallel-jobs'; private const OPTION_SKIP_ENABLE_EXTENSION = 'skip-enable-extension'; + private const OPTION_FORCE = 'force'; /** @psalm-suppress UnusedConstructor */ private function __construct() @@ -86,6 +87,12 @@ public static function configureDownloadBuildInstallOptions(Command $command): v InputOption::VALUE_NONE, 'Specify this to skip attempting to enable the extension in php.ini', ); + $command->addOption( + self::OPTION_FORCE, + null, + InputOption::VALUE_NONE, + 'To attempt to install a version that doesn\'t match the version constraints from the meta-data, for instance to install an older version than recommended, or when the signature is not available.', + ); self::configurePhpConfigOptions($command); From fea6ddc05453753d6f708813c1dc1c3602416092 Mon Sep 17 00:00:00 2001 From: Bellangelo Date: Tue, 31 Dec 2024 06:37:00 +0200 Subject: [PATCH 02/17] Add method to determine if --force option is passed --- src/Command/CommandHelper.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/Command/CommandHelper.php b/src/Command/CommandHelper.php index ca776832..813ff9a4 100644 --- a/src/Command/CommandHelper.php +++ b/src/Command/CommandHelper.php @@ -173,6 +173,11 @@ public static function determineAttemptToSetupIniFile(InputInterface $input): bo return ! $input->hasOption(self::OPTION_SKIP_ENABLE_EXTENSION) || ! $input->getOption(self::OPTION_SKIP_ENABLE_EXTENSION); } + public static function determineForceInstallingPackageVersion(InputInterface $input): bool + { + return ! $input->hasOption(self::OPTION_FORCE) || ! $input->getOption(self::OPTION_FORCE); + } + public static function determinePhpizePathFromInputs(InputInterface $input): PhpizePath|null { if ($input->hasOption(self::OPTION_WITH_PHPIZE_PATH)) { From 44ae540911a2c4c3df47d2f646fc0509bb19dbff Mon Sep 17 00:00:00 2001 From: Bellangelo Date: Tue, 31 Dec 2024 06:45:28 +0200 Subject: [PATCH 03/17] Pass the option to the handlers --- src/Command/InstallCommand.php | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/src/Command/InstallCommand.php b/src/Command/InstallCommand.php index aca34af2..b7e588e8 100644 --- a/src/Command/InstallCommand.php +++ b/src/Command/InstallCommand.php @@ -42,13 +42,13 @@ public function configure(): void public function execute(InputInterface $input, OutputInterface $output): int { - if (! TargetPlatform::isRunningAsRoot()) { + if (!TargetPlatform::isRunningAsRoot()) { $output->writeln('This command may need elevated privileges, and may prompt you for your password.'); } $targetPlatform = CommandHelper::determineTargetPlatformFromInputs($input, $output); - $requestedNameAndVersion = CommandHelper::requestedNameAndVersionPair($input); + $forceInstallPackageVersion = CommandHelper::determineForceInstallingPackageVersion($input); $composer = PieComposerFactory::createPieComposer( $this->container, @@ -63,7 +63,12 @@ public function execute(InputInterface $input, OutputInterface $output): int ), ); - $package = ($this->dependencyResolver)($composer, $targetPlatform, $requestedNameAndVersion); + $package = ($this->dependencyResolver)( + $composer, + $targetPlatform, + $requestedNameAndVersion, + $forceInstallPackageVersion + ); $output->writeln(sprintf('Found package: %s which provides %s', $package->prettyNameAndVersion(), $package->extensionName->nameWithExtPrefix())); // Now we know what package we have, we can validate the configure options for the command and re-create the @@ -85,7 +90,13 @@ public function execute(InputInterface $input, OutputInterface $output): int ); try { - ($this->composerIntegrationHandler)($package, $composer, $targetPlatform, $requestedNameAndVersion); + ($this->composerIntegrationHandler)( + $package, + $composer, + $targetPlatform, + $requestedNameAndVersion, + $forceInstallPackageVersion + ); } catch (ComposerRunFailed $composerRunFailed) { $output->writeln('' . $composerRunFailed->getMessage() . ''); From 209b9fee9835195fcfd66962f9d0015dbf03c7a6 Mon Sep 17 00:00:00 2001 From: Bellangelo Date: Tue, 31 Dec 2024 06:49:54 +0200 Subject: [PATCH 04/17] Ignore platform requirement when resolving dependencies --- src/DependencyResolver/DependencyResolver.php | 7 ++++++- .../ResolveDependencyWithComposer.php | 10 ++++++++-- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/DependencyResolver/DependencyResolver.php b/src/DependencyResolver/DependencyResolver.php index 98309fe0..860cd0e8 100644 --- a/src/DependencyResolver/DependencyResolver.php +++ b/src/DependencyResolver/DependencyResolver.php @@ -11,5 +11,10 @@ interface DependencyResolver { /** @throws UnableToResolveRequirement */ - public function __invoke(Composer $composer, TargetPlatform $targetPlatform, RequestedPackageAndVersion $requestedPackageAndVersion): Package; + public function __invoke( + Composer $composer, + TargetPlatform $targetPlatform, + RequestedPackageAndVersion $requestedPackageAndVersion, + bool $forceInstallPackageVersion + ): Package; } diff --git a/src/DependencyResolver/ResolveDependencyWithComposer.php b/src/DependencyResolver/ResolveDependencyWithComposer.php index 8bbdc020..d2bdbd28 100644 --- a/src/DependencyResolver/ResolveDependencyWithComposer.php +++ b/src/DependencyResolver/ResolveDependencyWithComposer.php @@ -5,6 +5,7 @@ namespace Php\Pie\DependencyResolver; use Composer\Composer; +use Composer\Filter\PlatformRequirementFilter\PlatformRequirementFilterFactory; use Composer\Package\CompletePackageInterface; use Php\Pie\ComposerIntegration\QuieterConsoleIO; use Php\Pie\ComposerIntegration\VersionSelectorFactory; @@ -23,13 +24,18 @@ public function __construct( ) { } - public function __invoke(Composer $composer, TargetPlatform $targetPlatform, RequestedPackageAndVersion $requestedPackageAndVersion): Package - { + public function __invoke( + Composer $composer, + TargetPlatform $targetPlatform, + RequestedPackageAndVersion $requestedPackageAndVersion, + bool $forceInstallPackageVersion, + ): Package { $versionSelector = VersionSelectorFactory::make($composer, $requestedPackageAndVersion, $targetPlatform); $package = $versionSelector->findBestCandidate( $requestedPackageAndVersion->package, $requestedPackageAndVersion->version, + platformRequirementFilter: PlatformRequirementFilterFactory::fromBoolOrList($forceInstallPackageVersion), io: $this->arrayCollectionIo, ); From df57cd5b7f6925b886a039e022ab764b41817856 Mon Sep 17 00:00:00 2001 From: Bellangelo Date: Tue, 31 Dec 2024 06:51:06 +0200 Subject: [PATCH 05/17] Ignore platform requirement when installing dependencies --- .../ComposerIntegrationHandler.php | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/ComposerIntegration/ComposerIntegrationHandler.php b/src/ComposerIntegration/ComposerIntegrationHandler.php index d5e33ca4..ef5b8675 100644 --- a/src/ComposerIntegration/ComposerIntegrationHandler.php +++ b/src/ComposerIntegration/ComposerIntegrationHandler.php @@ -5,6 +5,7 @@ namespace Php\Pie\ComposerIntegration; use Composer\Composer; +use Composer\Filter\PlatformRequirementFilter\PlatformRequirementFilterFactory; use Composer\Installer; use Composer\Json\JsonManipulator; use Php\Pie\DependencyResolver\Package; @@ -27,8 +28,13 @@ public function __construct( ) { } - public function __invoke(Package $package, Composer $composer, TargetPlatform $targetPlatform, RequestedPackageAndVersion $requestedPackageAndVersion): void - { + public function __invoke( + Package $package, + Composer $composer, + TargetPlatform $targetPlatform, + RequestedPackageAndVersion $requestedPackageAndVersion, + bool $forceInstallPackageVersion + ): void { $versionSelector = VersionSelectorFactory::make($composer, $requestedPackageAndVersion, $targetPlatform); $recommendedRequireVersion = $requestedPackageAndVersion->version; @@ -64,6 +70,7 @@ public function __invoke(Package $package, Composer $composer, TargetPlatform $t ->setInstall(true) ->setIgnoredTypes([]) ->setDryRun(false) + ->setPlatformRequirementFilter(PlatformRequirementFilterFactory::fromBoolOrList($forceInstallPackageVersion)) ->setDownloadOnly(false); if (file_exists(PieComposerFactory::getLockFile($pieComposerJson))) { From 69ed308d4d80d88a75aaa95f5c0d8c6e1f324300 Mon Sep 17 00:00:00 2001 From: Bellangelo Date: Tue, 31 Dec 2024 06:53:21 +0200 Subject: [PATCH 06/17] Fix code style --- src/Command/InstallCommand.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Command/InstallCommand.php b/src/Command/InstallCommand.php index b7e588e8..f10baa49 100644 --- a/src/Command/InstallCommand.php +++ b/src/Command/InstallCommand.php @@ -67,7 +67,7 @@ public function execute(InputInterface $input, OutputInterface $output): int $composer, $targetPlatform, $requestedNameAndVersion, - $forceInstallPackageVersion + $forceInstallPackageVersion, ); $output->writeln(sprintf('Found package: %s which provides %s', $package->prettyNameAndVersion(), $package->extensionName->nameWithExtPrefix())); From 77073c5bb3a5c18cfb4bb5370f76e2b7040a6493 Mon Sep 17 00:00:00 2001 From: Bellangelo Date: Tue, 31 Dec 2024 07:00:37 +0200 Subject: [PATCH 07/17] Fix logical error --- src/Command/CommandHelper.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Command/CommandHelper.php b/src/Command/CommandHelper.php index 813ff9a4..d94fb810 100644 --- a/src/Command/CommandHelper.php +++ b/src/Command/CommandHelper.php @@ -175,7 +175,7 @@ public static function determineAttemptToSetupIniFile(InputInterface $input): bo public static function determineForceInstallingPackageVersion(InputInterface $input): bool { - return ! $input->hasOption(self::OPTION_FORCE) || ! $input->getOption(self::OPTION_FORCE); + return $input->getOption(self::OPTION_FORCE); } public static function determinePhpizePathFromInputs(InputInterface $input): PhpizePath|null From fa5844419fa182317b944cd7949036a651bead17 Mon Sep 17 00:00:00 2001 From: Bellangelo Date: Tue, 31 Dec 2024 07:02:29 +0200 Subject: [PATCH 08/17] Fix code styling --- src/Command/InstallCommand.php | 8 ++++---- src/ComposerIntegration/ComposerIntegrationHandler.php | 2 +- src/DependencyResolver/DependencyResolver.php | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/Command/InstallCommand.php b/src/Command/InstallCommand.php index f10baa49..0640b5e4 100644 --- a/src/Command/InstallCommand.php +++ b/src/Command/InstallCommand.php @@ -42,12 +42,12 @@ public function configure(): void public function execute(InputInterface $input, OutputInterface $output): int { - if (!TargetPlatform::isRunningAsRoot()) { + if (! TargetPlatform::isRunningAsRoot()) { $output->writeln('This command may need elevated privileges, and may prompt you for your password.'); } - $targetPlatform = CommandHelper::determineTargetPlatformFromInputs($input, $output); - $requestedNameAndVersion = CommandHelper::requestedNameAndVersionPair($input); + $targetPlatform = CommandHelper::determineTargetPlatformFromInputs($input, $output); + $requestedNameAndVersion = CommandHelper::requestedNameAndVersionPair($input); $forceInstallPackageVersion = CommandHelper::determineForceInstallingPackageVersion($input); $composer = PieComposerFactory::createPieComposer( @@ -95,7 +95,7 @@ public function execute(InputInterface $input, OutputInterface $output): int $composer, $targetPlatform, $requestedNameAndVersion, - $forceInstallPackageVersion + $forceInstallPackageVersion, ); } catch (ComposerRunFailed $composerRunFailed) { $output->writeln('' . $composerRunFailed->getMessage() . ''); diff --git a/src/ComposerIntegration/ComposerIntegrationHandler.php b/src/ComposerIntegration/ComposerIntegrationHandler.php index ef5b8675..05d9c8b1 100644 --- a/src/ComposerIntegration/ComposerIntegrationHandler.php +++ b/src/ComposerIntegration/ComposerIntegrationHandler.php @@ -33,7 +33,7 @@ public function __invoke( Composer $composer, TargetPlatform $targetPlatform, RequestedPackageAndVersion $requestedPackageAndVersion, - bool $forceInstallPackageVersion + bool $forceInstallPackageVersion, ): void { $versionSelector = VersionSelectorFactory::make($composer, $requestedPackageAndVersion, $targetPlatform); diff --git a/src/DependencyResolver/DependencyResolver.php b/src/DependencyResolver/DependencyResolver.php index 860cd0e8..8179089f 100644 --- a/src/DependencyResolver/DependencyResolver.php +++ b/src/DependencyResolver/DependencyResolver.php @@ -15,6 +15,6 @@ public function __invoke( Composer $composer, TargetPlatform $targetPlatform, RequestedPackageAndVersion $requestedPackageAndVersion, - bool $forceInstallPackageVersion + bool $forceInstallPackageVersion, ): Package; } From bca995155486afd6efb5089f9d0c7dabc2c612f0 Mon Sep 17 00:00:00 2001 From: Bellangelo Date: Tue, 31 Dec 2024 07:11:37 +0200 Subject: [PATCH 09/17] Handle force option in build command --- src/Command/BuildCommand.php | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/src/Command/BuildCommand.php b/src/Command/BuildCommand.php index 0860038e..05cb1f15 100644 --- a/src/Command/BuildCommand.php +++ b/src/Command/BuildCommand.php @@ -42,8 +42,8 @@ public function configure(): void public function execute(InputInterface $input, OutputInterface $output): int { $targetPlatform = CommandHelper::determineTargetPlatformFromInputs($input, $output); - $requestedNameAndVersion = CommandHelper::requestedNameAndVersionPair($input); + $forceInstallPackageVersion = CommandHelper::determineForceInstallingPackageVersion($input); $composer = PieComposerFactory::createPieComposer( $this->container, @@ -58,7 +58,12 @@ public function execute(InputInterface $input, OutputInterface $output): int ), ); - $package = ($this->dependencyResolver)($composer, $targetPlatform, $requestedNameAndVersion); + $package = ($this->dependencyResolver)( + $composer, + $targetPlatform, + $requestedNameAndVersion, + $forceInstallPackageVersion + ); $output->writeln(sprintf('Found package: %s which provides %s', $package->prettyNameAndVersion(), $package->extensionName->nameWithExtPrefix())); // Now we know what package we have, we can validate the configure options for the command and re-create the @@ -80,7 +85,13 @@ public function execute(InputInterface $input, OutputInterface $output): int ); try { - ($this->composerIntegrationHandler)($package, $composer, $targetPlatform, $requestedNameAndVersion); + ($this->composerIntegrationHandler)( + $package, + $composer, + $targetPlatform, + $requestedNameAndVersion, + $forceInstallPackageVersion + ); } catch (ComposerRunFailed $composerRunFailed) { $output->writeln('' . $composerRunFailed->getMessage() . ''); From ef36c82ad992ea3909b87a5f54f59b9018987591 Mon Sep 17 00:00:00 2001 From: Bellangelo Date: Tue, 31 Dec 2024 07:13:09 +0200 Subject: [PATCH 10/17] Handle force option in download command --- src/Command/BuildCommand.php | 8 ++++---- src/Command/DownloadCommand.php | 21 ++++++++++++++++----- 2 files changed, 20 insertions(+), 9 deletions(-) diff --git a/src/Command/BuildCommand.php b/src/Command/BuildCommand.php index 05cb1f15..09983648 100644 --- a/src/Command/BuildCommand.php +++ b/src/Command/BuildCommand.php @@ -41,8 +41,8 @@ public function configure(): void public function execute(InputInterface $input, OutputInterface $output): int { - $targetPlatform = CommandHelper::determineTargetPlatformFromInputs($input, $output); - $requestedNameAndVersion = CommandHelper::requestedNameAndVersionPair($input); + $targetPlatform = CommandHelper::determineTargetPlatformFromInputs($input, $output); + $requestedNameAndVersion = CommandHelper::requestedNameAndVersionPair($input); $forceInstallPackageVersion = CommandHelper::determineForceInstallingPackageVersion($input); $composer = PieComposerFactory::createPieComposer( @@ -62,7 +62,7 @@ public function execute(InputInterface $input, OutputInterface $output): int $composer, $targetPlatform, $requestedNameAndVersion, - $forceInstallPackageVersion + $forceInstallPackageVersion, ); $output->writeln(sprintf('Found package: %s which provides %s', $package->prettyNameAndVersion(), $package->extensionName->nameWithExtPrefix())); @@ -90,7 +90,7 @@ public function execute(InputInterface $input, OutputInterface $output): int $composer, $targetPlatform, $requestedNameAndVersion, - $forceInstallPackageVersion + $forceInstallPackageVersion, ); } catch (ComposerRunFailed $composerRunFailed) { $output->writeln('' . $composerRunFailed->getMessage() . ''); diff --git a/src/Command/DownloadCommand.php b/src/Command/DownloadCommand.php index f6616290..4a7439b1 100644 --- a/src/Command/DownloadCommand.php +++ b/src/Command/DownloadCommand.php @@ -43,9 +43,9 @@ public function execute(InputInterface $input, OutputInterface $output): int { CommandHelper::validateInput($input, $this); - $targetPlatform = CommandHelper::determineTargetPlatformFromInputs($input, $output); - - $requestedNameAndVersion = CommandHelper::requestedNameAndVersionPair($input); + $targetPlatform = CommandHelper::determineTargetPlatformFromInputs($input, $output); + $requestedNameAndVersion = CommandHelper::requestedNameAndVersionPair($input); + $forceInstallPackageVersion = CommandHelper::determineForceInstallingPackageVersion($input); $composer = PieComposerFactory::createPieComposer( $this->container, @@ -60,11 +60,22 @@ public function execute(InputInterface $input, OutputInterface $output): int ), ); - $package = ($this->dependencyResolver)($composer, $targetPlatform, $requestedNameAndVersion); + $package = ($this->dependencyResolver)( + $composer, + $targetPlatform, + $requestedNameAndVersion, + $forceInstallPackageVersion, + ); $output->writeln(sprintf('Found package: %s which provides %s', $package->prettyNameAndVersion(), $package->extensionName->nameWithExtPrefix())); try { - ($this->composerIntegrationHandler)($package, $composer, $targetPlatform, $requestedNameAndVersion); + ($this->composerIntegrationHandler)( + $package, + $composer, + $targetPlatform, + $requestedNameAndVersion, + $forceInstallPackageVersion, + ); } catch (ComposerRunFailed $composerRunFailed) { $output->writeln('' . $composerRunFailed->getMessage() . ''); From baa686c9b7a2a7f5380fe319b831553bf2831eb4 Mon Sep 17 00:00:00 2001 From: Bellangelo Date: Tue, 31 Dec 2024 07:14:33 +0200 Subject: [PATCH 11/17] Handle force option in info command --- src/Command/InfoCommand.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/Command/InfoCommand.php b/src/Command/InfoCommand.php index 9f1f806f..b11a1b24 100644 --- a/src/Command/InfoCommand.php +++ b/src/Command/InfoCommand.php @@ -58,7 +58,12 @@ public function execute(InputInterface $input, OutputInterface $output): int ), ); - $package = ($this->dependencyResolver)($composer, $targetPlatform, $requestedNameAndVersion); + $package = ($this->dependencyResolver)( + $composer, + $targetPlatform, + $requestedNameAndVersion, + CommandHelper::determineForceInstallingPackageVersion($input) + ); $output->writeln(sprintf('Found package: %s which provides %s', $package->prettyNameAndVersion(), $package->extensionName->nameWithExtPrefix())); $output->writeln(sprintf('Extension name: %s', $package->extensionName->name())); From 3887f850ec2c30630d2c59b783b1dae79b02508a Mon Sep 17 00:00:00 2001 From: Bellangelo Date: Tue, 31 Dec 2024 07:15:03 +0200 Subject: [PATCH 12/17] Fix test dependencies --- src/Command/InfoCommand.php | 2 +- .../ResolveDependencyWithComposerTest.php | 1 + .../ResolveDependencyWithComposerTest.php | 7 ++++++- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/Command/InfoCommand.php b/src/Command/InfoCommand.php index b11a1b24..0d03e934 100644 --- a/src/Command/InfoCommand.php +++ b/src/Command/InfoCommand.php @@ -62,7 +62,7 @@ public function execute(InputInterface $input, OutputInterface $output): int $composer, $targetPlatform, $requestedNameAndVersion, - CommandHelper::determineForceInstallingPackageVersion($input) + CommandHelper::determineForceInstallingPackageVersion($input), ); $output->writeln(sprintf('Found package: %s which provides %s', $package->prettyNameAndVersion(), $package->extensionName->nameWithExtPrefix())); diff --git a/test/integration/DependencyResolver/ResolveDependencyWithComposerTest.php b/test/integration/DependencyResolver/ResolveDependencyWithComposerTest.php index 1477b39c..43d5799e 100644 --- a/test/integration/DependencyResolver/ResolveDependencyWithComposerTest.php +++ b/test/integration/DependencyResolver/ResolveDependencyWithComposerTest.php @@ -95,6 +95,7 @@ public function testDependenciesAreResolvedToExpectedVersions( ), $targetPlatform, $requestedPackageAndVersion, + false, ); self::assertSame($expectedVersion, $package->version); diff --git a/test/unit/DependencyResolver/ResolveDependencyWithComposerTest.php b/test/unit/DependencyResolver/ResolveDependencyWithComposerTest.php index 1fff415a..360413f8 100644 --- a/test/unit/DependencyResolver/ResolveDependencyWithComposerTest.php +++ b/test/unit/DependencyResolver/ResolveDependencyWithComposerTest.php @@ -64,7 +64,7 @@ public function testPackageThatCanBeResolved(): void $package = (new ResolveDependencyWithComposer( $this->createMock(QuieterConsoleIO::class), - ))($this->composer, $targetPlatform, new RequestedPackageAndVersion('asgrim/example-pie-extension', '^1.0')); + ))($this->composer, $targetPlatform, new RequestedPackageAndVersion('asgrim/example-pie-extension', '^1.0'), false); self::assertSame('asgrim/example-pie-extension', $package->name); self::assertStringStartsWith('1.', $package->version); @@ -118,6 +118,7 @@ public function testPackageThatCannotBeResolvedThrowsException(array $platformOv $package, $version, ), + false, ); } @@ -164,6 +165,7 @@ public function testZtsOnlyPackageCannotBeInstalledOnNtsSystem(): void 'test-vendor/test-package', '1.0.0', ), + false, ); } @@ -210,6 +212,7 @@ public function testNtsOnlyPackageCannotBeInstalledOnZtsSystem(): void 'test-vendor/test-package', '1.0.0', ), + false, ); } @@ -256,6 +259,7 @@ public function testExtensionCanOnlyBeInstalledIfOsFamilyIsCompatible(): void 'test-vendor/test-package', '1.0.0', ), + false, ); } @@ -302,6 +306,7 @@ public function testExtensionCanOnlyBeInstalledIfOsFamilyIsNotInCompatible(): vo 'test-vendor/test-package', '1.0.0', ), + false, ); } } From 1641d2435720d0cd35b725a1d382fbe9d0c78b53 Mon Sep 17 00:00:00 2001 From: Bellangelo Date: Tue, 31 Dec 2024 07:39:41 +0200 Subject: [PATCH 13/17] Make more strict checks --- src/Command/CommandHelper.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Command/CommandHelper.php b/src/Command/CommandHelper.php index d94fb810..6fc1368f 100644 --- a/src/Command/CommandHelper.php +++ b/src/Command/CommandHelper.php @@ -175,7 +175,7 @@ public static function determineAttemptToSetupIniFile(InputInterface $input): bo public static function determineForceInstallingPackageVersion(InputInterface $input): bool { - return $input->getOption(self::OPTION_FORCE); + return $input->hasOption(self::OPTION_FORCE) && $input->getOption(self::OPTION_FORCE); } public static function determinePhpizePathFromInputs(InputInterface $input): PhpizePath|null From e94a4849821e4c7c9ce5d4ca65f0a5b3fb4a81fc Mon Sep 17 00:00:00 2001 From: Bellangelo Date: Tue, 31 Dec 2024 07:39:57 +0200 Subject: [PATCH 14/17] Test the force option in the download command --- .../Command/DownloadCommandTest.php | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/test/integration/Command/DownloadCommandTest.php b/test/integration/Command/DownloadCommandTest.php index 2baf4103..d5adca8e 100644 --- a/test/integration/Command/DownloadCommandTest.php +++ b/test/integration/Command/DownloadCommandTest.php @@ -151,4 +151,24 @@ public function testDownloadCommandFailsWhenUsingIncompatiblePhpVersion(): void // 1.0.0 is only compatible with PHP 8.3.0 $this->commandTester->execute(['requested-package-and-version' => self::TEST_PACKAGE . ':1.0.0']); } + + #[RequiresPhp('<8.3')] + public function testDownloadCommandPassesWhenUsingIncompatiblePhpVersionWithForceOption(): void + { + $incompatiblePackage = self::TEST_PACKAGE . ':' . '1.x-dev'; + + // 1.0.0 is only compatible with PHP 8.3.0 + $this->commandTester->execute( + [ + '--force' => true, + 'requested-package-and-version' => $incompatiblePackage, + ], + ); + + $this->commandTester->assertCommandIsSuccessful(); + + $outputString = $this->commandTester->getDisplay(); + self::assertStringContainsString('Found package: ' . $incompatiblePackage . ' which provides', $outputString); + self::assertStringContainsString('Extracted ' . $incompatiblePackage . ' source to', $outputString); + } } From c0cc89253b651457c8fb6f77955faf8b9f1399b7 Mon Sep 17 00:00:00 2001 From: Bellangelo Date: Tue, 31 Dec 2024 07:45:15 +0200 Subject: [PATCH 15/17] Test the force option in the dependency resolver --- .../ResolveDependencyWithComposerTest.php | 41 +++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/test/unit/DependencyResolver/ResolveDependencyWithComposerTest.php b/test/unit/DependencyResolver/ResolveDependencyWithComposerTest.php index 360413f8..6cdd9a4b 100644 --- a/test/unit/DependencyResolver/ResolveDependencyWithComposerTest.php +++ b/test/unit/DependencyResolver/ResolveDependencyWithComposerTest.php @@ -122,6 +122,47 @@ public function testPackageThatCannotBeResolvedThrowsException(array $platformOv ); } + /** + * @param array $platformOverrides + * @param non-empty-string $package + * @param non-empty-string $version + */ + #[DataProvider('unresolvableDependencies')] + public function testUnresolvedPackageCanBeInstalledWithForceOption(array $platformOverrides, string $package, string $version): void + { + $phpBinaryPath = $this->createMock(PhpBinaryPath::class); + $phpBinaryPath->expects(self::once()) + ->method('version') + ->willReturn($platformOverrides['php']); + + $targetPlatform = new TargetPlatform( + OperatingSystem::NonWindows, + OperatingSystemFamily::Linux, + $phpBinaryPath, + Architecture::x86_64, + ThreadSafetyMode::ThreadSafe, + 1, + null, + ); + + $this->expectException(UnableToResolveRequirement::class); + + $package = (new ResolveDependencyWithComposer( + $this->createMock(QuieterConsoleIO::class), + ))( + $this->composer, + $targetPlatform, + new RequestedPackageAndVersion( + $package, + $version, + ), + true, + ); + + self::assertSame('asgrim/example-pie-extension', $package->name); + self::assertStringStartsWith('1.', $package->version); + } + public function testZtsOnlyPackageCannotBeInstalledOnNtsSystem(): void { $pkg = new CompletePackage('test-vendor/test-package', '1.0.0.0', '1.0.0'); From 54d0dfbeb3aab75f0905eda358dbb217117af8b1 Mon Sep 17 00:00:00 2001 From: Bellangelo Date: Tue, 31 Dec 2024 08:21:10 +0200 Subject: [PATCH 16/17] Fix test --- test/integration/Command/DownloadCommandTest.php | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/test/integration/Command/DownloadCommandTest.php b/test/integration/Command/DownloadCommandTest.php index d5adca8e..fec8f2e2 100644 --- a/test/integration/Command/DownloadCommandTest.php +++ b/test/integration/Command/DownloadCommandTest.php @@ -152,22 +152,23 @@ public function testDownloadCommandFailsWhenUsingIncompatiblePhpVersion(): void $this->commandTester->execute(['requested-package-and-version' => self::TEST_PACKAGE . ':1.0.0']); } - #[RequiresPhp('<8.3')] + #[RequiresPhp('<8.2')] public function testDownloadCommandPassesWhenUsingIncompatiblePhpVersionWithForceOption(): void { - $incompatiblePackage = self::TEST_PACKAGE . ':' . '1.x-dev'; + // 1.0.1 is only compatible with PHP 8.3.0 + $incompatiblePackage = self::TEST_PACKAGE . ':1.0.1'; - // 1.0.0 is only compatible with PHP 8.3.0 $this->commandTester->execute( [ - '--force' => true, 'requested-package-and-version' => $incompatiblePackage, + '--force' => true, ], ); $this->commandTester->assertCommandIsSuccessful(); $outputString = $this->commandTester->getDisplay(); + self::assertStringContainsString('Found package: ' . $incompatiblePackage . ' which provides', $outputString); self::assertStringContainsString('Extracted ' . $incompatiblePackage . ' source to', $outputString); } From 0c0a4769670677ee37dbf6ade1975ea3736055ff Mon Sep 17 00:00:00 2001 From: Bellangelo Date: Tue, 31 Dec 2024 08:27:58 +0200 Subject: [PATCH 17/17] Package does not load on Windows --- test/integration/Command/DownloadCommandTest.php | 1 + 1 file changed, 1 insertion(+) diff --git a/test/integration/Command/DownloadCommandTest.php b/test/integration/Command/DownloadCommandTest.php index fec8f2e2..c15bc88e 100644 --- a/test/integration/Command/DownloadCommandTest.php +++ b/test/integration/Command/DownloadCommandTest.php @@ -152,6 +152,7 @@ public function testDownloadCommandFailsWhenUsingIncompatiblePhpVersion(): void $this->commandTester->execute(['requested-package-and-version' => self::TEST_PACKAGE . ':1.0.0']); } + #[RequiresOperatingSystemFamily('Linux')] #[RequiresPhp('<8.2')] public function testDownloadCommandPassesWhenUsingIncompatiblePhpVersionWithForceOption(): void {