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