2013-08-09 19:24:58 +00:00
|
|
|
<?php
|
2013-10-11 23:12:02 +00:00
|
|
|
|
2013-08-15 19:45:42 +00:00
|
|
|
/*
|
|
|
|
* 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.
|
2013-08-09 19:24:58 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
namespace Composer\Test\Downloader;
|
|
|
|
|
|
|
|
use Composer\Downloader\PerforceDownloader;
|
|
|
|
use Composer\Config;
|
|
|
|
use Composer\Repository\VcsRepository;
|
2014-03-14 19:45:31 +00:00
|
|
|
use Composer\IO\IOInterface;
|
2015-12-14 14:35:27 +00:00
|
|
|
use Composer\Util\Filesystem;
|
2013-08-09 19:24:58 +00:00
|
|
|
|
2013-08-15 19:45:42 +00:00
|
|
|
/**
|
|
|
|
* @author Matt Whittom <Matt.Whittom@veteransunited.com>
|
|
|
|
*/
|
2013-09-04 14:24:49 +00:00
|
|
|
class PerforceDownloaderTest extends \PHPUnit_Framework_TestCase
|
|
|
|
{
|
2014-03-14 19:45:31 +00:00
|
|
|
protected $config;
|
|
|
|
protected $downloader;
|
|
|
|
protected $io;
|
|
|
|
protected $package;
|
|
|
|
protected $processExecutor;
|
|
|
|
protected $repoConfig;
|
|
|
|
protected $repository;
|
|
|
|
protected $testPath;
|
2015-12-14 14:35:27 +00:00
|
|
|
protected $fs;
|
2013-08-09 19:24:58 +00:00
|
|
|
|
2014-03-25 13:30:44 +00:00
|
|
|
protected function setUp()
|
2013-09-04 14:24:49 +00:00
|
|
|
{
|
2015-12-14 14:35:27 +00:00
|
|
|
$this->fs = new Filesystem;
|
2014-03-14 19:45:31 +00:00
|
|
|
$this->testPath = sys_get_temp_dir() . '/composer-test';
|
2015-12-14 14:35:27 +00:00
|
|
|
$this->fs->ensureDirectoryExists($this->testPath);
|
2014-03-14 19:45:31 +00:00
|
|
|
$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);
|
2013-08-09 19:24:58 +00:00
|
|
|
}
|
|
|
|
|
2014-03-25 13:30:44 +00:00
|
|
|
protected function tearDown()
|
2014-03-14 19:45:31 +00:00
|
|
|
{
|
|
|
|
$this->downloader = null;
|
|
|
|
$this->package = null;
|
|
|
|
$this->repository = null;
|
|
|
|
$this->io = null;
|
|
|
|
$this->config = null;
|
|
|
|
$this->repoConfig = null;
|
2015-12-14 14:35:27 +00:00
|
|
|
if (is_dir($this->testPath)) {
|
|
|
|
$this->fs->removeDirectory($this->testPath);
|
|
|
|
}
|
2014-03-14 19:45:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
2014-06-10 14:02:44 +00:00
|
|
|
|
2014-03-14 19:45:31 +00:00
|
|
|
return $config;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function getMockIoInterface()
|
|
|
|
{
|
|
|
|
return $this->getMock('Composer\IO\IOInterface');
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function getMockPackageInterface(VcsRepository $repository)
|
2013-09-04 14:24:49 +00:00
|
|
|
{
|
|
|
|
$package = $this->getMock('Composer\Package\PackageInterface');
|
2014-03-14 19:45:31 +00:00
|
|
|
$package->expects($this->any())->method('getRepository')->will($this->returnValue($repository));
|
2014-06-10 14:02:44 +00:00
|
|
|
|
2014-03-14 19:45:31 +00:00
|
|
|
return $package;
|
2013-08-09 19:24:58 +00:00
|
|
|
}
|
|
|
|
|
2014-03-14 19:45:31 +00:00
|
|
|
protected function getRepoConfig()
|
|
|
|
{
|
2013-10-19 15:55:30 +00:00
|
|
|
return array('url' => 'TEST_URL', 'p4user' => 'TEST_USER');
|
2014-03-14 19:45:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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));
|
2014-06-10 14:02:44 +00:00
|
|
|
|
2014-03-14 19:45:31 +00:00
|
|
|
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');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @depends testInitPerforceInstantiatesANewPerforceObject
|
|
|
|
* @depends testInitPerforceDoesNothingIfPerforceAlreadySet
|
|
|
|
*/
|
2014-03-24 20:19:35 +00:00
|
|
|
public function testDoDownloadWithTag()
|
2013-09-04 14:24:49 +00:00
|
|
|
{
|
2014-03-14 19:45:31 +00:00
|
|
|
//I really don't like this test but the logic of each Perforce method is tested in the Perforce class. Really I am just enforcing workflow.
|
2014-03-24 20:19:35 +00:00
|
|
|
$ref = 'SOURCE_REF@123';
|
|
|
|
$label = 123;
|
|
|
|
$this->package->expects($this->once())->method('getSourceReference')->will($this->returnValue($ref));
|
2015-02-06 12:52:44 +00:00
|
|
|
$this->io->expects($this->once())->method('writeError')->with($this->stringContains('Cloning '.$ref));
|
2014-03-24 20:19:35 +00:00
|
|
|
$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);
|
2013-10-19 15:55:30 +00:00
|
|
|
$this->downloader->doDownload($this->package, $this->testPath, 'url');
|
2014-03-24 20:19:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @depends testInitPerforceInstantiatesANewPerforceObject
|
|
|
|
* @depends testInitPerforceDoesNothingIfPerforceAlreadySet
|
|
|
|
*/
|
|
|
|
public function testDoDownloadWithNoTag()
|
|
|
|
{
|
2013-09-09 19:48:24 +00:00
|
|
|
$ref = 'SOURCE_REF';
|
2014-03-24 20:19:35 +00:00
|
|
|
$label = null;
|
2014-03-14 19:45:31 +00:00
|
|
|
$this->package->expects($this->once())->method('getSourceReference')->will($this->returnValue($ref));
|
2015-02-06 12:52:44 +00:00
|
|
|
$this->io->expects($this->once())->method('writeError')->with($this->stringContains('Cloning '.$ref));
|
2014-03-14 19:45:31 +00:00
|
|
|
$perforceMethods = array('setStream', 'p4Login', 'writeP4ClientSpec', 'connectClient', 'syncCodeBase', 'cleanupClientSpec');
|
|
|
|
$perforce = $this->getMockBuilder('Composer\Util\Perforce', $perforceMethods)->disableOriginalConstructor()->getMock();
|
2014-03-17 21:06:19 +00:00
|
|
|
$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');
|
2014-03-24 20:19:35 +00:00
|
|
|
$perforce->expects($this->at(5))->method('syncCodeBase')->with($label);
|
2014-03-17 21:06:19 +00:00
|
|
|
$perforce->expects($this->at(6))->method('cleanupClientSpec');
|
2014-03-14 19:45:31 +00:00
|
|
|
$this->downloader->setPerforce($perforce);
|
2013-10-19 15:55:30 +00:00
|
|
|
$this->downloader->doDownload($this->package, $this->testPath, 'url');
|
2013-08-09 19:24:58 +00:00
|
|
|
}
|
|
|
|
}
|