123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124 |
- <?php
- /*
- * This file is part of Composer.
- *
- * (c) Nils Adermann <naderman@naderman.de>
- * Jordi Boggiano <j.boggiano@seld.be>
- *
- * For the full copyright and license information, please view the LICENSE
- * file that was distributed with this source code.
- */
- namespace Composer\Test\Downloader;
- use Composer\Downloader\GitDownloader;
- class GitDownloaderTest extends \PHPUnit_Framework_TestCase
- {
- /**
- * @expectedException \InvalidArgumentException
- */
- public function testDownloadForPackageWithoutSourceReference()
- {
- $packageMock = $this->getMock('Composer\Package\PackageInterface');
- $packageMock->expects($this->once())
- ->method('getSourceReference')
- ->will($this->returnValue(null));
- $downloader = new GitDownloader($this->getMock('Composer\IO\IOInterface'));
- $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\'');
- $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/l3l0/composer'));
- $processExecutor = $this->getMock('Composer\Util\ProcessExecutor');
- $processExecutor->expects($this->once())
- ->method('execute')
- ->with($this->equalTo($expectedGitCommand));
- $downloader = new GitDownloader($this->getMock('Composer\IO\IOInterface'), $processExecutor);
- $downloader->download($packageMock, 'composerPath');
- }
- /**
- * @expectedException \InvalidArgumentException
- */
- public function testUpdateforPackageWithoutSourceReference()
- {
- $initialPackageMock = $this->getMock('Composer\Package\PackageInterface');
- $sourcePackageMock = $this->getMock('Composer\Package\PackageInterface');
- $sourcePackageMock->expects($this->once())
- ->method('getSourceReference')
- ->will($this->returnValue(null));
- $downloader = new GitDownloader($this->getMock('Composer\IO\IOInterface'));
- $downloader->update($initialPackageMock, $sourcePackageMock, '/path');
- }
- public function testUpdate()
- {
- $expectedGitUpdateCommand = $this->getCmd('cd \'composerPath\' && git fetch && git checkout \'ref\' && git reset --hard \'ref\'');
- $expectedGitResetCommand = $this->getCmd('cd \'composerPath\' && git status --porcelain');
- $packageMock = $this->getMock('Composer\Package\PackageInterface');
- $packageMock->expects($this->any())
- ->method('getSourceReference')
- ->will($this->returnValue('ref'));
- $packageMock->expects($this->any())
- ->method('getSourceUrl')
- ->will($this->returnValue('https://github.com/l3l0/composer'));
- $processExecutor = $this->getMock('Composer\Util\ProcessExecutor');
- $processExecutor->expects($this->at(0))
- ->method('execute')
- ->with($this->equalTo($expectedGitResetCommand));
- $processExecutor->expects($this->at(1))
- ->method('execute')
- ->with($this->equalTo($expectedGitUpdateCommand));
- $downloader = new GitDownloader($this->getMock('Composer\IO\IOInterface'), $processExecutor);
- $downloader->update($packageMock, $packageMock, 'composerPath');
- }
- public function testRemove()
- {
- $expectedGitResetCommand = $this->getCmd('cd \'composerPath\' && git status --porcelain');
- $packageMock = $this->getMock('Composer\Package\PackageInterface');
- $processExecutor = $this->getMock('Composer\Util\ProcessExecutor');
- $processExecutor->expects($this->any())
- ->method('execute')
- ->with($this->equalTo($expectedGitResetCommand));
- $filesystem = $this->getMock('Composer\Util\Filesystem');
- $filesystem->expects($this->any())
- ->method('removeDirectory')
- ->with($this->equalTo('composerPath'));
- $downloader = new GitDownloader($this->getMock('Composer\IO\IOInterface'), $processExecutor, $filesystem);
- $downloader->remove($packageMock, 'composerPath');
- }
- public function testGetInstallationSource()
- {
- $downloader = new GitDownloader($this->getMock('Composer\IO\IOInterface'));
- $this->assertEquals('source', $downloader->getInstallationSource());
- }
- private function getCmd($cmd)
- {
- if (defined('PHP_WINDOWS_VERSION_BUILD')) {
- return strtr($cmd, "'", '"');
- }
- return $cmd;
- }
- }
|