1
0
Fork 0

Fix tests and run it before the push url updater

pull/3205/merge
Jordi Boggiano 2014-10-20 20:16:14 +01:00
parent fb1747624c
commit a309e1d89d
2 changed files with 24 additions and 9 deletions

View File

@ -52,6 +52,10 @@ class GitDownloader extends VcsDownloader
};
$this->gitUtil->runCommand($commandCallable, $url, $path, true);
if ($url !== $package->getSourceUrl()) {
$url = $package->getSourceUrl();
$this->process->execute(sprintf('git remote set-url origin %s', ProcessExecutor::escape($url)), $output, $path);
}
$this->setPushUrl($path, $url);
if ($newRef = $this->updateToCommit($path, $ref, $package->getPrettyVersion(), $package->getReleaseDate())) {
@ -60,10 +64,6 @@ class GitDownloader extends VcsDownloader
}
$package->setSourceReference($newRef);
}
if ($url !== $package->getSourceUrl()) {
$this->process->execute(sprintf('git remote set-url origin %s', $package->getSourceUrl()), $output, $path);
}
}
/**

View File

@ -53,6 +53,9 @@ class GitDownloaderTest extends \PHPUnit_Framework_TestCase
$packageMock->expects($this->any())
->method('getSourceUrls')
->will($this->returnValue(array('https://example.com/composer/composer')));
$packageMock->expects($this->any())
->method('getSourceUrl')
->will($this->returnValue('https://example.com/composer/composer'));
$packageMock->expects($this->any())
->method('getPrettyVersion')
->will($this->returnValue('dev-master'));
@ -91,36 +94,45 @@ class GitDownloaderTest extends \PHPUnit_Framework_TestCase
->will($this->returnValue('ref'));
$packageMock->expects($this->any())
->method('getSourceUrls')
->will($this->returnValue(array('https://github.com/composer/composer')));
->will($this->returnValue(array('https://github.com/mirrors/composer', 'https://github.com/composer/composer')));
$packageMock->expects($this->any())
->method('getSourceUrl')
->will($this->returnValue('https://github.com/composer/composer'));
$packageMock->expects($this->any())
->method('getPrettyVersion')
->will($this->returnValue('1.0.0'));
$processExecutor = $this->getMock('Composer\Util\ProcessExecutor');
$expectedGitCommand = $this->winCompat("git clone --no-checkout 'git://github.com/composer/composer' 'composerPath' && cd 'composerPath' && git remote add composer 'git://github.com/composer/composer' && git fetch composer");
$expectedGitCommand = $this->winCompat("git clone --no-checkout 'git://github.com/mirrors/composer' 'composerPath' && cd 'composerPath' && git remote add composer 'git://github.com/mirrors/composer' && git fetch composer");
$processExecutor->expects($this->at(0))
->method('execute')
->with($this->equalTo($expectedGitCommand))
->will($this->returnValue(1));
$expectedGitCommand = $this->winCompat("git clone --no-checkout 'https://github.com/composer/composer' 'composerPath' && cd 'composerPath' && git remote add composer 'https://github.com/composer/composer' && git fetch composer");
$expectedGitCommand = $this->winCompat("git clone --no-checkout 'https://github.com/mirrors/composer' 'composerPath' && cd 'composerPath' && git remote add composer 'https://github.com/mirrors/composer' && git fetch composer");
$processExecutor->expects($this->at(2))
->method('execute')
->with($this->equalTo($expectedGitCommand))
->will($this->returnValue(0));
$expectedGitCommand = $this->winCompat("git remote set-url --push origin 'git@github.com:composer/composer.git'");
$expectedGitCommand = $this->winCompat("git remote set-url origin 'https://github.com/composer/composer'");
$processExecutor->expects($this->at(3))
->method('execute')
->with($this->equalTo($expectedGitCommand), $this->equalTo(null), $this->equalTo($this->winCompat('composerPath')))
->will($this->returnValue(0));
$expectedGitCommand = $this->winCompat("git remote set-url --push origin 'git@github.com:composer/composer.git'");
$processExecutor->expects($this->at(4))
->method('execute')
->with($this->equalTo($expectedGitCommand), $this->equalTo(null), $this->equalTo($this->winCompat('composerPath')))
->will($this->returnValue(0));
$processExecutor->expects($this->at(5))
->method('execute')
->with($this->equalTo('git branch -r'))
->will($this->returnValue(0));
$processExecutor->expects($this->at(5))
$processExecutor->expects($this->at(6))
->method('execute')
->with($this->equalTo($this->winCompat("git checkout 'ref' && git reset --hard 'ref'")), $this->equalTo(null), $this->equalTo($this->winCompat('composerPath')))
->will($this->returnValue(0));
@ -149,6 +161,9 @@ class GitDownloaderTest extends \PHPUnit_Framework_TestCase
$packageMock->expects($this->any())
->method('getSourceUrls')
->will($this->returnValue(array('https://github.com/composer/composer')));
$packageMock->expects($this->any())
->method('getSourceUrl')
->will($this->returnValue('https://github.com/composer/composer'));
$packageMock->expects($this->any())
->method('getPrettyVersion')
->will($this->returnValue('1.0.0'));