From 94daeca57b87da6762116bd85861adc722bfa0df Mon Sep 17 00:00:00 2001 From: Rob Bast Date: Fri, 5 Feb 2016 11:39:14 +0100 Subject: [PATCH 1/4] add test and adjust rule error message --- src/Composer/DependencyResolver/Rule.php | 4 +- .../installer/github-issues-4319.test | 45 +++++++++++++++++++ 2 files changed, 48 insertions(+), 1 deletion(-) create mode 100644 tests/Composer/Test/Fixtures/installer/github-issues-4319.test diff --git a/src/Composer/DependencyResolver/Rule.php b/src/Composer/DependencyResolver/Rule.php index 13bbb7e09..32546fd27 100644 --- a/src/Composer/DependencyResolver/Rule.php +++ b/src/Composer/DependencyResolver/Rule.php @@ -207,7 +207,9 @@ class Rule } elseif ($targetName === 'hhvm') { $text .= ' -> you are running this with PHP and not HHVM.'; } else { - $text .= ' -> your PHP version ('. phpversion() .') or value of "config.platform.php" in composer.json does not satisfy that requirement.'; + $available = $pool->whatProvides($targetName); + $version = count($available) ? $available[0]->getPrettyVersion() : phpversion(); + $text .= ' -> your PHP version or "config.platform.php" value ('.$version.') does not satisfy that requirement.'; } } elseif (0 === strpos($targetName, 'ext-')) { // handle php extensions diff --git a/tests/Composer/Test/Fixtures/installer/github-issues-4319.test b/tests/Composer/Test/Fixtures/installer/github-issues-4319.test new file mode 100644 index 000000000..5bfc17af6 --- /dev/null +++ b/tests/Composer/Test/Fixtures/installer/github-issues-4319.test @@ -0,0 +1,45 @@ +--TEST-- + +See Github issue #4319 ( github.com/composer/composer/issues/4319 ). + +Present a clear error message when config.platform.php version results in a conflict rule. + +--CONDITION-- +!defined('HHVM_VERSION') + +--COMPOSER-- +{ + "repositories": [ + { + "type": "package", + "package": [ + { "name": "a", "version": "1.0.0", "require": { "php": "5.5" } } + ] + } + ], + "require": { + "a": "~1.0" + }, + "config": { + "platform": { + "php": "5.3" + } + } +} + +--RUN-- +install + +--EXPECT-OUTPUT-- +Loading composer repositories with package information +Installing dependencies (including require-dev) +Your requirements could not be resolved to an installable set of packages. + + Problem 1 + - Installation request for a ~1.0 -> satisfiable by a[1.0.0]. + - a 1.0.0 requires php 5.5 -> your PHP version or "config.platform.php" value (5.3) does not satisfy that requirement. + +--EXPECT-- + +--EXPECT-EXIT-CODE-- +2 From baabc612f672b45eb74d6884e835360bbaabcc2e Mon Sep 17 00:00:00 2001 From: Rob Bast Date: Fri, 5 Feb 2016 13:21:30 +0100 Subject: [PATCH 2/4] adjust message, skip test currently we have no way to put dynamic values or wildcards in EXPECT-OUTPUT --- src/Composer/DependencyResolver/Rule.php | 31 ++++++++++++++----- .../Repository/PlatformRepository.php | 1 + ...9.test => github-issues-4319.test.skipped} | 2 +- 3 files changed, 25 insertions(+), 9 deletions(-) rename tests/Composer/Test/Fixtures/installer/{github-issues-4319.test => github-issues-4319.test.skipped} (85%) diff --git a/src/Composer/DependencyResolver/Rule.php b/src/Composer/DependencyResolver/Rule.php index 32546fd27..54a002203 100644 --- a/src/Composer/DependencyResolver/Rule.php +++ b/src/Composer/DependencyResolver/Rule.php @@ -12,6 +12,8 @@ namespace Composer\DependencyResolver; +use Composer\Package\CompletePackage; + /** * @author Nils Adermann */ @@ -203,27 +205,40 @@ class Rule if ($targetName === 'php' || $targetName === 'php-64bit' || $targetName === 'hhvm') { // handle php/hhvm if (defined('HHVM_VERSION')) { - $text .= ' -> your HHVM version does not satisfy that requirement.'; + return $text . ' -> your HHVM version does not satisfy that requirement.'; } elseif ($targetName === 'hhvm') { - $text .= ' -> you are running this with PHP and not HHVM.'; + return $text . ' -> you are running this with PHP and not HHVM.'; } else { - $available = $pool->whatProvides($targetName); - $version = count($available) ? $available[0]->getPrettyVersion() : phpversion(); - $text .= ' -> your PHP version or "config.platform.php" value ('.$version.') does not satisfy that requirement.'; + $packages = $pool->whatProvides($targetName); + $package = count($packages) ? current($packages) : phpversion(); + + if (!($package instanceof CompletePackage)) { + return $text . ' -> your PHP version ('.phpversion().') does not satisfy that requirement.'; + } + + $extra = $package->getExtra(); + + if (!empty($extra['config.platform'])) { + $text .= ' -> your PHP version ('.phpversion().') overriden by "config.platform.php" version ('.$package->getPrettyVersion().') does not satisfy that requirement.'; + } else { + $text .= ' -> your PHP version ('.$package->getPrettyVersion().') does not satisfy that requirement.'; + } + + return $text; } } elseif (0 === strpos($targetName, 'ext-')) { // handle php extensions $ext = substr($targetName, 4); $error = extension_loaded($ext) ? 'has the wrong version ('.(phpversion($ext) ?: '0').') installed' : 'is missing from your system'; - $text .= ' -> the requested PHP extension '.$ext.' '.$error.'.'; + return $text . ' -> the requested PHP extension '.$ext.' '.$error.'.'; } elseif (0 === strpos($targetName, 'lib-')) { // handle linked libs $lib = substr($targetName, 4); - $text .= ' -> the requested linked library '.$lib.' has the wrong version installed or is missing from your system, make sure to have the extension providing it.'; + return $text . ' -> the requested linked library '.$lib.' has the wrong version installed or is missing from your system, make sure to have the extension providing it.'; } else { - $text .= ' -> no matching package found.'; + return $text . ' -> no matching package found.'; } } diff --git a/src/Composer/Repository/PlatformRepository.php b/src/Composer/Repository/PlatformRepository.php index 27f52aa65..5016335b0 100644 --- a/src/Composer/Repository/PlatformRepository.php +++ b/src/Composer/Repository/PlatformRepository.php @@ -59,6 +59,7 @@ class PlatformRepository extends ArrayRepository $version = $versionParser->normalize($override['version']); $package = new CompletePackage($override['name'], $version, $override['version']); $package->setDescription('Package overridden via config.platform'); + $package->setExtra(array('config.platform' => true)); parent::addPackage($package); } diff --git a/tests/Composer/Test/Fixtures/installer/github-issues-4319.test b/tests/Composer/Test/Fixtures/installer/github-issues-4319.test.skipped similarity index 85% rename from tests/Composer/Test/Fixtures/installer/github-issues-4319.test rename to tests/Composer/Test/Fixtures/installer/github-issues-4319.test.skipped index 5bfc17af6..3833bcf9b 100644 --- a/tests/Composer/Test/Fixtures/installer/github-issues-4319.test +++ b/tests/Composer/Test/Fixtures/installer/github-issues-4319.test.skipped @@ -37,7 +37,7 @@ Your requirements could not be resolved to an installable set of packages. Problem 1 - Installation request for a ~1.0 -> satisfiable by a[1.0.0]. - - a 1.0.0 requires php 5.5 -> your PHP version or "config.platform.php" value (5.3) does not satisfy that requirement. + - a 1.0.0 requires php 5.5 -> your PHP version (5.6.17) overriden by "config.platform.php" version (5.3) does not satisfy that requirement. --EXPECT-- From baa84d9be1477b2db7d964a6b52aae8302fbfc1d Mon Sep 17 00:00:00 2001 From: Rob Bast Date: Fri, 5 Feb 2016 13:34:21 +0100 Subject: [PATCH 3/4] adjust test and assertion to be more flexible --- .../Test/Fixtures/installer/github-issues-4319.test.skipped | 2 +- tests/Composer/Test/InstallerTest.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/Composer/Test/Fixtures/installer/github-issues-4319.test.skipped b/tests/Composer/Test/Fixtures/installer/github-issues-4319.test.skipped index 3833bcf9b..56536ed72 100644 --- a/tests/Composer/Test/Fixtures/installer/github-issues-4319.test.skipped +++ b/tests/Composer/Test/Fixtures/installer/github-issues-4319.test.skipped @@ -37,7 +37,7 @@ Your requirements could not be resolved to an installable set of packages. Problem 1 - Installation request for a ~1.0 -> satisfiable by a[1.0.0]. - - a 1.0.0 requires php 5.5 -> your PHP version (5.6.17) overriden by "config.platform.php" version (5.3) does not satisfy that requirement. + - a 1.0.0 requires php 5.5 -> your PHP version (%s) overriden by "config.platform.php" version (5.3) does not satisfy that requirement. --EXPECT-- diff --git a/tests/Composer/Test/InstallerTest.php b/tests/Composer/Test/InstallerTest.php index eaf6caa03..5aa9f862e 100644 --- a/tests/Composer/Test/InstallerTest.php +++ b/tests/Composer/Test/InstallerTest.php @@ -252,7 +252,7 @@ class InstallerTest extends TestCase $this->assertSame(rtrim($expect), implode("\n", $installationManager->getTrace())); if ($expectOutput) { - $this->assertEquals(rtrim($expectOutput), rtrim($output)); + $this->assertStringMatchesFormat(rtrim($expectOutput), rtrim($output)); } } From 5db0f623b01d802b20dc49ad9d430a43b668cbf7 Mon Sep 17 00:00:00 2001 From: Rob Bast Date: Fri, 5 Feb 2016 13:36:53 +0100 Subject: [PATCH 4/4] enable test again --- .../{github-issues-4319.test.skipped => github-issues-4319.test} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename tests/Composer/Test/Fixtures/installer/{github-issues-4319.test.skipped => github-issues-4319.test} (100%) diff --git a/tests/Composer/Test/Fixtures/installer/github-issues-4319.test.skipped b/tests/Composer/Test/Fixtures/installer/github-issues-4319.test similarity index 100% rename from tests/Composer/Test/Fixtures/installer/github-issues-4319.test.skipped rename to tests/Composer/Test/Fixtures/installer/github-issues-4319.test