1
0
Fork 0

Update Git/Hg downloaders tests, making sure they never use a live filesystem instance

pull/404/merge
Jordi Boggiano 2012-03-08 00:11:52 +01:00
parent 775c00258d
commit ada9c20db1
4 changed files with 75 additions and 29 deletions

View File

@ -47,7 +47,7 @@ abstract class VcsDownloader implements DownloaderInterface
public function download(PackageInterface $package, $path)
{
if (!$package->getSourceReference()) {
throw new \InvalidArgumentException('The given package is missing reference information');
throw new \InvalidArgumentException('Package '.$package->getPrettyName().' is missing reference information');
}
$this->io->write(" - Package <info>" . $package->getName() . "</info> (<comment>" . $package->getPrettyVersion() . "</comment>)");
@ -62,7 +62,7 @@ abstract class VcsDownloader implements DownloaderInterface
public function update(PackageInterface $initial, PackageInterface $target, $path)
{
if (!$target->getSourceReference()) {
throw new \InvalidArgumentException('The given package is missing reference information');
throw new \InvalidArgumentException('Package '.$target->getPrettyName().' is missing reference information');
}
$this->io->write(" - Package <info>" . $target->getName() . "</info> (<comment>" . $target->getPrettyVersion() . "</comment>)");

View File

@ -16,6 +16,15 @@ use Composer\Downloader\GitDownloader;
class GitDownloaderTest extends \PHPUnit_Framework_TestCase
{
protected function getDownloaderMock($io = null, $executor = null, $filesystem = null)
{
$io = $io ?: $this->getMock('Composer\IO\IOInterface');
$executor = $executor ?: $this->getMock('Composer\Util\ProcessExecutor');
$filesystem = $filesystem ?: $this->getMock('Composer\Util\Filesystem');
return new GitDownloader($io, $executor, $filesystem);
}
/**
* @expectedException \InvalidArgumentException
*/
@ -26,27 +35,60 @@ class GitDownloaderTest extends \PHPUnit_Framework_TestCase
->method('getSourceReference')
->will($this->returnValue(null));
$downloader = new GitDownloader($this->getMock('Composer\IO\IOInterface'));
$downloader = $this->getDownloaderMock();
$downloader->download($packageMock, '/path');
}
public function testDownload()
{
$expectedGitCommand = $this->getCmd('git clone \'https://github.com/l3l0/composer\' \'composerPath\' && cd \'composerPath\' && git checkout \'ref\' && git reset --hard \'ref\'');
$expectedGitCommand = $this->getCmd('git clone \'https://example.com/composer/composer\' \'composerPath\' && cd \'composerPath\' && git checkout \'ref\' && git reset --hard \'ref\'');
$packageMock = $this->getMock('Composer\Package\PackageInterface');
$packageMock->expects($this->any())
->method('getSourceReference')
->will($this->returnValue('ref'));
$packageMock->expects($this->once())
$packageMock->expects($this->any())
->method('getSourceUrl')
->will($this->returnValue('https://github.com/l3l0/composer'));
->will($this->returnValue('https://example.com/composer/composer'));
$processExecutor = $this->getMock('Composer\Util\ProcessExecutor');
$processExecutor->expects($this->once())
->method('execute')
->with($this->equalTo($expectedGitCommand))
->will($this->returnValue(0));
$downloader = new GitDownloader($this->getMock('Composer\IO\IOInterface'), $processExecutor);
$downloader = $this->getDownloaderMock(null, $processExecutor);
$downloader->download($packageMock, 'composerPath');
}
public function testDownloadUsesVariousProtocolsForGithub()
{
$packageMock = $this->getMock('Composer\Package\PackageInterface');
$packageMock->expects($this->any())
->method('getSourceReference')
->will($this->returnValue('ref'));
$packageMock->expects($this->once())
->method('getSourceUrl')
->will($this->returnValue('https://github.com/composer/composer'));
$processExecutor = $this->getMock('Composer\Util\ProcessExecutor');
$expectedGitCommand = $this->getCmd('git clone \'git://github.com/composer/composer\' \'composerPath\' && cd \'composerPath\' && git checkout \'ref\' && git reset --hard \'ref\'');
$processExecutor->expects($this->at(0))
->method('execute')
->with($this->equalTo($expectedGitCommand))
->will($this->returnValue(1));
$expectedGitCommand = $this->getCmd('git clone \'https://github.com/composer/composer\' \'composerPath\' && cd \'composerPath\' && git checkout \'ref\' && git reset --hard \'ref\'');
$processExecutor->expects($this->at(1))
->method('execute')
->with($this->equalTo($expectedGitCommand))
->will($this->returnValue(1));
$expectedGitCommand = $this->getCmd('git clone \'http://github.com/composer/composer\' \'composerPath\' && cd \'composerPath\' && git checkout \'ref\' && git reset --hard \'ref\'');
$processExecutor->expects($this->at(2))
->method('execute')
->with($this->equalTo($expectedGitCommand))
->will($this->returnValue(0));
$downloader = $this->getDownloaderMock(null, $processExecutor);
$downloader->download($packageMock, 'composerPath');
}
@ -55,21 +97,21 @@ class GitDownloaderTest extends \PHPUnit_Framework_TestCase
*/
public function testDownloadThrowsRuntimeExceptionIfGitCommandFails()
{
$expectedGitCommand = $this->getCmd('git clone \'https://github.com/l3l0/composer\' \'composerPath\' && cd \'composerPath\' && git checkout \'ref\' && git reset --hard \'ref\'');
$expectedGitCommand = $this->getCmd('git clone \'https://example.com/composer/composer\' \'composerPath\' && cd \'composerPath\' && git checkout \'ref\' && git reset --hard \'ref\'');
$packageMock = $this->getMock('Composer\Package\PackageInterface');
$packageMock->expects($this->any())
->method('getSourceReference')
->will($this->returnValue('ref'));
$packageMock->expects($this->once())
$packageMock->expects($this->any())
->method('getSourceUrl')
->will($this->returnValue('https://github.com/l3l0/composer'));
->will($this->returnValue('https://example.com/composer/composer'));
$processExecutor = $this->getMock('Composer\Util\ProcessExecutor');
$processExecutor->expects($this->once())
->method('execute')
->with($this->equalTo($expectedGitCommand))
->will($this->returnValue(1));
$downloader = new GitDownloader($this->getMock('Composer\IO\IOInterface'), $processExecutor);
$downloader = $this->getDownloaderMock(null, $processExecutor);
$downloader->download($packageMock, 'composerPath');
}
@ -84,7 +126,7 @@ class GitDownloaderTest extends \PHPUnit_Framework_TestCase
->method('getSourceReference')
->will($this->returnValue(null));
$downloader = new GitDownloader($this->getMock('Composer\IO\IOInterface'));
$downloader = $this->getDownloaderMock();
$downloader->update($initialPackageMock, $sourcePackageMock, '/path');
}
@ -110,7 +152,7 @@ class GitDownloaderTest extends \PHPUnit_Framework_TestCase
->with($this->equalTo($expectedGitUpdateCommand))
->will($this->returnValue(0));
$downloader = new GitDownloader($this->getMock('Composer\IO\IOInterface'), $processExecutor);
$downloader = $this->getDownloaderMock(null, $processExecutor);
$downloader->update($packageMock, $packageMock, 'composerPath');
}
@ -139,7 +181,7 @@ class GitDownloaderTest extends \PHPUnit_Framework_TestCase
->with($this->equalTo($expectedGitUpdateCommand))
->will($this->returnValue(1));
$downloader = new GitDownloader($this->getMock('Composer\IO\IOInterface'), $processExecutor);
$downloader = $this->getDownloaderMock(null, $processExecutor);
$downloader->update($packageMock, $packageMock, 'composerPath');
}
@ -158,13 +200,13 @@ class GitDownloaderTest extends \PHPUnit_Framework_TestCase
->method('removeDirectory')
->with($this->equalTo('composerPath'));
$downloader = new GitDownloader($this->getMock('Composer\IO\IOInterface'), $processExecutor, $filesystem);
$downloader = $this->getDownloaderMock(null, $processExecutor, $filesystem);
$downloader->remove($packageMock, 'composerPath');
}
public function testGetInstallationSource()
{
$downloader = new GitDownloader($this->getMock('Composer\IO\IOInterface'));
$downloader = $this->getDownloaderMock();
$this->assertEquals('source', $downloader->getInstallationSource());
}

