1
0
Fork 0

Merge branch '1.2'

pull/5776/head
Jordi Boggiano 2016-10-08 11:27:52 +02:00
commit 4cd6eabdba
5 changed files with 99 additions and 26 deletions

View File

@ -99,8 +99,11 @@ 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.
// 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');
$prependAutoloader = $config->get('prepend-autoloader') === false ? 'false' : 'true';
$targetDir = $vendorPath.'/'.$targetDir;

View File

@ -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;

View File

@ -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);
}

View File

@ -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);
}
}

View File

@ -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';