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;
|
|
|
|
|
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
|
|
|
|
{
|
2013-08-09 19:24:58 +00:00
|
|
|
private $io;
|
|
|
|
private $config;
|
|
|
|
private $testPath;
|
|
|
|
public static $repository;
|
|
|
|
|
2013-09-06 17:31:04 +00:00
|
|
|
protected function setUp()
|
2013-09-04 14:24:49 +00:00
|
|
|
{
|
2013-08-09 19:24:58 +00:00
|
|
|
$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');
|
|
|
|
}
|
|
|
|
|
2013-09-04 14:24:49 +00:00
|
|
|
public function testDoDownloadGetRepoConfig()
|
|
|
|
{
|
2013-08-09 19:24:58 +00:00
|
|
|
$downloader = new PerforceDownloader($this->io, $this->config);
|
2013-09-04 14:24:49 +00:00
|
|
|
$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)
|
|
|
|
);
|
2013-08-09 19:24:58 +00:00
|
|
|
$package->expects($this->at(0))
|
2013-09-04 14:24:49 +00:00
|
|
|
->method('getSourceReference')
|
2013-09-09 19:48:24 +00:00
|
|
|
->will($this->returnValue('SOURCE_REF'));
|
2013-08-09 19:24:58 +00:00
|
|
|
$package->expects($this->at(1))
|
2013-09-04 14:24:49 +00:00
|
|
|
->method('getPrettyVersion')
|
2013-09-09 19:48:24 +00:00
|
|
|
->will($this->returnValue('100'));
|
2013-08-09 19:24:58 +00:00
|
|
|
$package->expects($this->at(2))
|
2013-09-04 14:24:49 +00:00
|
|
|
->method('getRepository')
|
|
|
|
->will($this->returnValue($repository));
|
2013-08-09 19:24:58 +00:00
|
|
|
$repository->expects($this->at(0))
|
2013-09-04 14:24:49 +00:00
|
|
|
->method('getRepoConfig');
|
2013-08-09 19:24:58 +00:00
|
|
|
$path = $this->testPath;
|
|
|
|
$downloader->doDownload($package, $path);
|
|
|
|
}
|
|
|
|
|
2013-09-04 14:24:49 +00:00
|
|
|
public function testDoDownload()
|
|
|
|
{
|
2013-08-09 19:24:58 +00:00
|
|
|
$downloader = new PerforceDownloader($this->io, $this->config);
|
2013-09-09 19:48:24 +00:00
|
|
|
$repoConfig = array('depot' => 'TEST_DEPOT', 'branch' => 'TEST_BRANCH', 'p4user' => 'TEST_USER');
|
|
|
|
$port = 'TEST_PORT';
|
|
|
|
$path = 'TEST_PATH';
|
2013-08-15 17:16:15 +00:00
|
|
|
$process = $this->getmock('Composer\Util\ProcessExecutor');
|
2013-09-04 14:24:49 +00:00
|
|
|
$perforce = $this->getMock(
|
|
|
|
'Composer\Util\Perforce',
|
|
|
|
array('setStream', 'queryP4User', 'writeP4ClientSpec', 'connectClient', 'syncCodeBase'),
|
2013-09-09 19:48:24 +00:00
|
|
|
array($repoConfig, $port, $path, $process, true, 'TEST')
|
2013-09-04 14:24:49 +00:00
|
|
|
);
|
2013-09-09 19:48:24 +00:00
|
|
|
$ref = 'SOURCE_REF';
|
|
|
|
$label = 'LABEL';
|
2013-08-09 19:24:58 +00:00
|
|
|
$perforce->expects($this->at(0))
|
2013-09-04 14:24:49 +00:00
|
|
|
->method('setStream')
|
|
|
|
->with($this->equalTo($ref));
|
2013-08-09 19:24:58 +00:00
|
|
|
$perforce->expects($this->at(1))
|
2013-09-04 14:24:49 +00:00
|
|
|
->method('queryP4User')
|
|
|
|
->with($this->io);
|
2013-08-09 19:24:58 +00:00
|
|
|
$perforce->expects($this->at(2))
|
2013-09-04 14:24:49 +00:00
|
|
|
->method('writeP4ClientSpec');
|
2013-08-09 19:24:58 +00:00
|
|
|
$perforce->expects($this->at(3))
|
2013-09-04 14:24:49 +00:00
|
|
|
->method('connectClient');
|
2013-08-09 19:24:58 +00:00
|
|
|
$perforce->expects($this->at(4))
|
2013-09-04 14:24:49 +00:00
|
|
|
->method('syncCodeBase')
|
|
|
|
->with($this->equalTo($label));
|
2013-10-11 23:21:34 +00:00
|
|
|
$downloader->setPerforce($perforce);
|
2013-09-04 14:24:49 +00:00
|
|
|
$package = $this->getMock('Composer\Package\PackageInterface');
|
2013-08-09 19:24:58 +00:00
|
|
|
$package->expects($this->at(0))
|
2013-09-04 14:24:49 +00:00
|
|
|
->method('getSourceReference')
|
|
|
|
->will($this->returnValue($ref));
|
2013-08-09 19:24:58 +00:00
|
|
|
$package->expects($this->at(1))
|
2013-09-04 14:24:49 +00:00
|
|
|
->method('getPrettyVersion')
|
|
|
|
->will($this->returnValue($label));
|
2013-08-09 19:24:58 +00:00
|
|
|
$path = $this->testPath;
|
|
|
|
$downloader->doDownload($package, $path);
|
|
|
|
}
|
|
|
|
}
|