Update Git/Hg downloaders tests, making sure they never use a live filesystem instance
parent
775c00258d
commit
ada9c20db1
|
@ -47,7 +47,7 @@ abstract class VcsDownloader implements DownloaderInterface
|
||||||
public function download(PackageInterface $package, $path)
|
public function download(PackageInterface $package, $path)
|
||||||
{
|
{
|
||||||
if (!$package->getSourceReference()) {
|
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>)");
|
$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)
|
public function update(PackageInterface $initial, PackageInterface $target, $path)
|
||||||
{
|
{
|
||||||
if (!$target->getSourceReference()) {
|
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>)");
|
$this->io->write(" - Package <info>" . $target->getName() . "</info> (<comment>" . $target->getPrettyVersion() . "</comment>)");
|
||||||
|
|
|
@ -16,6 +16,15 @@ use Composer\Downloader\GitDownloader;
|
||||||
|
|
||||||
class GitDownloaderTest extends \PHPUnit_Framework_TestCase
|
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
|
* @expectedException \InvalidArgumentException
|
||||||
*/
|
*/
|
||||||
|
@ -26,27 +35,60 @@ class GitDownloaderTest extends \PHPUnit_Framework_TestCase
|
||||||
->method('getSourceReference')
|
->method('getSourceReference')
|
||||||
->will($this->returnValue(null));
|
->will($this->returnValue(null));
|
||||||
|
|
||||||
$downloader = new GitDownloader($this->getMock('Composer\IO\IOInterface'));
|
$downloader = $this->getDownloaderMock();
|
||||||
$downloader->download($packageMock, '/path');
|
$downloader->download($packageMock, '/path');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testDownload()
|
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 = $this->getMock('Composer\Package\PackageInterface');
|
||||||
$packageMock->expects($this->any())
|
$packageMock->expects($this->any())
|
||||||
->method('getSourceReference')
|
->method('getSourceReference')
|
||||||
->will($this->returnValue('ref'));
|
->will($this->returnValue('ref'));
|
||||||
$packageMock->expects($this->once())
|
$packageMock->expects($this->any())
|
||||||
->method('getSourceUrl')
|
->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 = $this->getMock('Composer\Util\ProcessExecutor');
|
||||||
$processExecutor->expects($this->once())
|
$processExecutor->expects($this->once())
|
||||||
->method('execute')
|
->method('execute')
|
||||||
->with($this->equalTo($expectedGitCommand))
|
->with($this->equalTo($expectedGitCommand))
|
||||||
->will($this->returnValue(0));
|
->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');
|
$downloader->download($packageMock, 'composerPath');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -55,21 +97,21 @@ class GitDownloaderTest extends \PHPUnit_Framework_TestCase
|
||||||
*/
|
*/
|
||||||
public function testDownloadThrowsRuntimeExceptionIfGitCommandFails()
|
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 = $this->getMock('Composer\Package\PackageInterface');
|
||||||
$packageMock->expects($this->any())
|
$packageMock->expects($this->any())
|
||||||
->method('getSourceReference')
|
->method('getSourceReference')
|
||||||
->will($this->returnValue('ref'));
|
->will($this->returnValue('ref'));
|
||||||
$packageMock->expects($this->once())
|
$packageMock->expects($this->any())
|
||||||
->method('getSourceUrl')
|
->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 = $this->getMock('Composer\Util\ProcessExecutor');
|
||||||
$processExecutor->expects($this->once())
|
$processExecutor->expects($this->once())
|
||||||
->method('execute')
|
->method('execute')
|
||||||
->with($this->equalTo($expectedGitCommand))
|
->with($this->equalTo($expectedGitCommand))
|
||||||
->will($this->returnValue(1));
|
->will($this->returnValue(1));
|
||||||
|
|
||||||
$downloader = new GitDownloader($this->getMock('Composer\IO\IOInterface'), $processExecutor);
|
$downloader = $this->getDownloaderMock(null, $processExecutor);
|
||||||
$downloader->download($packageMock, 'composerPath');
|
$downloader->download($packageMock, 'composerPath');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -84,7 +126,7 @@ class GitDownloaderTest extends \PHPUnit_Framework_TestCase
|
||||||
->method('getSourceReference')
|
->method('getSourceReference')
|
||||||
->will($this->returnValue(null));
|
->will($this->returnValue(null));
|
||||||
|
|
||||||
$downloader = new GitDownloader($this->getMock('Composer\IO\IOInterface'));
|
$downloader = $this->getDownloaderMock();
|
||||||
$downloader->update($initialPackageMock, $sourcePackageMock, '/path');
|
$downloader->update($initialPackageMock, $sourcePackageMock, '/path');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -110,7 +152,7 @@ class GitDownloaderTest extends \PHPUnit_Framework_TestCase
|
||||||
->with($this->equalTo($expectedGitUpdateCommand))
|
->with($this->equalTo($expectedGitUpdateCommand))
|
||||||
->will($this->returnValue(0));
|
->will($this->returnValue(0));
|
||||||
|
|
||||||
$downloader = new GitDownloader($this->getMock('Composer\IO\IOInterface'), $processExecutor);
|
$downloader = $this->getDownloaderMock(null, $processExecutor);
|
||||||
$downloader->update($packageMock, $packageMock, 'composerPath');
|
$downloader->update($packageMock, $packageMock, 'composerPath');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -139,7 +181,7 @@ class GitDownloaderTest extends \PHPUnit_Framework_TestCase
|
||||||
->with($this->equalTo($expectedGitUpdateCommand))
|
->with($this->equalTo($expectedGitUpdateCommand))
|
||||||
->will($this->returnValue(1));
|
->will($this->returnValue(1));
|
||||||
|
|
||||||
$downloader = new GitDownloader($this->getMock('Composer\IO\IOInterface'), $processExecutor);
|
$downloader = $this->getDownloaderMock(null, $processExecutor);
|
||||||
$downloader->update($packageMock, $packageMock, 'composerPath');
|
$downloader->update($packageMock, $packageMock, 'composerPath');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -158,13 +200,13 @@ class GitDownloaderTest extends \PHPUnit_Framework_TestCase
|
||||||
->method('removeDirectory')
|
->method('removeDirectory')
|
||||||
->with($this->equalTo('composerPath'));
|
->with($this->equalTo('composerPath'));
|
||||||
|
|
||||||
$downloader = new GitDownloader($this->getMock('Composer\IO\IOInterface'), $processExecutor, $filesystem);
|
$downloader = $this->getDownloaderMock(null, $processExecutor, $filesystem);
|
||||||
$downloader->remove($packageMock, 'composerPath');
|
$downloader->remove($packageMock, 'composerPath');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testGetInstallationSource()
|
public function testGetInstallationSource()
|
||||||
{
|
{
|
||||||
$downloader = new GitDownloader($this->getMock('Composer\IO\IOInterface'));
|
$downloader = $this->getDownloaderMock();
|
||||||
|
|
||||||
$this->assertEquals('source', $downloader->getInstallationSource());
|
$this->assertEquals('source', $downloader->getInstallationSource());
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,6 +16,15 @@ use Composer\Downloader\HgDownloader;
|
||||||
|
|
||||||
class HgDownloaderTest extends \PHPUnit_Framework_TestCase
|
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
|
* @expectedException \InvalidArgumentException
|
||||||
*/
|
*/
|
||||||
|
@ -26,7 +35,7 @@ class HgDownloaderTest extends \PHPUnit_Framework_TestCase
|
||||||
->method('getSourceReference')
|
->method('getSourceReference')
|
||||||
->will($this->returnValue(null));
|
->will($this->returnValue(null));
|
||||||
|
|
||||||
$downloader = new HgDownloader($this->getMock('Composer\IO\IOInterface'));
|
$downloader = $this->getDownloaderMock();
|
||||||
$downloader->download($packageMock, '/path');
|
$downloader->download($packageMock, '/path');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -45,7 +54,7 @@ class HgDownloaderTest extends \PHPUnit_Framework_TestCase
|
||||||
->method('execute')
|
->method('execute')
|
||||||
->with($this->equalTo($expectedGitCommand));
|
->with($this->equalTo($expectedGitCommand));
|
||||||
|
|
||||||
$downloader = new HgDownloader($this->getMock('Composer\IO\IOInterface'), $processExecutor);
|
$downloader = $this->getDownloaderMock(null, $processExecutor);
|
||||||
$downloader->download($packageMock, 'composerPath');
|
$downloader->download($packageMock, 'composerPath');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -60,7 +69,7 @@ class HgDownloaderTest extends \PHPUnit_Framework_TestCase
|
||||||
->method('getSourceReference')
|
->method('getSourceReference')
|
||||||
->will($this->returnValue(null));
|
->will($this->returnValue(null));
|
||||||
|
|
||||||
$downloader = new HgDownloader($this->getMock('Composer\IO\IOInterface'));
|
$downloader = $this->getDownloaderMock();
|
||||||
$downloader->update($initialPackageMock, $sourcePackageMock, '/path');
|
$downloader->update($initialPackageMock, $sourcePackageMock, '/path');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -84,7 +93,7 @@ class HgDownloaderTest extends \PHPUnit_Framework_TestCase
|
||||||
->method('execute')
|
->method('execute')
|
||||||
->with($this->equalTo($expectedUpdateCommand));
|
->with($this->equalTo($expectedUpdateCommand));
|
||||||
|
|
||||||
$downloader = new HgDownloader($this->getMock('Composer\IO\IOInterface'), $processExecutor);
|
$downloader = $this->getDownloaderMock(null, $processExecutor);
|
||||||
$downloader->update($packageMock, $packageMock, 'composerPath');
|
$downloader->update($packageMock, $packageMock, 'composerPath');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -102,13 +111,13 @@ class HgDownloaderTest extends \PHPUnit_Framework_TestCase
|
||||||
->method('removeDirectory')
|
->method('removeDirectory')
|
||||||
->with($this->equalTo('composerPath'));
|
->with($this->equalTo('composerPath'));
|
||||||
|
|
||||||
$downloader = new HgDownloader($this->getMock('Composer\IO\IOInterface'), $processExecutor, $filesystem);
|
$downloader = $this->getDownloaderMock(null, $processExecutor, $filesystem);
|
||||||
$downloader->remove($packageMock, 'composerPath');
|
$downloader->remove($packageMock, 'composerPath');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testGetInstallationSource()
|
public function testGetInstallationSource()
|
||||||
{
|
{
|
||||||
$downloader = new HgDownloader($this->getMock('Composer\IO\IOInterface'));
|
$downloader = $this->getDownloaderMock(null);
|
||||||
|
|
||||||
$this->assertEquals('source', $downloader->getInstallationSource());
|
$this->assertEquals('source', $downloader->getInstallationSource());
|
||||||
}
|
}
|
||||||
|
|
|
@ -49,14 +49,9 @@ class LibraryInstallerTest extends TestCase
|
||||||
|
|
||||||
protected function tearDown()
|
protected function tearDown()
|
||||||
{
|
{
|
||||||
if (is_dir($this->vendorDir)) {
|
|
||||||
$this->fs->removeDirectory($this->vendorDir);
|
$this->fs->removeDirectory($this->vendorDir);
|
||||||
}
|
|
||||||
|
|
||||||
if (is_dir($this->binDir)) {
|
|
||||||
$this->fs->removeDirectory($this->binDir);
|
$this->fs->removeDirectory($this->binDir);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
public function testInstallerCreationShouldNotCreateVendorDirectory()
|
public function testInstallerCreationShouldNotCreateVendorDirectory()
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue