Take into account prefer-stable and dev packages when computing outdated, refs #5251
parent
2a3b56e82c
commit
6146f7aded
|
@ -176,7 +176,7 @@ EOT
|
||||||
} else {
|
} else {
|
||||||
$latestPackage = null;
|
$latestPackage = null;
|
||||||
if ($input->getOption('latest')) {
|
if ($input->getOption('latest')) {
|
||||||
$latestPackage = $this->findLatestPackage($package->getName(), $composer, $phpVersion);
|
$latestPackage = $this->findLatestPackage($package, $composer, $phpVersion);
|
||||||
}
|
}
|
||||||
$this->printMeta($package, $versions, $installedRepo, $latestPackage);
|
$this->printMeta($package, $versions, $installedRepo, $latestPackage);
|
||||||
$this->printLinks($package, 'requires');
|
$this->printLinks($package, 'requires');
|
||||||
|
@ -275,7 +275,7 @@ EOT
|
||||||
if ($showVersion) {
|
if ($showVersion) {
|
||||||
$versionLength = max($versionLength, strlen($package->getFullPrettyVersion()));
|
$versionLength = max($versionLength, strlen($package->getFullPrettyVersion()));
|
||||||
if ($showLatest) {
|
if ($showLatest) {
|
||||||
$latestPackage = $this->findLatestPackage($package->getName(), $composer, $phpVersion);
|
$latestPackage = $this->findLatestPackage($package, $composer, $phpVersion);
|
||||||
$latestPackages[$package->getPrettyName()] = $latestPackage;
|
$latestPackages[$package->getPrettyName()] = $latestPackage;
|
||||||
$latestLength = max($latestLength, strlen($latestPackage->getFullPrettyVersion()));
|
$latestLength = max($latestLength, strlen($latestPackage->getFullPrettyVersion()));
|
||||||
}
|
}
|
||||||
|
@ -701,17 +701,18 @@ EOT
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Given a package name, this finds the latest package matching it
|
* Given a package, this finds the latest package matching it
|
||||||
*
|
*
|
||||||
* @param string $name
|
* @param PackageInterface $package
|
||||||
* @param Composer $composer
|
* @param Composer $composer
|
||||||
* @param string $phpVersion
|
* @param string $phpVersion
|
||||||
*
|
*
|
||||||
* @return PackageInterface|null
|
* @return PackageInterface|null
|
||||||
*/
|
*/
|
||||||
private function findLatestPackage($name, Composer $composer, $phpVersion)
|
private function findLatestPackage(PackageInterface $package, Composer $composer, $phpVersion)
|
||||||
{
|
{
|
||||||
// find the latest version allowed in this pool
|
// find the latest version allowed in this pool
|
||||||
|
$name = $package->getName();
|
||||||
$versionSelector = new VersionSelector($this->getPool($composer));
|
$versionSelector = new VersionSelector($this->getPool($composer));
|
||||||
$stability = $composer->getPackage()->getMinimumStability();
|
$stability = $composer->getPackage()->getMinimumStability();
|
||||||
$flags = $composer->getPackage()->getStabilityFlags();
|
$flags = $composer->getPackage()->getStabilityFlags();
|
||||||
|
@ -719,7 +720,17 @@ EOT
|
||||||
$stability = array_search($flags[$name], BasePackage::$stabilities, true);
|
$stability = array_search($flags[$name], BasePackage::$stabilities, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $versionSelector->findBestCandidate($name, null, $phpVersion, $stability);
|
$bestStability = $stability;
|
||||||
|
if ($composer->getPackage()->getPreferStable()) {
|
||||||
|
$bestStability = $package->getStability();
|
||||||
|
}
|
||||||
|
|
||||||
|
$targetVersion = null;
|
||||||
|
if (0 === strpos($package->getVersion(), 'dev-')) {
|
||||||
|
$targetVersion = $package->getVersion();
|
||||||
|
}
|
||||||
|
|
||||||
|
return $versionSelector->findBestCandidate($name, $targetVersion, $phpVersion, $bestStability);
|
||||||
}
|
}
|
||||||
|
|
||||||
private function getPool(Composer $composer)
|
private function getPool(Composer $composer)
|
||||||
|
|
|
@ -129,6 +129,26 @@ class VersionSelectorTest extends \PHPUnit_Framework_TestCase
|
||||||
$this->assertSame($package2, $best, 'Latest version should be returned (1.1.0-beta)');
|
$this->assertSame($package2, $best, 'Latest version should be returned (1.1.0-beta)');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testMostStableUnstableVersionIsReturned()
|
||||||
|
{
|
||||||
|
$packageName = 'foobar';
|
||||||
|
|
||||||
|
$package2 = $this->createPackage('1.1.0-beta');
|
||||||
|
$package3 = $this->createPackage('1.2.0-alpha');
|
||||||
|
$packages = array($package2, $package3);
|
||||||
|
|
||||||
|
$pool = $this->createMockPool();
|
||||||
|
$pool->expects($this->once())
|
||||||
|
->method('whatProvides')
|
||||||
|
->with($packageName, null, true)
|
||||||
|
->will($this->returnValue($packages));
|
||||||
|
|
||||||
|
$versionSelector = new VersionSelector($pool);
|
||||||
|
$best = $versionSelector->findBestCandidate($packageName, null, null, 'stable');
|
||||||
|
|
||||||
|
$this->assertSame($package2, $best, 'Latest version should be returned (1.1.0-beta)');
|
||||||
|
}
|
||||||
|
|
||||||
public function testFalseReturnedOnNoPackages()
|
public function testFalseReturnedOnNoPackages()
|
||||||
{
|
{
|
||||||
$pool = $this->createMockPool();
|
$pool = $this->createMockPool();
|
||||||
|
|
Loading…
Reference in New Issue