|
|
|
@ -15,86 +15,120 @@ namespace Composer\Test\Downloader;
|
|
|
|
|
use Composer\Downloader\PerforceDownloader;
|
|
|
|
|
use Composer\Config;
|
|
|
|
|
use Composer\Repository\VcsRepository;
|
|
|
|
|
use Composer\IO\IOInterface;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @author Matt Whittom <Matt.Whittom@veteransunited.com>
|
|
|
|
|
*/
|
|
|
|
|
class PerforceDownloaderTest extends \PHPUnit_Framework_TestCase
|
|
|
|
|
{
|
|
|
|
|
private $io;
|
|
|
|
|
private $config;
|
|
|
|
|
private $testPath;
|
|
|
|
|
public static $repository;
|
|
|
|
|
|
|
|
|
|
protected $config;
|
|
|
|
|
protected $downloader;
|
|
|
|
|
protected $io;
|
|
|
|
|
protected $package;
|
|
|
|
|
protected $processExecutor;
|
|
|
|
|
protected $repoConfig;
|
|
|
|
|
protected $repository;
|
|
|
|
|
protected $testPath;
|
|
|
|
|
|
|
|
|
|
protected function setUp()
|
|
|
|
|
public function setUp()
|
|
|
|
|
{
|
|
|
|
|
$this->testPath = sys_get_temp_dir() . '/composer-test';
|
|
|
|
|
$this->config = new Config();
|
|
|
|
|
$this->config->merge(
|
|
|
|
|
array(
|
|
|
|
|
'config' => array(
|
|
|
|
|
'home' => $this->testPath,
|
|
|
|
|
),
|
|
|
|
|
)
|
|
|
|
|
);
|
|
|
|
|
$this->io = $this->getMock('Composer\IO\IOInterface');
|
|
|
|
|
$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);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function testInitPerforceGetRepoConfig()
|
|
|
|
|
public 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)
|
|
|
|
|
{
|
|
|
|
|
$downloader = new PerforceDownloader($this->io, $this->config);
|
|
|
|
|
$package = $this->getMock('Composer\Package\PackageInterface');
|
|
|
|
|
$repoConfig = array('url' => 'TEST_URL', 'p4user' => 'TEST_USER');
|
|
|
|
|
$repository = $this->getMock(
|
|
|
|
|
'Composer\Repository\VcsRepository',
|
|
|
|
|
array('getRepoConfig'),
|
|
|
|
|
array($repoConfig, $this->io, $this->config)
|
|
|
|
|
);
|
|
|
|
|
$package->expects($this->at(0))
|
|
|
|
|
->method('getRepository')
|
|
|
|
|
->will($this->returnValue($repository));
|
|
|
|
|
$repository->expects($this->at(0))
|
|
|
|
|
->method('getRepoConfig');
|
|
|
|
|
$path = $this->testPath;
|
|
|
|
|
$downloader->initPerforce($package, $path, 'SOURCE_REF');
|
|
|
|
|
$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');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @depends testInitPerforceInstantiatesANewPerforceObject
|
|
|
|
|
* @depends testInitPerforceDoesNothingIfPerforceAlreadySet
|
|
|
|
|
*/
|
|
|
|
|
public function testDoDownload()
|
|
|
|
|
{
|
|
|
|
|
$downloader = new PerforceDownloader($this->io, $this->config);
|
|
|
|
|
$repoConfig = array('depot' => 'TEST_DEPOT', 'branch' => 'TEST_BRANCH', 'p4user' => 'TEST_USER');
|
|
|
|
|
$port = 'TEST_PORT';
|
|
|
|
|
$path = 'TEST_PATH';
|
|
|
|
|
$process = $this->getmock('Composer\Util\ProcessExecutor');
|
|
|
|
|
$perforce = $this->getMock(
|
|
|
|
|
'Composer\Util\Perforce',
|
|
|
|
|
array('setStream', 'queryP4User', 'writeP4ClientSpec', 'connectClient', 'syncCodeBase'),
|
|
|
|
|
array($repoConfig, $port, $path, $process, true, 'TEST')
|
|
|
|
|
);
|
|
|
|
|
//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.
|
|
|
|
|
$ref = 'SOURCE_REF';
|
|
|
|
|
$label = 'LABEL';
|
|
|
|
|
$perforce->expects($this->at(0))
|
|
|
|
|
->method('setStream')
|
|
|
|
|
->with($this->equalTo($ref));
|
|
|
|
|
$perforce->expects($this->at(1))
|
|
|
|
|
->method('queryP4User')
|
|
|
|
|
->with($this->io);
|
|
|
|
|
$perforce->expects($this->at(2))
|
|
|
|
|
->method('writeP4ClientSpec');
|
|
|
|
|
$perforce->expects($this->at(3))
|
|
|
|
|
->method('connectClient');
|
|
|
|
|
$perforce->expects($this->at(4))
|
|
|
|
|
->method('syncCodeBase')
|
|
|
|
|
->with($this->equalTo($label));
|
|
|
|
|
$downloader->setPerforce($perforce);
|
|
|
|
|
$package = $this->getMock('Composer\Package\PackageInterface');
|
|
|
|
|
$package->expects($this->at(0))
|
|
|
|
|
->method('getSourceReference')
|
|
|
|
|
->will($this->returnValue($ref));
|
|
|
|
|
$package->expects($this->at(1))
|
|
|
|
|
->method('getPrettyVersion')
|
|
|
|
|
->will($this->returnValue($label));
|
|
|
|
|
$path = $this->testPath;
|
|
|
|
|
$downloader->doDownload($package, $path);
|
|
|
|
|
$this->package->expects($this->once())->method('getSourceReference')->will($this->returnValue($ref));
|
|
|
|
|
$this->package->expects($this->once())->method('getPrettyVersion')->will($this->returnValue($label));
|
|
|
|
|
$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('setStream')->with($this->equalTo($ref));
|
|
|
|
|
$perforce->expects($this->at(1))->method('p4Login')->with($this->identicalTo($this->io));
|
|
|
|
|
$perforce->expects($this->at(2))->method('writeP4ClientSpec');
|
|
|
|
|
$perforce->expects($this->at(3))->method('connectClient');
|
|
|
|
|
$perforce->expects($this->at(4))->method('syncCodeBase');
|
|
|
|
|
$perforce->expects($this->at(5))->method('cleanupClientSpec');
|
|
|
|
|
$this->downloader->setPerforce($perforce);
|
|
|
|
|
$this->downloader->doDownload($this->package, $this->testPath);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|