View File

@ -16,6 +16,15 @@ use Composer\Downloader\HgDownloader;
class HgDownloaderTest extends \PHPUnit_Framework_TestCase
{
protected function getDownloaderMock($io = null, $executor = null, $filesystem = null)
{
$io = $io ?: $this->getMock('Composer\IO\IOInterface');
$executor = $executor ?: $this->getMock('Composer\Util\ProcessExecutor');
$filesystem = $filesystem ?: $this->getMock('Composer\Util\Filesystem');
return new HgDownloader($io, $executor, $filesystem);
}
/**
* @expectedException \InvalidArgumentException
*/
@ -26,7 +35,7 @@ class HgDownloaderTest extends \PHPUnit_Framework_TestCase
->method('getSourceReference')
->will($this->returnValue(null));
$downloader = new HgDownloader($this->getMock('Composer\IO\IOInterface'));
$downloader = $this->getDownloaderMock();
$downloader->download($packageMock, '/path');
}
@ -45,7 +54,7 @@ class HgDownloaderTest extends \PHPUnit_Framework_TestCase
->method('execute')
->with($this->equalTo($expectedGitCommand));
$downloader = new HgDownloader($this->getMock('Composer\IO\IOInterface'), $processExecutor);
$downloader = $this->getDownloaderMock(null, $processExecutor);
$downloader->download($packageMock, 'composerPath');
}
@ -60,7 +69,7 @@ class HgDownloaderTest extends \PHPUnit_Framework_TestCase
->method('getSourceReference')
->will($this->returnValue(null));
$downloader = new HgDownloader($this->getMock('Composer\IO\IOInterface'));
$downloader = $this->getDownloaderMock();
$downloader->update($initialPackageMock, $sourcePackageMock, '/path');
}
@ -84,7 +93,7 @@ class HgDownloaderTest extends \PHPUnit_Framework_TestCase
->method('execute')
->with($this->equalTo($expectedUpdateCommand));
$downloader = new HgDownloader($this->getMock('Composer\IO\IOInterface'), $processExecutor);
$downloader = $this->getDownloaderMock(null, $processExecutor);
$downloader->update($packageMock, $packageMock, 'composerPath');
}
@ -102,13 +111,13 @@ class HgDownloaderTest extends \PHPUnit_Framework_TestCase
->method('removeDirectory')
->with($this->equalTo('composerPath'));
$downloader = new HgDownloader($this->getMock('Composer\IO\IOInterface'), $processExecutor, $filesystem);
$downloader = $this->getDownloaderMock(null, $processExecutor, $filesystem);
$downloader->remove($packageMock, 'composerPath');
}
public function testGetInstallationSource()
{
$downloader = new HgDownloader($this->getMock('Composer\IO\IOInterface'));
$downloader = $this->getDownloaderMock(null);
$this->assertEquals('source', $downloader->getInstallationSource());
}

View File

@ -49,14 +49,9 @@ class LibraryInstallerTest extends TestCase
protected function tearDown()
{
if (is_dir($this->vendorDir)) {
$this->fs->removeDirectory($this->vendorDir);
}
if (is_dir($this->binDir)) {
$this->fs->removeDirectory($this->binDir);
}
}
public function testInstallerCreationShouldNotCreateVendorDirectory()
{