Merge pull request #5726 from alcohol/what-provides-stability-ordering-issue
What provides stability ordering issuepull/5744/head^2
commit
205030afc6
|
@ -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;
|
||||
|
|
|
@ -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';
|
||||
|
|
Loading…
Reference in New Issue