1
0
Fork 0

Merge remote-tracking branch 'naderman/fix-duplicate-alias'

pull/836/head
Jordi Boggiano 2012-07-01 19:07:14 +02:00
commit 2ede0a3b54
4 changed files with 89 additions and 5 deletions

View File

@ -105,7 +105,10 @@ class ArrayRepository implements RepositoryInterface
// create alias package on the fly if needed
if ($package->getAlias()) {
$this->addPackage($this->createAliasPackage($package));
$alias = $this->createAliasPackage($package);
if (!$this->hasPackage($alias)) {
$this->addPackage($alias);
}
}
}

View File

@ -0,0 +1,55 @@
--TEST--
Update aliased package to non-aliased version
--COMPOSER--
{
"repositories": [
{
"type": "package",
"package": [
{
"name": "a/a", "version": "dev-master",
"extra": { "branch-alias": { "dev-master": "1.0.x-dev" } },
"source": { "reference": "master", "type": "git", "url": "" }
}
]
}
],
"require": {
"a/a": "1.*"
},
"minimum-stability": "stable"
}
--LOCK--
{
"packages": [
{ "package": "a/a", "version": "dev-master", "source-reference": "1234" },
{ "package": "a/a", "version": "dev-master", "alias-pretty-version": "1.0.x-dev", "alias-version": "1.0.9999999.9999999-dev" }
],
"packages-dev": null,
"aliases": [],
"minimum-stability": "stable",
"stability-flags": []
}
--INSTALLED--
[
{
"name": "a/a", "version": "dev-master",
"extra": { "branch-alias": { "dev-master": "1.0.x-dev" } },
"source": { "reference": "1234", "type": "git", "url": "" }
}
]
--RUN--
update
--EXPECT-LOCK--
{
"packages": [
{ "package": "a/a", "version": "dev-master", "alias-pretty-version": "1.0.x-dev", "alias-version": "1.0.9999999.9999999-dev" },
{ "package": "a/a", "version": "dev-master", "source-reference": "master" }
],
"packages-dev": null,
"aliases": [],
"minimum-stability": "stable",
"stability-flags": []
}
--EXPECT--
Updating a/a (dev-master 1234) to a/a (dev-master master)

View File

@ -123,7 +123,7 @@ class InstallerTest extends TestCase
/**
* @dataProvider getIntegrationTests
*/
public function testIntegration($file, $message, $condition, $composerConfig, $lock, $installed, $installedDev, $run, $expect)
public function testIntegration($file, $message, $condition, $composerConfig, $lock, $installed, $installedDev, $run, $expectLock, $expect)
{
if ($condition) {
eval('$res = '.$condition.';');
@ -170,6 +170,17 @@ class InstallerTest extends TestCase
->method('exists')
->will($this->returnValue(true));
if ($expectLock) {
$actualLock = array();
$lockJsonMock->expects($this->atLeastOnce())
->method('write')
->will($this->returnCallback(function ($hash, $options) use (&$actualLock) {
// need to do assertion outside of mock for nice phpunit output
// so store value temporarily in reference for later assetion
$actualLock = $hash;
}));
}
$locker = new Locker($lockJsonMock, $repositoryManager, $composer->getInstallationManager(), md5(json_encode($composerConfig)));
$composer->setLocker($locker);
@ -208,6 +219,11 @@ class InstallerTest extends TestCase
fseek($appOutput, 0);
$this->assertEquals(0, $result, $output . stream_get_contents($appOutput));
if ($expectLock) {
unset($actualLock['hash']);
$this->assertEquals($expectLock, $actualLock);
}
$installationManager = $composer->getInstallationManager();
$this->assertSame($expect, implode("\n", $installationManager->getTrace()));
}
@ -233,12 +249,14 @@ class InstallerTest extends TestCase
(?:--INSTALLED--\s*(?P<installed>'.$content.'))?\s*
(?:--INSTALLED:DEV--\s*(?P<installedDev>'.$content.'))?\s*
--RUN--\s*(?P<run>.*?)\s*
(?:--EXPECT-LOCK--\s*(?P<expectLock>'.$content.'))?\s*
--EXPECT--\s*(?P<expect>.*?)\s*
$}xs';
$installed = array();
$installedDev = array();
$lock = array();
$expectLock = array();
if (preg_match($pattern, $test, $match)) {
try {
@ -258,6 +276,9 @@ class InstallerTest extends TestCase
$installedDev = JsonFile::parseJson($match['installedDev']);
}
$run = $match['run'];
if (!empty($match['expectLock'])) {
$expectLock = JsonFile::parseJson($match['expectLock']);
}
$expect = $match['expect'];
} catch (\Exception $e) {
die(sprintf('Test "%s" is not valid: '.$e->getMessage(), str_replace($fixturesDir.'/', '', $file)));
@ -266,7 +287,7 @@ class InstallerTest extends TestCase
die(sprintf('Test "%s" is not valid, did not match the expected format.', str_replace($fixturesDir.'/', '', $file)));
}
$tests[] = array(str_replace($fixturesDir.'/', '', $file), $message, $condition, $composer, $lock, $installed, $installedDev, $run, $expect);
$tests[] = array(str_replace($fixturesDir.'/', '', $file), $message, $condition, $composer, $lock, $installed, $installedDev, $run, $expectLock, $expect);
}
return $tests;

View File

@ -56,9 +56,14 @@ class InstallationManagerMock extends InstallationManager
public function markAliasInstalled(RepositoryInterface $repo, MarkAliasInstalledOperation $operation)
{
$this->installed[] = $operation->getPackage();
$package = $operation->getPackage();
$this->installed[] = $package;
$this->trace[] = (string) $operation;
$repo->addPackage(clone $operation->getPackage());
if (!$repo->hasPackage($package)) {
$repo->addPackage($package);
}
}
public function markAliasUninstalled(RepositoryInterface $repo, MarkAliasUninstalledOperation $operation)