From 3013674c925ca2fee817e8e9f8b11ff80453cad0 Mon Sep 17 00:00:00 2001 From: Martin Herndl Date: Thu, 11 Nov 2021 12:24:12 +0100 Subject: [PATCH] Refactor ignore platform reqs checks (#10079) Introduces a `PlatformRequirementFilter` with methods that help to decide if a requirement is ignored or not as discussed in #10045 but without changing behaviour. --- src/Composer/Autoload/AutoloadGenerator.php | 39 ++++++++------ src/Composer/Command/CreateProjectCommand.php | 21 ++++---- src/Composer/Command/DumpAutoloadCommand.php | 3 +- src/Composer/Command/InitCommand.php | 21 ++++---- src/Composer/Command/InstallCommand.php | 3 +- src/Composer/Command/ReinstallCommand.php | 3 +- src/Composer/Command/RemoveCommand.php | 3 +- src/Composer/Command/RequireCommand.php | 3 +- src/Composer/Command/UpdateCommand.php | 3 +- .../DependencyResolver/RuleSetGenerator.php | 37 +++++++------ src/Composer/DependencyResolver/Solver.php | 17 +++--- .../IgnoreAllPlatformRequirementFilter.php | 17 ++++++ .../IgnoreListPlatformRequirementFilter.php | 34 ++++++++++++ ...IgnoreNothingPlatformRequirementFilter.php | 15 ++++++ .../PlatformRequirementFilterFactory.php | 45 ++++++++++++++++ .../PlatformRequirementFilterInterface.php | 12 +++++ src/Composer/Installer.php | 41 +++++++++----- .../Package/Version/VersionSelector.php | 30 +++++++---- .../Test/Autoload/AutoloadGeneratorTest.php | 3 +- ...IgnoreAllPlatformRequirementFilterTest.php | 33 ++++++++++++ ...gnoreListPlatformRequirementFilterTest.php | 35 ++++++++++++ ...reNothingPlatformRequirementFilterTest.php | 32 +++++++++++ .../PlatformRequirementFilterFactoryTest.php | 53 +++++++++++++++++++ tests/Composer/Test/InstallerTest.php | 5 +- .../Package/Version/VersionSelectorTest.php | 9 ++-- 25 files changed, 419 insertions(+), 98 deletions(-) create mode 100644 src/Composer/Filter/PlatformRequirementFilter/IgnoreAllPlatformRequirementFilter.php create mode 100644 src/Composer/Filter/PlatformRequirementFilter/IgnoreListPlatformRequirementFilter.php create mode 100644 src/Composer/Filter/PlatformRequirementFilter/IgnoreNothingPlatformRequirementFilter.php create mode 100644 src/Composer/Filter/PlatformRequirementFilter/PlatformRequirementFilterFactory.php create mode 100644 src/Composer/Filter/PlatformRequirementFilter/PlatformRequirementFilterInterface.php create mode 100644 tests/Composer/Test/Filter/PlatformRequirementFilter/IgnoreAllPlatformRequirementFilterTest.php create mode 100644 tests/Composer/Test/Filter/PlatformRequirementFilter/IgnoreListPlatformRequirementFilterTest.php create mode 100644 tests/Composer/Test/Filter/PlatformRequirementFilter/IgnoreNothingPlatformRequirementFilterTest.php create mode 100644 tests/Composer/Test/Filter/PlatformRequirementFilter/PlatformRequirementFilterFactoryTest.php diff --git a/src/Composer/Autoload/AutoloadGenerator.php b/src/Composer/Autoload/AutoloadGenerator.php index d8bd5101d..d8f6dea0d 100644 --- a/src/Composer/Autoload/AutoloadGenerator.php +++ b/src/Composer/Autoload/AutoloadGenerator.php @@ -14,13 +14,15 @@ namespace Composer\Autoload; use Composer\Config; use Composer\EventDispatcher\EventDispatcher; +use Composer\Filter\PlatformRequirementFilter\IgnoreAllPlatformRequirementFilter; +use Composer\Filter\PlatformRequirementFilter\PlatformRequirementFilterFactory; +use Composer\Filter\PlatformRequirementFilter\PlatformRequirementFilterInterface; use Composer\Installer\InstallationManager; use Composer\IO\IOInterface; use Composer\Package\AliasPackage; use Composer\Package\PackageInterface; use Composer\Package\RootPackageInterface; use Composer\Repository\InstalledRepositoryInterface; -use Composer\Repository\PlatformRepository; use Composer\Semver\Constraint\Bound; use Composer\Util\Filesystem; use Composer\Util\Platform; @@ -70,14 +72,16 @@ class AutoloadGenerator private $runScripts = false; /** - * @var bool|string[] + * @var PlatformRequirementFilterInterface */ - private $ignorePlatformReqs = false; + private $platformRequirementFilter; public function __construct(EventDispatcher $eventDispatcher, IOInterface $io = null) { $this->eventDispatcher = $eventDispatcher; $this->io = $io; + + $this->platformRequirementFilter = PlatformRequirementFilterFactory::ignoreNothing(); } /** @@ -133,16 +137,22 @@ class AutoloadGenerator * * @param bool|string[] $ignorePlatformReqs * @return void + * + * @deprecated use setPlatformRequirementFilter instead */ public function setIgnorePlatformRequirements($ignorePlatformReqs) { - if (is_array($ignorePlatformReqs)) { - $this->ignorePlatformReqs = array_filter($ignorePlatformReqs, function ($req) { - return PlatformRepository::isPlatformPackage($req); - }); - } else { - $this->ignorePlatformReqs = (bool) $ignorePlatformReqs; - } + trigger_error('AutoloadGenerator::setIgnorePlatformRequirements is deprecated since Composer 2.2, use setPlatformRequirementFilter instead.', E_USER_DEPRECATED); + + $this->setPlatformRequirementFilter(PlatformRequirementFilterFactory::fromBoolOrList($ignorePlatformReqs)); + } + + /** + * @return void + */ + public function setPlatformRequirementFilter(PlatformRequirementFilterInterface $platformRequirementFilter) + { + $this->platformRequirementFilter = $platformRequirementFilter; } /** @@ -391,10 +401,10 @@ EOF; unlink($includeFilesFilePath); } $filesystem->filePutContentsIfModified($targetDir.'/autoload_static.php', $this->getStaticFile($suffix, $targetDir, $vendorPath, $basePath, $staticPhpVersion)); - $checkPlatform = $config->get('platform-check') && $this->ignorePlatformReqs !== true; + $checkPlatform = $config->get('platform-check') && !($this->platformRequirementFilter instanceof IgnoreAllPlatformRequirementFilter); $platformCheckContent = null; if ($checkPlatform) { - $platformCheckContent = $this->getPlatformCheck($packageMap, $this->ignorePlatformReqs ?: array(), $config->get('platform-check'), $devPackageNames); + $platformCheckContent = $this->getPlatformCheck($packageMap, $config->get('platform-check'), $devPackageNames); if (null === $platformCheckContent) { $checkPlatform = false; } @@ -740,12 +750,11 @@ EOF; /** * @param array $packageMap - * @param string[] $ignorePlatformReqs * @param bool $checkPlatform * @param string[] $devPackageNames * @return ?string */ - protected function getPlatformCheck(array $packageMap, array $ignorePlatformReqs, $checkPlatform, array $devPackageNames) + protected function getPlatformCheck(array $packageMap, $checkPlatform, array $devPackageNames) { $lowestPhpVersion = Bound::zero(); $requiredExtensions = array(); @@ -768,7 +777,7 @@ EOF; } foreach ($package->getRequires() as $link) { - if (in_array($link->getTarget(), $ignorePlatformReqs, true)) { + if ($this->platformRequirementFilter->isIgnored($link->getTarget())) { continue; } diff --git a/src/Composer/Command/CreateProjectCommand.php b/src/Composer/Command/CreateProjectCommand.php index da01080f6..0cf206a53 100644 --- a/src/Composer/Command/CreateProjectCommand.php +++ b/src/Composer/Command/CreateProjectCommand.php @@ -14,6 +14,9 @@ namespace Composer\Command; use Composer\Config; use Composer\Factory; +use Composer\Filter\PlatformRequirementFilter\IgnoreAllPlatformRequirementFilter; +use Composer\Filter\PlatformRequirementFilter\PlatformRequirementFilterFactory; +use Composer\Filter\PlatformRequirementFilter\PlatformRequirementFilterInterface; use Composer\Installer; use Composer\Installer\ProjectInstaller; use Composer\Installer\SuggestedPackagesReporter; @@ -159,7 +162,7 @@ EOT $input->getOption('no-scripts'), $input->getOption('no-progress'), $input->getOption('no-install'), - $ignorePlatformReqs, + PlatformRequirementFilterFactory::fromBoolOrList($ignorePlatformReqs), !$input->getOption('no-secure-http'), $input->getOption('add-repository') ); @@ -178,14 +181,13 @@ EOT * @param bool $noScripts * @param bool $noProgress * @param bool $noInstall - * @param bool $ignorePlatformReqs * @param bool $secureHttp * @param bool $addRepository * * @return int * @throws \Exception */ - public function installProject(IOInterface $io, Config $config, InputInterface $input, $packageName = null, $directory = null, $packageVersion = null, $stability = 'stable', $preferSource = false, $preferDist = false, $installDevPackages = false, $repositories = null, $disablePlugins = false, $noScripts = false, $noProgress = false, $noInstall = false, $ignorePlatformReqs = false, $secureHttp = true, $addRepository = false) + public function installProject(IOInterface $io, Config $config, InputInterface $input, $packageName = null, $directory = null, $packageVersion = null, $stability = 'stable', $preferSource = false, $preferDist = false, $installDevPackages = false, $repositories = null, $disablePlugins = false, $noScripts = false, $noProgress = false, $noInstall = false, PlatformRequirementFilterInterface $platformRequirementFilter = null, $secureHttp = true, $addRepository = false) { $oldCwd = getcwd(); @@ -193,13 +195,15 @@ EOT $repositories = (array) $repositories; } + $platformRequirementFilter = $platformRequirementFilter ?: PlatformRequirementFilterFactory::ignoreNothing(); + // we need to manually load the configuration to pass the auth credentials to the io interface! $io->loadConfiguration($config); $this->suggestedPackagesReporter = new SuggestedPackagesReporter($io); if ($packageName !== null) { - $installedFromVcs = $this->installRootPackage($io, $config, $packageName, $directory, $packageVersion, $stability, $preferSource, $preferDist, $installDevPackages, $repositories, $disablePlugins, $noScripts, $noProgress, $ignorePlatformReqs, $secureHttp); + $installedFromVcs = $this->installRootPackage($io, $config, $packageName, $platformRequirementFilter, $directory, $packageVersion, $stability, $preferSource, $preferDist, $installDevPackages, $repositories, $disablePlugins, $noScripts, $noProgress, $secureHttp); } else { $installedFromVcs = false; } @@ -250,7 +254,7 @@ EOT $installer->setPreferSource($preferSource) ->setPreferDist($preferDist) ->setDevMode($installDevPackages) - ->setIgnorePlatformRequirements($ignorePlatformReqs) + ->setPlatformRequirementFilter($platformRequirementFilter) ->setSuggestedPackagesReporter($this->suggestedPackagesReporter) ->setOptimizeAutoloader($config->get('optimize-autoloader')) ->setClassMapAuthoritative($config->get('classmap-authoritative')) @@ -342,13 +346,12 @@ EOT * @param bool $disablePlugins * @param bool $noScripts * @param bool $noProgress - * @param bool $ignorePlatformReqs * @param bool $secureHttp * * @return bool * @throws \Exception */ - protected function installRootPackage(IOInterface $io, Config $config, $packageName, $directory = null, $packageVersion = null, $stability = 'stable', $preferSource = false, $preferDist = false, $installDevPackages = false, array $repositories = null, $disablePlugins = false, $noScripts = false, $noProgress = false, $ignorePlatformReqs = false, $secureHttp = true) + protected function installRootPackage(IOInterface $io, Config $config, $packageName, PlatformRequirementFilterInterface $platformRequirementFilter, $directory = null, $packageVersion = null, $stability = 'stable', $preferSource = false, $preferDist = false, $installDevPackages = false, array $repositories = null, $disablePlugins = false, $noScripts = false, $noProgress = false, $secureHttp = true) { if (!$secureHttp) { $config->merge(array('config' => array('secure-http' => false))); @@ -425,11 +428,11 @@ EOT // find the latest version if there are multiple $versionSelector = new VersionSelector($repositorySet, $platformRepo); - $package = $versionSelector->findBestCandidate($name, $packageVersion, $stability, $ignorePlatformReqs); + $package = $versionSelector->findBestCandidate($name, $packageVersion, $stability, $platformRequirementFilter); if (!$package) { $errorMessage = "Could not find package $name with " . ($packageVersion ? "version $packageVersion" : "stability $stability"); - if (true !== $ignorePlatformReqs && $versionSelector->findBestCandidate($name, $packageVersion, $stability, true)) { + if (!($platformRequirementFilter instanceof IgnoreAllPlatformRequirementFilter) && $versionSelector->findBestCandidate($name, $packageVersion, $stability, PlatformRequirementFilterFactory::ignoreAll())) { throw new \InvalidArgumentException($errorMessage .' in a version installable using your PHP version, PHP extensions and Composer version.'); } diff --git a/src/Composer/Command/DumpAutoloadCommand.php b/src/Composer/Command/DumpAutoloadCommand.php index 20da6fb15..7640af731 100644 --- a/src/Composer/Command/DumpAutoloadCommand.php +++ b/src/Composer/Command/DumpAutoloadCommand.php @@ -12,6 +12,7 @@ namespace Composer\Command; +use Composer\Filter\PlatformRequirementFilter\PlatformRequirementFilterFactory; use Composer\Plugin\CommandEvent; use Composer\Plugin\PluginEvents; use Symfony\Component\Console\Input\InputInterface; @@ -97,7 +98,7 @@ EOT $generator->setClassMapAuthoritative($authoritative); $generator->setRunScripts(true); $generator->setApcu($apcu, $apcuPrefix); - $generator->setIgnorePlatformRequirements($ignorePlatformReqs); + $generator->setPlatformRequirementFilter(PlatformRequirementFilterFactory::fromBoolOrList($ignorePlatformReqs)); $numberOfClasses = $generator->dump($config, $localRepo, $package, $installationManager, 'composer', $optimize); if ($authoritative) { diff --git a/src/Composer/Command/InitCommand.php b/src/Composer/Command/InitCommand.php index d2e09e0f9..5ed9b684a 100644 --- a/src/Composer/Command/InitCommand.php +++ b/src/Composer/Command/InitCommand.php @@ -13,6 +13,8 @@ namespace Composer\Command; use Composer\Factory; +use Composer\Filter\PlatformRequirementFilter\IgnoreAllPlatformRequirementFilter; +use Composer\Filter\PlatformRequirementFilter\PlatformRequirementFilterFactory; use Composer\Json\JsonFile; use Composer\Json\JsonValidationException; use Composer\Package\BasePackage; @@ -890,22 +892,23 @@ EOT if ($input->hasOption('ignore-platform-reqs') && $input->hasOption('ignore-platform-req')) { $ignorePlatformReqs = $input->getOption('ignore-platform-reqs') ?: ($input->getOption('ignore-platform-req') ?: false); } + $platformRequirementFilter = PlatformRequirementFilterFactory::fromBoolOrList($ignorePlatformReqs); // find the latest version allowed in this repo set $versionSelector = new VersionSelector($this->getRepositorySet($input, $minimumStability), $platformRepo); $effectiveMinimumStability = $minimumStability ?: $this->getMinimumStability($input); - $package = $versionSelector->findBestCandidate($name, $requiredVersion, $preferredStability, $ignorePlatformReqs); + $package = $versionSelector->findBestCandidate($name, $requiredVersion, $preferredStability, $platformRequirementFilter); if (!$package) { // platform packages can not be found in the pool in versions other than the local platform's has // so if platform reqs are ignored we just take the user's word for it - if ((true === $ignorePlatformReqs || (is_array($ignorePlatformReqs) && in_array($name, $ignorePlatformReqs))) && PlatformRepository::isPlatformPackage($name)) { + if ($platformRequirementFilter->isIgnored($name)) { return array($name, $requiredVersion ?: '*'); } // Check whether the package requirements were the problem - if (true !== $ignorePlatformReqs && ($candidate = $versionSelector->findBestCandidate($name, $requiredVersion, $preferredStability, true))) { + if (!($platformRequirementFilter instanceof IgnoreAllPlatformRequirementFilter) && ($candidate = $versionSelector->findBestCandidate($name, $requiredVersion, $preferredStability, PlatformRequirementFilterFactory::ignoreAll()))) { throw new \InvalidArgumentException(sprintf( 'Package %s%s has requirements incompatible with your PHP version, PHP extensions and Composer version' . $this->getPlatformExceptionDetails($candidate, $platformRepo), $name, @@ -913,9 +916,9 @@ EOT )); } // Check whether the minimum stability was the problem but the package exists - if ($package = $versionSelector->findBestCandidate($name, $requiredVersion, $preferredStability, $ignorePlatformReqs, RepositorySet::ALLOW_UNACCEPTABLE_STABILITIES)) { + if ($package = $versionSelector->findBestCandidate($name, $requiredVersion, $preferredStability, $platformRequirementFilter, RepositorySet::ALLOW_UNACCEPTABLE_STABILITIES)) { // we must first verify if a valid package would be found in a lower priority repository - if ($allReposPackage = $versionSelector->findBestCandidate($name, $requiredVersion, $preferredStability, $ignorePlatformReqs, RepositorySet::ALLOW_SHADOWED_REPOSITORIES)) { + if ($allReposPackage = $versionSelector->findBestCandidate($name, $requiredVersion, $preferredStability, $platformRequirementFilter, RepositorySet::ALLOW_SHADOWED_REPOSITORIES)) { throw new \InvalidArgumentException( 'Package '.$name.' exists in '.$allReposPackage->getRepository()->getRepoName().' and '.$package->getRepository()->getRepoName().' which has a higher repository priority. The packages with higher priority do not match your minimum-stability and are therefore not installable. See https://getcomposer.org/repoprio for details and assistance.' ); @@ -928,9 +931,9 @@ EOT )); } // Check whether the required version was the problem - if ($requiredVersion && $package = $versionSelector->findBestCandidate($name, null, $preferredStability, $ignorePlatformReqs)) { + if ($requiredVersion && $package = $versionSelector->findBestCandidate($name, null, $preferredStability, $platformRequirementFilter)) { // we must first verify if a valid package would be found in a lower priority repository - if ($allReposPackage = $versionSelector->findBestCandidate($name, $requiredVersion, $preferredStability, false, RepositorySet::ALLOW_SHADOWED_REPOSITORIES)) { + if ($allReposPackage = $versionSelector->findBestCandidate($name, $requiredVersion, $preferredStability, PlatformRequirementFilterFactory::ignoreNothing(), RepositorySet::ALLOW_SHADOWED_REPOSITORIES)) { throw new \InvalidArgumentException( 'Package '.$name.' exists in '.$allReposPackage->getRepository()->getRepoName().' and '.$package->getRepository()->getRepoName().' which has a higher repository priority. The packages with higher priority do not match your constraint and are therefore not installable. See https://getcomposer.org/repoprio for details and assistance.' ); @@ -943,9 +946,9 @@ EOT )); } // Check whether the PHP version was the problem for all versions - if (true !== $ignorePlatformReqs && ($candidate = $versionSelector->findBestCandidate($name, null, $preferredStability, true, RepositorySet::ALLOW_UNACCEPTABLE_STABILITIES))) { + if (!($platformRequirementFilter instanceof IgnoreAllPlatformRequirementFilter) && ($candidate = $versionSelector->findBestCandidate($name, null, $preferredStability, PlatformRequirementFilterFactory::ignoreAll(), RepositorySet::ALLOW_UNACCEPTABLE_STABILITIES))) { $additional = ''; - if (false === $versionSelector->findBestCandidate($name, null, $preferredStability, true)) { + if (false === $versionSelector->findBestCandidate($name, null, $preferredStability, PlatformRequirementFilterFactory::ignoreAll())) { $additional = PHP_EOL.PHP_EOL.'Additionally, the package was only found with a stability of "'.$candidate->getStability().'" while your minimum stability is "'.$effectiveMinimumStability.'".'; } diff --git a/src/Composer/Command/InstallCommand.php b/src/Composer/Command/InstallCommand.php index 583fc33a1..fb3fc4aa3 100644 --- a/src/Composer/Command/InstallCommand.php +++ b/src/Composer/Command/InstallCommand.php @@ -12,6 +12,7 @@ namespace Composer\Command; +use Composer\Filter\PlatformRequirementFilter\PlatformRequirementFilterFactory; use Composer\Installer; use Composer\Plugin\CommandEvent; use Composer\Plugin\PluginEvents; @@ -130,7 +131,7 @@ EOT ->setOptimizeAutoloader($optimize) ->setClassMapAuthoritative($authoritative) ->setApcuAutoloader($apcu, $apcuPrefix) - ->setIgnorePlatformRequirements($ignorePlatformReqs) + ->setPlatformRequirementFilter(PlatformRequirementFilterFactory::fromBoolOrList($ignorePlatformReqs)) ; if ($input->getOption('no-plugins')) { diff --git a/src/Composer/Command/ReinstallCommand.php b/src/Composer/Command/ReinstallCommand.php index 94da95f1d..6d0122168 100644 --- a/src/Composer/Command/ReinstallCommand.php +++ b/src/Composer/Command/ReinstallCommand.php @@ -15,6 +15,7 @@ namespace Composer\Command; use Composer\DependencyResolver\Operation\InstallOperation; use Composer\DependencyResolver\Operation\UninstallOperation; use Composer\DependencyResolver\Transaction; +use Composer\Filter\PlatformRequirementFilter\PlatformRequirementFilterFactory; use Composer\Package\AliasPackage; use Composer\Package\BasePackage; use Composer\Plugin\CommandEvent; @@ -158,7 +159,7 @@ EOT $generator = $composer->getAutoloadGenerator(); $generator->setClassMapAuthoritative($authoritative); $generator->setApcu($apcu, $apcuPrefix); - $generator->setIgnorePlatformRequirements($ignorePlatformReqs); + $generator->setPlatformRequirementFilter(PlatformRequirementFilterFactory::fromBoolOrList($ignorePlatformReqs)); $generator->dump($config, $localRepo, $package, $installationManager, 'composer', $optimize); } diff --git a/src/Composer/Command/RemoveCommand.php b/src/Composer/Command/RemoveCommand.php index 926500c09..535739fd0 100644 --- a/src/Composer/Command/RemoveCommand.php +++ b/src/Composer/Command/RemoveCommand.php @@ -14,6 +14,7 @@ namespace Composer\Command; use Composer\Config\JsonConfigSource; use Composer\DependencyResolver\Request; +use Composer\Filter\PlatformRequirementFilter\PlatformRequirementFilterFactory; use Composer\Installer; use Composer\Plugin\CommandEvent; use Composer\Plugin\PluginEvents; @@ -265,7 +266,7 @@ EOT ->setUpdate(true) ->setInstall(!$input->getOption('no-install')) ->setUpdateAllowTransitiveDependencies($updateAllowTransitiveDependencies) - ->setIgnorePlatformRequirements($ignorePlatformReqs) + ->setPlatformRequirementFilter(PlatformRequirementFilterFactory::fromBoolOrList($ignorePlatformReqs)) ->setDryRun($dryRun) ; diff --git a/src/Composer/Command/RequireCommand.php b/src/Composer/Command/RequireCommand.php index c629af5db..aa5a4e105 100644 --- a/src/Composer/Command/RequireCommand.php +++ b/src/Composer/Command/RequireCommand.php @@ -13,6 +13,7 @@ namespace Composer\Command; use Composer\DependencyResolver\Request; +use Composer\Filter\PlatformRequirementFilter\PlatformRequirementFilterFactory; use Composer\Util\Filesystem; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputArgument; @@ -413,7 +414,7 @@ EOT ->setUpdate(true) ->setInstall(!$input->getOption('no-install')) ->setUpdateAllowTransitiveDependencies($updateAllowTransitiveDependencies) - ->setIgnorePlatformRequirements($ignorePlatformReqs) + ->setPlatformRequirementFilter(PlatformRequirementFilterFactory::fromBoolOrList($ignorePlatformReqs)) ->setPreferStable($input->getOption('prefer-stable')) ->setPreferLowest($input->getOption('prefer-lowest')) ; diff --git a/src/Composer/Command/UpdateCommand.php b/src/Composer/Command/UpdateCommand.php index 84c99ffd7..8cdeba4d8 100644 --- a/src/Composer/Command/UpdateCommand.php +++ b/src/Composer/Command/UpdateCommand.php @@ -14,6 +14,7 @@ namespace Composer\Command; use Composer\Composer; use Composer\DependencyResolver\Request; +use Composer\Filter\PlatformRequirementFilter\PlatformRequirementFilterFactory; use Composer\Installer; use Composer\IO\IOInterface; use Composer\Package\Loader\RootPackageLoader; @@ -236,7 +237,7 @@ EOT ->setUpdateMirrors($updateMirrors) ->setUpdateAllowList($packages) ->setUpdateAllowTransitiveDependencies($updateAllowTransitiveDependencies) - ->setIgnorePlatformRequirements($ignorePlatformReqs) + ->setPlatformRequirementFilter(PlatformRequirementFilterFactory::fromBoolOrList($ignorePlatformReqs)) ->setPreferStable($input->getOption('prefer-stable')) ->setPreferLowest($input->getOption('prefer-lowest')) ; diff --git a/src/Composer/DependencyResolver/RuleSetGenerator.php b/src/Composer/DependencyResolver/RuleSetGenerator.php index e20a6299e..94c834841 100644 --- a/src/Composer/DependencyResolver/RuleSetGenerator.php +++ b/src/Composer/DependencyResolver/RuleSetGenerator.php @@ -12,6 +12,8 @@ namespace Composer\DependencyResolver; +use Composer\Filter\PlatformRequirementFilter\PlatformRequirementFilterFactory; +use Composer\Filter\PlatformRequirementFilter\PlatformRequirementFilterInterface; use Composer\Package\BasePackage; use Composer\Package\AliasPackage; use Composer\Repository\PlatformRepository; @@ -160,10 +162,9 @@ class RuleSetGenerator } /** - * @param bool|string[] $ignorePlatformReqs * @return void */ - protected function addRulesForPackage(BasePackage $package, $ignorePlatformReqs) + protected function addRulesForPackage(BasePackage $package, PlatformRequirementFilterInterface $platformRequirementFilter) { /** @var \SplQueue */ $workQueue = new \SplQueue; @@ -196,7 +197,7 @@ class RuleSetGenerator } foreach ($package->getRequires() as $link) { - if ((true === $ignorePlatformReqs || (is_array($ignorePlatformReqs) && in_array($link->getTarget(), $ignorePlatformReqs, true))) && PlatformRepository::isPlatformPackage($link->getTarget())) { + if ($platformRequirementFilter->isIgnored($link->getTarget())) { continue; } @@ -212,10 +213,9 @@ class RuleSetGenerator } /** - * @param bool|string[] $ignorePlatformReqs * @return void */ - protected function addConflictRules($ignorePlatformReqs = false) + protected function addConflictRules(PlatformRequirementFilterInterface $platformRequirementFilter) { /** @var BasePackage $package */ foreach ($this->addedMap as $package) { @@ -225,7 +225,7 @@ class RuleSetGenerator continue; } - if ((true === $ignorePlatformReqs || (is_array($ignorePlatformReqs) && in_array($link->getTarget(), $ignorePlatformReqs, true))) && PlatformRepository::isPlatformPackage($link->getTarget())) { + if ($platformRequirementFilter->isIgnored($link->getTarget())) { continue; } @@ -251,10 +251,9 @@ class RuleSetGenerator } /** - * @param bool|string[] $ignorePlatformReqs * @return void */ - protected function addRulesForRequest(Request $request, $ignorePlatformReqs) + protected function addRulesForRequest(Request $request, PlatformRequirementFilterInterface $platformRequirementFilter) { foreach ($request->getFixedPackages() as $package) { if ($package->id == -1) { @@ -267,7 +266,7 @@ class RuleSetGenerator throw new \LogicException("Fixed package ".$package->getPrettyString()." was not added to solver pool."); } - $this->addRulesForPackage($package, $ignorePlatformReqs); + $this->addRulesForPackage($package, $platformRequirementFilter); $rule = $this->createInstallOneOfRule(array($package), Rule::RULE_FIXED, array( 'package' => $package, @@ -276,14 +275,14 @@ class RuleSetGenerator } foreach ($request->getRequires() as $packageName => $constraint) { - if ((true === $ignorePlatformReqs || (is_array($ignorePlatformReqs) && in_array($packageName, $ignorePlatformReqs, true))) && PlatformRepository::isPlatformPackage($packageName)) { + if ($platformRequirementFilter->isIgnored($packageName)) { continue; } $packages = $this->pool->whatProvides($packageName, $constraint); if ($packages) { foreach ($packages as $package) { - $this->addRulesForPackage($package, $ignorePlatformReqs); + $this->addRulesForPackage($package, $platformRequirementFilter); } $rule = $this->createInstallOneOfRule($packages, Rule::RULE_ROOT_REQUIRE, array( @@ -296,10 +295,9 @@ class RuleSetGenerator } /** - * @param bool|string[] $ignorePlatformReqs * @return void */ - protected function addRulesForRootAliases($ignorePlatformReqs) + protected function addRulesForRootAliases(PlatformRequirementFilterInterface $platformRequirementFilter) { foreach ($this->pool->getPackages() as $package) { // ensure that rules for root alias packages and aliases of packages which were loaded are also loaded @@ -309,22 +307,23 @@ class RuleSetGenerator $package instanceof AliasPackage && ($package->isRootPackageAlias() || isset($this->addedMap[$package->getAliasOf()->id])) ) { - $this->addRulesForPackage($package, $ignorePlatformReqs); + $this->addRulesForPackage($package, $platformRequirementFilter); } } } /** - * @param bool|string[] $ignorePlatformReqs * @return RuleSet */ - public function getRulesFor(Request $request, $ignorePlatformReqs = false) + public function getRulesFor(Request $request, PlatformRequirementFilterInterface $platformRequirementFilter = null) { - $this->addRulesForRequest($request, $ignorePlatformReqs); + $platformRequirementFilter = $platformRequirementFilter ?: PlatformRequirementFilterFactory::ignoreNothing(); - $this->addRulesForRootAliases($ignorePlatformReqs); + $this->addRulesForRequest($request, $platformRequirementFilter); - $this->addConflictRules($ignorePlatformReqs); + $this->addRulesForRootAliases($platformRequirementFilter); + + $this->addConflictRules($platformRequirementFilter); // Remove references to packages $this->addedMap = $this->addedPackagesByNames = array(); diff --git a/src/Composer/DependencyResolver/Solver.php b/src/Composer/DependencyResolver/Solver.php index c8979748b..c3bdbfff0 100644 --- a/src/Composer/DependencyResolver/Solver.php +++ b/src/Composer/DependencyResolver/Solver.php @@ -12,9 +12,10 @@ namespace Composer\DependencyResolver; +use Composer\Filter\PlatformRequirementFilter\PlatformRequirementFilterFactory; +use Composer\Filter\PlatformRequirementFilter\PlatformRequirementFilterInterface; use Composer\IO\IOInterface; use Composer\Package\BasePackage; -use Composer\Repository\PlatformRepository; /** * @author Nils Adermann @@ -166,13 +167,12 @@ class Solver } /** - * @param bool|string[] $ignorePlatformReqs * @return void */ - protected function checkForRootRequireProblems(Request $request, $ignorePlatformReqs) + protected function checkForRootRequireProblems(Request $request, PlatformRequirementFilterInterface $platformRequirementFilter) { foreach ($request->getRequires() as $packageName => $constraint) { - if ((true === $ignorePlatformReqs || (is_array($ignorePlatformReqs) && in_array($packageName, $ignorePlatformReqs, true))) && PlatformRepository::isPlatformPackage($packageName)) { + if ($platformRequirementFilter->isIgnored($packageName)) { continue; } @@ -185,18 +185,19 @@ class Solver } /** - * @param bool|string[] $ignorePlatformReqs * @return LockTransaction */ - public function solve(Request $request, $ignorePlatformReqs = false) + public function solve(Request $request, PlatformRequirementFilterInterface $platformRequirementFilter = null) { + $platformRequirementFilter = $platformRequirementFilter ?: PlatformRequirementFilterFactory::ignoreNothing(); + $this->setupFixedMap($request); $this->io->writeError('Generating rules', true, IOInterface::DEBUG); $ruleSetGenerator = new RuleSetGenerator($this->policy, $this->pool); - $this->rules = $ruleSetGenerator->getRulesFor($request, $ignorePlatformReqs); + $this->rules = $ruleSetGenerator->getRulesFor($request, $platformRequirementFilter); unset($ruleSetGenerator); - $this->checkForRootRequireProblems($request, $ignorePlatformReqs); + $this->checkForRootRequireProblems($request, $platformRequirementFilter); $this->decisions = new Decisions($this->pool); $this->watchGraph = new RuleWatchGraph; diff --git a/src/Composer/Filter/PlatformRequirementFilter/IgnoreAllPlatformRequirementFilter.php b/src/Composer/Filter/PlatformRequirementFilter/IgnoreAllPlatformRequirementFilter.php new file mode 100644 index 000000000..0d64d8236 --- /dev/null +++ b/src/Composer/Filter/PlatformRequirementFilter/IgnoreAllPlatformRequirementFilter.php @@ -0,0 +1,17 @@ +reqList = $reqList; + } + + /** + * @param string $req + * @return bool + */ + public function isIgnored($req) + { + if (!PlatformRepository::isPlatformPackage($req)) { + return false; + } + + return in_array($req, $this->reqList, true); + } +} diff --git a/src/Composer/Filter/PlatformRequirementFilter/IgnoreNothingPlatformRequirementFilter.php b/src/Composer/Filter/PlatformRequirementFilter/IgnoreNothingPlatformRequirementFilter.php new file mode 100644 index 000000000..94c1a9a97 --- /dev/null +++ b/src/Composer/Filter/PlatformRequirementFilter/IgnoreNothingPlatformRequirementFilter.php @@ -0,0 +1,15 @@ +eventDispatcher = $eventDispatcher; $this->autoloadGenerator = $autoloadGenerator; $this->suggestedPackagesReporter = new SuggestedPackagesReporter($this->io); + $this->platformRequirementFilter = PlatformRequirementFilterFactory::ignoreNothing(); $this->writeLock = $config->get('lock'); } @@ -329,7 +335,7 @@ class Installer $this->autoloadGenerator->setClassMapAuthoritative($this->classMapAuthoritative); $this->autoloadGenerator->setApcu($this->apcuAutoloader, $this->apcuAutoloaderPrefix); $this->autoloadGenerator->setRunScripts($this->runScripts); - $this->autoloadGenerator->setIgnorePlatformRequirements($this->ignorePlatformReqs); + $this->autoloadGenerator->setPlatformRequirementFilter($this->platformRequirementFilter); $this->autoloadGenerator->dump($this->config, $localRepo, $this->package, $this->installationManager, 'composer', $this->optimizeAutoloader); } @@ -431,7 +437,7 @@ class Installer // solve dependencies $solver = new Solver($policy, $pool, $this->io); try { - $lockTransaction = $solver->solve($request, $this->ignorePlatformReqs); + $lockTransaction = $solver->solve($request, $this->platformRequirementFilter); $ruleSetSize = $solver->getRuleSetSize(); $solver = null; } catch (SolverProblemsException $e) { @@ -609,7 +615,7 @@ class Installer $solver = new Solver($policy, $pool, $this->io); try { - $nonDevLockTransaction = $solver->solve($request, $this->ignorePlatformReqs); + $nonDevLockTransaction = $solver->solve($request, $this->platformRequirementFilter); $solver = null; } catch (SolverProblemsException $e) { $err = 'Unable to find a compatible set of packages based on your non-dev requirements alone.'; @@ -674,7 +680,7 @@ class Installer // solve dependencies $solver = new Solver($policy, $pool, $this->io); try { - $lockTransaction = $solver->solve($request, $this->ignorePlatformReqs); + $lockTransaction = $solver->solve($request, $this->platformRequirementFilter); $solver = null; // installing the locked packages on this platform resulted in lock modifying operations, there wasn't a conflict, but the lock file as-is seems to not work on this system @@ -799,7 +805,7 @@ class Installer $rootRequires = array(); foreach ($requires as $req => $constraint) { // skip platform requirements from the root package to avoid filtering out existing platform packages - if ((true === $this->ignorePlatformReqs || (is_array($this->ignorePlatformReqs) && in_array($req, $this->ignorePlatformReqs, true))) && PlatformRepository::isPlatformPackage($req)) { + if ($this->platformRequirementFilter->isIgnored($req)) { continue; } if ($constraint instanceof Link) { @@ -1242,16 +1248,23 @@ class Installer * @param bool|string[] $ignorePlatformReqs * * @return Installer + * + * @deprecated use setPlatformRequirementFilter instead */ public function setIgnorePlatformRequirements($ignorePlatformReqs) { - if (is_array($ignorePlatformReqs)) { - $this->ignorePlatformReqs = array_filter($ignorePlatformReqs, function ($req) { - return PlatformRepository::isPlatformPackage($req); - }); - } else { - $this->ignorePlatformReqs = (bool) $ignorePlatformReqs; - } + trigger_error('Installer::setIgnorePlatformRequirements is deprecated since Composer 2.2, use setPlatformRequirementFilter instead.', E_USER_DEPRECATED); + + return $this->setPlatformRequirementFilter(PlatformRequirementFilterFactory::fromBoolOrList($ignorePlatformReqs)); + } + + /** + * @param PlatformRequirementFilterInterface $platformRequirementFilter + * @return Installer + */ + public function setPlatformRequirementFilter(PlatformRequirementFilterInterface $platformRequirementFilter) + { + $this->platformRequirementFilter = $platformRequirementFilter; return $this; } diff --git a/src/Composer/Package/Version/VersionSelector.php b/src/Composer/Package/Version/VersionSelector.php index 79972999a..5dfd6fa50 100644 --- a/src/Composer/Package/Version/VersionSelector.php +++ b/src/Composer/Package/Version/VersionSelector.php @@ -12,6 +12,9 @@ namespace Composer\Package\Version; +use Composer\Filter\PlatformRequirementFilter\IgnoreAllPlatformRequirementFilter; +use Composer\Filter\PlatformRequirementFilter\PlatformRequirementFilterFactory; +use Composer\Filter\PlatformRequirementFilter\PlatformRequirementFilterInterface; use Composer\Package\BasePackage; use Composer\Package\AliasPackage; use Composer\Package\PackageInterface; @@ -57,32 +60,37 @@ class VersionSelector * Given a package name and optional version, returns the latest PackageInterface * that matches. * - * @param string $packageName - * @param string $targetPackageVersion - * @param string $preferredStability - * @param bool|string[] $ignorePlatformReqs - * @param int $repoSetFlags - * + * @param string $packageName + * @param string $targetPackageVersion + * @param string $preferredStability + * @param PlatformRequirementFilterInterface|bool|string[] $platformRequirementFilter + * @param int $repoSetFlags* * @return PackageInterface|false */ - public function findBestCandidate($packageName, $targetPackageVersion = null, $preferredStability = 'stable', $ignorePlatformReqs = false, $repoSetFlags = 0) + public function findBestCandidate($packageName, $targetPackageVersion = null, $preferredStability = 'stable', $platformRequirementFilter = null, $repoSetFlags = 0) { if (!isset(BasePackage::$stabilities[$preferredStability])) { // If you get this, maybe you are still relying on the Composer 1.x signature where the 3rd arg was the php version throw new \UnexpectedValueException('Expected a valid stability name as 3rd argument, got '.$preferredStability); } + if (null === $platformRequirementFilter) { + $platformRequirementFilter = PlatformRequirementFilterFactory::ignoreNothing(); + } elseif (!($platformRequirementFilter instanceof PlatformRequirementFilterInterface)) { + trigger_error('VersionSelector::findBestCandidate with ignored platform reqs as bool|array is deprecated since Composer 2.2, use an instance of PlatformRequirementFilterInterface instead.', E_USER_DEPRECATED); + $platformRequirementFilter = PlatformRequirementFilterFactory::fromBoolOrList($platformRequirementFilter); + } + $constraint = $targetPackageVersion ? $this->getParser()->parseConstraints($targetPackageVersion) : null; $candidates = $this->repositorySet->findPackages(strtolower($packageName), $constraint, $repoSetFlags); - if ($this->platformConstraints && true !== $ignorePlatformReqs) { + if ($this->platformConstraints && !($platformRequirementFilter instanceof IgnoreAllPlatformRequirementFilter)) { $platformConstraints = $this->platformConstraints; - $ignorePlatformReqs = $ignorePlatformReqs ?: array(); - $candidates = array_filter($candidates, function ($pkg) use ($platformConstraints, $ignorePlatformReqs) { + $candidates = array_filter($candidates, function ($pkg) use ($platformConstraints, $platformRequirementFilter) { $reqs = $pkg->getRequires(); foreach ($reqs as $name => $link) { - if (!in_array($name, $ignorePlatformReqs, true)) { + if (!$platformRequirementFilter->isIgnored($name)) { if (isset($platformConstraints[$name])) { foreach ($platformConstraints[$name] as $constraint) { if ($link->getConstraint()->matches($constraint)) { diff --git a/tests/Composer/Test/Autoload/AutoloadGeneratorTest.php b/tests/Composer/Test/Autoload/AutoloadGeneratorTest.php index 650c4c962..391bd5d08 100644 --- a/tests/Composer/Test/Autoload/AutoloadGeneratorTest.php +++ b/tests/Composer/Test/Autoload/AutoloadGeneratorTest.php @@ -13,6 +13,7 @@ namespace Composer\Test\Autoload; use Composer\Autoload\AutoloadGenerator; +use Composer\Filter\PlatformRequirementFilter\PlatformRequirementFilterFactory; use Composer\Package\Link; use Composer\Package\Version\VersionParser; use Composer\Semver\Constraint\Constraint; @@ -1731,7 +1732,7 @@ EOF; ->method('getCanonicalPackages') ->will($this->returnValue(array())); - $this->generator->setIgnorePlatformRequirements($ignorePlatformReqs); + $this->generator->setPlatformRequirementFilter(PlatformRequirementFilterFactory::fromBoolOrList($ignorePlatformReqs)); $this->generator->dump($this->config, $this->repository, $package, $this->im, 'composer', true, '_1'); if (null === $expectedFixture) { diff --git a/tests/Composer/Test/Filter/PlatformRequirementFilter/IgnoreAllPlatformRequirementFilterTest.php b/tests/Composer/Test/Filter/PlatformRequirementFilter/IgnoreAllPlatformRequirementFilterTest.php new file mode 100644 index 000000000..2208ca9b3 --- /dev/null +++ b/tests/Composer/Test/Filter/PlatformRequirementFilter/IgnoreAllPlatformRequirementFilterTest.php @@ -0,0 +1,33 @@ +assertSame($expectIgnored, $platformRequirementFilter->isIgnored($req)); + } + + /** + * @return array + */ + public function dataIsIgnored() + { + return array( + 'php is ignored' => array('php', true), + 'monolog/monolog is not ignored' => array('monolog/monolog', false), + ); + } +} diff --git a/tests/Composer/Test/Filter/PlatformRequirementFilter/IgnoreListPlatformRequirementFilterTest.php b/tests/Composer/Test/Filter/PlatformRequirementFilter/IgnoreListPlatformRequirementFilterTest.php new file mode 100644 index 000000000..4c2c5a8ab --- /dev/null +++ b/tests/Composer/Test/Filter/PlatformRequirementFilter/IgnoreListPlatformRequirementFilterTest.php @@ -0,0 +1,35 @@ +assertSame($expectIgnored, $platformRequirementFilter->isIgnored($req)); + } + + /** + * @return array + */ + public function dataIsIgnored() + { + return array( + 'ext-json is ignored if listed' => array(array('ext-json', 'monolog/monolog'), 'ext-json', true), + 'php is not ignored if not listed' => array(array('ext-json', 'monolog/monolog'), 'php', false), + 'monolog/monolog is not ignored even if listed' => array(array('ext-json', 'monolog/monolog'), 'monolog/monolog', false), + ); + } +} diff --git a/tests/Composer/Test/Filter/PlatformRequirementFilter/IgnoreNothingPlatformRequirementFilterTest.php b/tests/Composer/Test/Filter/PlatformRequirementFilter/IgnoreNothingPlatformRequirementFilterTest.php new file mode 100644 index 000000000..dacc498f9 --- /dev/null +++ b/tests/Composer/Test/Filter/PlatformRequirementFilter/IgnoreNothingPlatformRequirementFilterTest.php @@ -0,0 +1,32 @@ +assertFalse($platformRequirementFilter->isIgnored($req)); + } + + /** + * @return array + */ + public function dataIsIgnored() + { + return array( + 'php is not ignored' => array('php'), + 'monolog/monolog is not ignored' => array('monolog/monolog'), + ); + } +} diff --git a/tests/Composer/Test/Filter/PlatformRequirementFilter/PlatformRequirementFilterFactoryTest.php b/tests/Composer/Test/Filter/PlatformRequirementFilter/PlatformRequirementFilterFactoryTest.php new file mode 100644 index 000000000..10eaa3fb3 --- /dev/null +++ b/tests/Composer/Test/Filter/PlatformRequirementFilter/PlatformRequirementFilterFactoryTest.php @@ -0,0 +1,53 @@ +assertInstanceOf($expectedInstance, PlatformRequirementFilterFactory::fromBoolOrList($boolOrList)); + } + + /** + * @return array + */ + public function dataFromBoolOrList() + { + return array( + 'true creates IgnoreAllFilter' => array(true, 'Composer\Filter\PlatformRequirementFilter\IgnoreAllPlatformRequirementFilter'), + 'false creates IgnoreNothingFilter' => array(false, 'Composer\Filter\PlatformRequirementFilter\IgnoreNothingPlatformRequirementFilter'), + 'list creates IgnoreListFilter' => array(array('php', 'ext-json'), 'Composer\Filter\PlatformRequirementFilter\IgnoreListPlatformRequirementFilter'), + ); + } + + public function testFromBoolThrowsExceptionIfTypeIsUnknown() + { + $this->setExpectedException('InvalidArgumentException', 'PlatformRequirementFilter: Unknown $boolOrList parameter NULL. Please report at https://github.com/composer/composer/issues/new.'); + + PlatformRequirementFilterFactory::fromBoolOrList(null); + } + + public function testIgnoreAll() + { + $platformRequirementFilter = PlatformRequirementFilterFactory::ignoreAll(); + + $this->assertInstanceOf('Composer\Filter\PlatformRequirementFilter\IgnoreAllPlatformRequirementFilter', $platformRequirementFilter); + } + + public function testIgnoreNothing() + { + $platformRequirementFilter = PlatformRequirementFilterFactory::ignoreNothing(); + + $this->assertInstanceOf('Composer\Filter\PlatformRequirementFilter\IgnoreNothingPlatformRequirementFilter', $platformRequirementFilter); + } +} diff --git a/tests/Composer/Test/InstallerTest.php b/tests/Composer/Test/InstallerTest.php index 11d501b62..79f03f824 100644 --- a/tests/Composer/Test/InstallerTest.php +++ b/tests/Composer/Test/InstallerTest.php @@ -13,6 +13,7 @@ namespace Composer\Test; use Composer\DependencyResolver\Request; +use Composer\Filter\PlatformRequirementFilter\PlatformRequirementFilterFactory; use Composer\Installer; use Symfony\Component\Console\Application; use Symfony\Component\Console\Command\Command; @@ -340,7 +341,7 @@ class InstallerTest extends TestCase $installer ->setDevMode(!$input->getOption('no-dev')) ->setDryRun($input->getOption('dry-run')) - ->setIgnorePlatformRequirements($ignorePlatformReqs); + ->setPlatformRequirementFilter(PlatformRequirementFilterFactory::fromBoolOrList($ignorePlatformReqs)); return $installer->run(); }); @@ -385,7 +386,7 @@ class InstallerTest extends TestCase ->setUpdateAllowTransitiveDependencies($updateAllowTransitiveDependencies) ->setPreferStable($input->getOption('prefer-stable')) ->setPreferLowest($input->getOption('prefer-lowest')) - ->setIgnorePlatformRequirements($ignorePlatformReqs); + ->setPlatformRequirementFilter(PlatformRequirementFilterFactory::fromBoolOrList($ignorePlatformReqs)); return $installer->run(); }); diff --git a/tests/Composer/Test/Package/Version/VersionSelectorTest.php b/tests/Composer/Test/Package/Version/VersionSelectorTest.php index 863f74243..153c522f6 100644 --- a/tests/Composer/Test/Package/Version/VersionSelectorTest.php +++ b/tests/Composer/Test/Package/Version/VersionSelectorTest.php @@ -12,6 +12,7 @@ namespace Composer\Test\Package\Version; +use Composer\Filter\PlatformRequirementFilter\PlatformRequirementFilterFactory; use Composer\Package\Version\VersionSelector; use Composer\Package\Package; use Composer\Package\Link; @@ -70,7 +71,7 @@ class VersionSelectorTest extends TestCase $best = $versionSelector->findBestCandidate($packageName); $this->assertSame($package1, $best, 'Latest version supporting php 5.5 should be returned (1.0.0)'); - $best = $versionSelector->findBestCandidate($packageName, null, 'stable', true); + $best = $versionSelector->findBestCandidate($packageName, null, 'stable', PlatformRequirementFilterFactory::ignoreAll()); $this->assertSame($package2, $best, 'Latest version should be returned when ignoring platform reqs (2.0.0)'); } @@ -96,7 +97,7 @@ class VersionSelectorTest extends TestCase $best = $versionSelector->findBestCandidate($packageName); $this->assertSame($package1, $best, 'Latest version supporting ext-zip 5.3.0 should be returned (1.0.0)'); - $best = $versionSelector->findBestCandidate($packageName, null, 'stable', true); + $best = $versionSelector->findBestCandidate($packageName, null, 'stable', PlatformRequirementFilterFactory::ignoreAll()); $this->assertSame($package2, $best, 'Latest version should be returned when ignoring platform reqs (2.0.0)'); } @@ -121,7 +122,7 @@ class VersionSelectorTest extends TestCase $best = $versionSelector->findBestCandidate($packageName); $this->assertSame($package1, $best, 'Latest version not requiring ext-barfoo should be returned (1.0.0)'); - $best = $versionSelector->findBestCandidate($packageName, null, 'stable', true); + $best = $versionSelector->findBestCandidate($packageName, null, 'stable', PlatformRequirementFilterFactory::ignoreAll()); $this->assertSame($package2, $best, 'Latest version should be returned when ignoring platform reqs (2.0.0)'); } @@ -147,7 +148,7 @@ class VersionSelectorTest extends TestCase $best = $versionSelector->findBestCandidate($packageName); $this->assertSame($package1, $best, 'Latest version supporting composer 1 should be returned (1.0.0)'); - $best = $versionSelector->findBestCandidate($packageName, null, 'stable', true); + $best = $versionSelector->findBestCandidate($packageName, null, 'stable', PlatformRequirementFilterFactory::ignoreAll()); $this->assertSame($package2, $best, 'Latest version should be returned when ignoring platform reqs (1.1.0)'); }