From 9f2bd34c87274e2141f85796079fe4650b804c06 Mon Sep 17 00:00:00 2001 From: Rob Bast Date: Tue, 27 Sep 2016 16:59:48 +0200 Subject: [PATCH 1/6] test copied from #5724 --- .../Package/Version/VersionSelectorTest.php | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/tests/Composer/Test/Package/Version/VersionSelectorTest.php b/tests/Composer/Test/Package/Version/VersionSelectorTest.php index f8f292f3d..c28ac3c17 100644 --- a/tests/Composer/Test/Package/Version/VersionSelectorTest.php +++ b/tests/Composer/Test/Package/Version/VersionSelectorTest.php @@ -88,6 +88,33 @@ class VersionSelectorTest extends \PHPUnit_Framework_TestCase $this->assertSame($package1, $best, 'Latest most stable version should be returned (1.0.0)'); } + public function testMostStableVersionIsReturnedRegardlessOfOrder() + { + $packageName = 'foobar'; + + $package1 = $this->createPackage('2.x-dev'); + $package2 = $this->createPackage('2.0.0-beta3'); + $packages = array($package1, $package2); + + $pool = $this->createMockPool(); + $pool->expects($this->at(0)) + ->method('whatProvides') + ->with($packageName, null, true) + ->will($this->returnValue($packages)); + + $pool->expects($this->at(1)) + ->method('whatProvides') + ->with($packageName, null, true) + ->will($this->returnValue(array_reverse($packages))); + + $versionSelector = new VersionSelector($pool); + $best = $versionSelector->findBestCandidate($packageName, null, null); + $this->assertSame($package2, $best, 'Expecting 2.0.0-beta3, cause beta is more stable than dev'); + + $best = $versionSelector->findBestCandidate($packageName, null, null); + $this->assertSame($package2, $best, 'Expecting 2.0.0-beta3, cause beta is more stable than dev'); + } + public function testHighestVersionIsReturned() { $packageName = 'foobar'; From 710bb0d0083eb8a0c476448d321fd80646efeddc Mon Sep 17 00:00:00 2001 From: Rob Bast Date: Tue, 27 Sep 2016 17:17:30 +0200 Subject: [PATCH 2/6] fix based on test, fixes #5724 --- src/Composer/Package/Version/VersionSelector.php | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/Composer/Package/Version/VersionSelector.php b/src/Composer/Package/Version/VersionSelector.php index 817d5ed48..8e225d803 100644 --- a/src/Composer/Package/Version/VersionSelector.php +++ b/src/Composer/Package/Version/VersionSelector.php @@ -71,11 +71,21 @@ class VersionSelector $candidatePriority = $candidate->getStabilityPriority(); $currentPriority = $package->getStabilityPriority(); - // candidate is less stable than our preferred stability, and we have a package that is more stable than it, so we skip it + // candidate is less stable than our preferred stability, + // and current package is more stable than candidate, skip it if ($minPriority < $candidatePriority && $currentPriority < $candidatePriority) { continue; } - // candidate is more stable than our preferred stability, and current package is less stable than preferred stability, then we select the candidate always + + // candidate is less stable than our preferred stability, + // and current package is less stable than candidate, select candidate + if ($minPriority < $candidatePriority && $candidatePriority < $currentPriority) { + $package = $candidate; + continue; + } + + // candidate is more stable than our preferred stability, + // and current package is less stable than preferred stability, select candidate if ($minPriority >= $candidatePriority && $minPriority < $currentPriority) { $package = $candidate; continue; From 9cbcda9ae6e783c473475f22e489dbe960006468 Mon Sep 17 00:00:00 2001 From: Rob Bast Date: Tue, 27 Sep 2016 18:03:14 +0200 Subject: [PATCH 3/6] add test that asserts pool priority matters also switch assertEquals for assertSame --- .../DependencyResolver/DefaultPolicyTest.php | 76 +++++++++++++------ 1 file changed, 54 insertions(+), 22 deletions(-) diff --git a/tests/Composer/Test/DependencyResolver/DefaultPolicyTest.php b/tests/Composer/Test/DependencyResolver/DefaultPolicyTest.php index d694813c6..a73139d54 100644 --- a/tests/Composer/Test/DependencyResolver/DefaultPolicyTest.php +++ b/tests/Composer/Test/DependencyResolver/DefaultPolicyTest.php @@ -23,10 +23,13 @@ use Composer\TestCase; class DefaultPolicyTest extends TestCase { + /** @var Pool */ protected $pool; + /** @var ArrayRepository */ protected $repo; + /** @var ArrayRepository */ protected $repoInstalled; - protected $request; + /** @var DefaultPolicy */ protected $policy; public function setUp() @@ -48,7 +51,7 @@ class DefaultPolicyTest extends TestCase $selected = $this->policy->selectPreferredPackages($this->pool, array(), $literals); - $this->assertEquals($expected, $selected); + $this->assertSame($expected, $selected); } public function testSelectNewest() @@ -62,7 +65,7 @@ class DefaultPolicyTest extends TestCase $selected = $this->policy->selectPreferredPackages($this->pool, array(), $literals); - $this->assertEquals($expected, $selected); + $this->assertSame($expected, $selected); } public function testSelectNewestPicksLatest() @@ -76,7 +79,7 @@ class DefaultPolicyTest extends TestCase $selected = $this->policy->selectPreferredPackages($this->pool, array(), $literals); - $this->assertEquals($expected, $selected); + $this->assertSame($expected, $selected); } public function testSelectNewestPicksLatestStableWithPreferStable() @@ -91,7 +94,7 @@ class DefaultPolicyTest extends TestCase $policy = new DefaultPolicy(true); $selected = $policy->selectPreferredPackages($this->pool, array(), $literals); - $this->assertEquals($expected, $selected); + $this->assertSame($expected, $selected); } public function testSelectNewestWithDevPicksNonDev() @@ -105,7 +108,7 @@ class DefaultPolicyTest extends TestCase $selected = $this->policy->selectPreferredPackages($this->pool, array(), $literals); - $this->assertEquals($expected, $selected); + $this->assertSame($expected, $selected); } public function testSelectNewestOverInstalled() @@ -120,18 +123,18 @@ class DefaultPolicyTest extends TestCase $selected = $this->policy->selectPreferredPackages($this->pool, $this->mapFromRepo($this->repoInstalled), $literals); - $this->assertEquals($expected, $selected); + $this->assertSame($expected, $selected); } public function testSelectFirstRepo() { - $this->repoImportant = new ArrayRepository; + $otherRepository = new ArrayRepository; $this->repo->addPackage($packageA = $this->getPackage('A', '1.0')); - $this->repoImportant->addPackage($packageAImportant = $this->getPackage('A', '1.0')); + $otherRepository->addPackage($packageAImportant = $this->getPackage('A', '1.0')); $this->pool->addRepository($this->repoInstalled); - $this->pool->addRepository($this->repoImportant); + $this->pool->addRepository($otherRepository); $this->pool->addRepository($this->repo); $literals = array($packageA->getId(), $packageAImportant->getId()); @@ -139,23 +142,52 @@ class DefaultPolicyTest extends TestCase $selected = $this->policy->selectPreferredPackages($this->pool, array(), $literals); - $this->assertEquals($expected, $selected); + $this->assertSame($expected, $selected); + } + + public function testRepositoryOrderingAffectsPriority() + { + $repo1 = new ArrayRepository; + $repo2 = new ArrayRepository; + + $repo1->addPackage($package1 = $this->getPackage('A', '1.0')); + $repo1->addPackage($package2 = $this->getPackage('A', '1.1')); + $repo2->addPackage($package3 = $this->getPackage('A', '1.1')); + $repo2->addPackage($package4 = $this->getPackage('A', '1.2')); + + $this->pool->addRepository($repo1); + $this->pool->addRepository($repo2); + + $literals = array($package1->getId(), $package2->getId(), $package3->getId(), $package4->getId()); + $expected = array($package2->getId()); + $selected = $this->policy->selectPreferredPackages($this->pool, array(), $literals); + + $this->assertSame($expected, $selected); + + $this->pool = new Pool('dev'); + $this->pool->addRepository($repo2); + $this->pool->addRepository($repo1); + + $expected = array($package4->getId()); + $selected = $this->policy->selectPreferredPackages($this->pool, array(), $literals); + + $this->assertSame($expected, $selected); } public function testSelectLocalReposFirst() { - $this->repoImportant = new ArrayRepository; + $repoImportant = new ArrayRepository; $this->repo->addPackage($packageA = $this->getPackage('A', 'dev-master')); $this->repo->addPackage($packageAAlias = new AliasPackage($packageA, '2.1.9999999.9999999-dev', '2.1.x-dev')); - $this->repoImportant->addPackage($packageAImportant = $this->getPackage('A', 'dev-feature-a')); - $this->repoImportant->addPackage($packageAAliasImportant = new AliasPackage($packageAImportant, '2.1.9999999.9999999-dev', '2.1.x-dev')); - $this->repoImportant->addPackage($packageA2Important = $this->getPackage('A', 'dev-master')); - $this->repoImportant->addPackage($packageA2AliasImportant = new AliasPackage($packageA2Important, '2.1.9999999.9999999-dev', '2.1.x-dev')); + $repoImportant->addPackage($packageAImportant = $this->getPackage('A', 'dev-feature-a')); + $repoImportant->addPackage($packageAAliasImportant = new AliasPackage($packageAImportant, '2.1.9999999.9999999-dev', '2.1.x-dev')); + $repoImportant->addPackage($packageA2Important = $this->getPackage('A', 'dev-master')); + $repoImportant->addPackage($packageA2AliasImportant = new AliasPackage($packageA2Important, '2.1.9999999.9999999-dev', '2.1.x-dev')); $packageAAliasImportant->setRootPackageAlias(true); $this->pool->addRepository($this->repoInstalled); - $this->pool->addRepository($this->repoImportant); + $this->pool->addRepository($repoImportant); $this->pool->addRepository($this->repo); $packages = $this->pool->whatProvides('a', new Constraint('=', '2.1.9999999.9999999-dev')); @@ -168,7 +200,7 @@ class DefaultPolicyTest extends TestCase $selected = $this->policy->selectPreferredPackages($this->pool, array(), $literals); - $this->assertEquals($expected, $selected); + $this->assertSame($expected, $selected); } public function testSelectAllProviders() @@ -186,7 +218,7 @@ class DefaultPolicyTest extends TestCase $selected = $this->policy->selectPreferredPackages($this->pool, array(), $literals); - $this->assertEquals($expected, $selected); + $this->assertSame($expected, $selected); } public function testPreferNonReplacingFromSameRepo() @@ -203,7 +235,7 @@ class DefaultPolicyTest extends TestCase $selected = $this->policy->selectPreferredPackages($this->pool, array(), $literals); - $this->assertEquals($expected, $selected); + $this->assertSame($expected, $selected); } public function testPreferReplacingPackageFromSameVendor() @@ -235,7 +267,7 @@ class DefaultPolicyTest extends TestCase $expected = $literals; $selected = $this->policy->selectPreferredPackages($this->pool, array(), $literals, 'vendor-a/package'); - $this->assertEquals($expected, $selected); + $this->assertSame($expected, $selected); } protected function mapFromRepo(RepositoryInterface $repo) @@ -261,6 +293,6 @@ class DefaultPolicyTest extends TestCase $selected = $policy->selectPreferredPackages($this->pool, array(), $literals); - $this->assertEquals($expected, $selected); + $this->assertSame($expected, $selected); } } From c774d41a9cab65512f413d0d35201d592620dd93 Mon Sep 17 00:00:00 2001 From: AnrDaemon Date: Thu, 29 Sep 2016 08:05:55 +0200 Subject: [PATCH 4/6] Fix realpath() failing on Windows --- src/Composer/Autoload/AutoloadGenerator.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/Composer/Autoload/AutoloadGenerator.php b/src/Composer/Autoload/AutoloadGenerator.php index 2a66a4bf6..95bab637e 100644 --- a/src/Composer/Autoload/AutoloadGenerator.php +++ b/src/Composer/Autoload/AutoloadGenerator.php @@ -99,8 +99,10 @@ class AutoloadGenerator $filesystem = new Filesystem(); $filesystem->ensureDirectoryExists($config->get('vendor-dir')); - $basePath = $filesystem->normalizePath(realpath(getcwd())); - $vendorPath = $filesystem->normalizePath(realpath($config->get('vendor-dir'))); + // Do not remove double realpath() calls. + // Fixes failing Windows realpath() implementation. + $basePath = $filesystem->normalizePath(realpath(realpath(getcwd()))); + $vendorPath = $filesystem->normalizePath(realpath(realpath($config->get('vendor-dir')))); $useGlobalIncludePath = (bool) $config->get('use-include-path'); $prependAutoloader = $config->get('prepend-autoloader') === false ? 'false' : 'true'; $targetDir = $vendorPath.'/'.$targetDir; From 902a5c32db1795a40b10a8f945e06718e6ccfe66 Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Thu, 29 Sep 2016 08:06:44 +0200 Subject: [PATCH 5/6] Add bug ref --- src/Composer/Autoload/AutoloadGenerator.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Composer/Autoload/AutoloadGenerator.php b/src/Composer/Autoload/AutoloadGenerator.php index 95bab637e..0d61083a0 100644 --- a/src/Composer/Autoload/AutoloadGenerator.php +++ b/src/Composer/Autoload/AutoloadGenerator.php @@ -101,6 +101,7 @@ class AutoloadGenerator $filesystem->ensureDirectoryExists($config->get('vendor-dir')); // Do not remove double realpath() calls. // Fixes failing Windows realpath() implementation. + // See https://bugs.php.net/bug.php?id=72738 $basePath = $filesystem->normalizePath(realpath(realpath(getcwd()))); $vendorPath = $filesystem->normalizePath(realpath(realpath($config->get('vendor-dir')))); $useGlobalIncludePath = (bool) $config->get('use-include-path'); From b502a35fc1c7cf249836c02b16bb384fef0ed7c5 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Fri, 7 Oct 2016 11:38:36 -0700 Subject: [PATCH 6/6] added missing var declaration --- src/Composer/Plugin/PluginManager.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Composer/Plugin/PluginManager.php b/src/Composer/Plugin/PluginManager.php index fcc170223..80b5b91ea 100644 --- a/src/Composer/Plugin/PluginManager.php +++ b/src/Composer/Plugin/PluginManager.php @@ -183,6 +183,7 @@ class PluginManager $path = $classLoader->findFile($class); $code = file_get_contents($path); $separatorPos = strrpos($class, '\\'); + $className = $class; if ($separatorPos) { $className = substr($class, $separatorPos + 1); }