123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158 |
- <?php
- namespace Composer\Test\Downloader;
- use Composer\Downloader\PerforceDownloader;
- use Composer\Config;
- use Composer\Repository\VcsRepository;
- use Composer\IO\IOInterface;
- class PerforceDownloaderTest extends \PHPUnit_Framework_TestCase
- {
-
- protected $config;
- protected $downloader;
- protected $io;
- protected $package;
- protected $processExecutor;
- protected $repoConfig;
- protected $repository;
- protected $testPath;
- protected function setUp()
- {
- $this->testPath = sys_get_temp_dir() . '/composer-test';
- $this->repoConfig = $this->getRepoConfig();
- $this->config = $this->getConfig();
- $this->io = $this->getMockIoInterface();
- $this->processExecutor = $this->getMockProcessExecutor();
- $this->repository = $this->getMockRepository($this->repoConfig, $this->io, $this->config);
- $this->package = $this->getMockPackageInterface($this->repository);
- $this->downloader = new PerforceDownloader($this->io, $this->config, $this->processExecutor);
- }
- protected function tearDown()
- {
- $this->downloader = null;
- $this->package = null;
- $this->repository = null;
- $this->io = null;
- $this->config = null;
- $this->repoConfig = null;
- $this->testPath = null;
- }
- protected function getMockProcessExecutor()
- {
- return $this->getMock('Composer\Util\ProcessExecutor');
- }
- protected function getConfig()
- {
- $config = new Config();
- $settings = array('config' => array('home' => $this->testPath));
- $config->merge($settings);
- return $config;
- }
- protected function getMockIoInterface()
- {
- return $this->getMock('Composer\IO\IOInterface');
- }
- protected function getMockPackageInterface(VcsRepository $repository)
- {
- $package = $this->getMock('Composer\Package\PackageInterface');
- $package->expects($this->any())->method('getRepository')->will($this->returnValue($repository));
- return $package;
- }
- protected function getRepoConfig()
- {
- return array('url' => 'TEST_URL', 'p4user' => 'TEST_USER');
- }
- protected function getMockRepository(array $repoConfig, IOInterface $io, Config $config)
- {
- $class = 'Composer\Repository\VcsRepository';
- $methods = array('getRepoConfig');
- $args = array($repoConfig, $io, $config);
- $repository = $this->getMock($class, $methods, $args);
- $repository->expects($this->any())->method('getRepoConfig')->will($this->returnValue($repoConfig));
- return $repository;
- }
- public function testInitPerforceInstantiatesANewPerforceObject()
- {
- $this->downloader->initPerforce($this->package, $this->testPath, 'SOURCE_REF');
- }
- public function testInitPerforceDoesNothingIfPerforceAlreadySet()
- {
- $perforce = $this->getMockBuilder('Composer\Util\Perforce')->disableOriginalConstructor()->getMock();
- $this->downloader->setPerforce($perforce);
- $this->repository->expects($this->never())->method('getRepoConfig');
- $this->downloader->initPerforce($this->package, $this->testPath, 'SOURCE_REF');
- }
-
- public function testDoDownloadWithTag()
- {
-
- $ref = 'SOURCE_REF@123';
- $label = 123;
- $this->package->expects($this->once())->method('getSourceReference')->will($this->returnValue($ref));
- $this->io->expects($this->once())->method('write')->with($this->stringContains('Cloning '.$ref));
- $perforceMethods = array('setStream', 'p4Login', 'writeP4ClientSpec', 'connectClient', 'syncCodeBase', 'cleanupClientSpec');
- $perforce = $this->getMockBuilder('Composer\Util\Perforce', $perforceMethods)->disableOriginalConstructor()->getMock();
- $perforce->expects($this->at(0))->method('initializePath')->with($this->equalTo($this->testPath));
- $perforce->expects($this->at(1))->method('setStream')->with($this->equalTo($ref));
- $perforce->expects($this->at(2))->method('p4Login')->with($this->identicalTo($this->io));
- $perforce->expects($this->at(3))->method('writeP4ClientSpec');
- $perforce->expects($this->at(4))->method('connectClient');
- $perforce->expects($this->at(5))->method('syncCodeBase')->with($label);
- $perforce->expects($this->at(6))->method('cleanupClientSpec');
- $this->downloader->setPerforce($perforce);
- $this->downloader->doDownload($this->package, $this->testPath);
- }
-
- public function testDoDownloadWithNoTag()
- {
- $ref = 'SOURCE_REF';
- $label = null;
- $this->package->expects($this->once())->method('getSourceReference')->will($this->returnValue($ref));
- $this->io->expects($this->once())->method('write')->with($this->stringContains('Cloning '.$ref));
- $perforceMethods = array('setStream', 'p4Login', 'writeP4ClientSpec', 'connectClient', 'syncCodeBase', 'cleanupClientSpec');
- $perforce = $this->getMockBuilder('Composer\Util\Perforce', $perforceMethods)->disableOriginalConstructor()->getMock();
- $perforce->expects($this->at(0))->method('initializePath')->with($this->equalTo($this->testPath));
- $perforce->expects($this->at(1))->method('setStream')->with($this->equalTo($ref));
- $perforce->expects($this->at(2))->method('p4Login')->with($this->identicalTo($this->io));
- $perforce->expects($this->at(3))->method('writeP4ClientSpec');
- $perforce->expects($this->at(4))->method('connectClient');
- $perforce->expects($this->at(5))->method('syncCodeBase')->with($label);
- $perforce->expects($this->at(6))->method('cleanupClientSpec');
- $this->downloader->setPerforce($perforce);
- $this->downloader->doDownload($this->package, $this->testPath);
- }
- }
|