1
0
Fork 0
composer/tests/Composer/Test/Downloader/PerforceDownloaderTest.php

109 lines
3.5 KiB
PHP
Raw Normal View History

2013-08-09 19:24:58 +00:00
<?php
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
*/
2013-08-15 19:45:42 +00:00
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>
*/
class PerforceDownloaderTest extends \PHPUnit_Framework_TestCase
{
2013-08-09 19:24:58 +00:00
private $io;
private $config;
private $testPath;
public static $repository;
protected function setUp()
{
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');
}
public function testDoDownloadGetRepoConfig()
{
2013-08-09 19:24:58 +00:00
$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)
);
2013-08-09 19:24:58 +00:00
$package->expects($this->at(0))
->method('getSourceReference')
->will($this->returnValue("SOURCE_REF"));
2013-08-09 19:24:58 +00:00
$package->expects($this->at(1))
->method('getPrettyVersion')
->will($this->returnValue("100"));
2013-08-09 19:24:58 +00:00
$package->expects($this->at(2))
->method('getRepository')
->will($this->returnValue($repository));
2013-08-09 19:24:58 +00:00
$repository->expects($this->at(0))
->method('getRepoConfig');
2013-08-09 19:24:58 +00:00
$path = $this->testPath;
$downloader->doDownload($package, $path);
}
public function testDoDownload()
{
2013-08-09 19:24:58 +00:00
$downloader = new PerforceDownloader($this->io, $this->config);
$repoConfig = array("depot" => "TEST_DEPOT", "branch" => "TEST_BRANCH", "p4user" => "TEST_USER");
2013-08-09 19:24:58 +00:00
$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")
);
2013-08-09 19:24:58 +00:00
$ref = "SOURCE_REF";
$label = "LABEL";
$perforce->expects($this->at(0))
->method('setStream')
->with($this->equalTo($ref));
2013-08-09 19:24:58 +00:00
$perforce->expects($this->at(1))
->method('queryP4User')
->with($this->io);
2013-08-09 19:24:58 +00:00
$perforce->expects($this->at(2))
->method('writeP4ClientSpec');
2013-08-09 19:24:58 +00:00
$perforce->expects($this->at(3))
->method('connectClient');
2013-08-09 19:24:58 +00:00
$perforce->expects($this->at(4))
->method('syncCodeBase')
->with($this->equalTo($label));
2013-08-09 19:24:58 +00:00
$downloader->injectPerforce($perforce);
$package = $this->getMock('Composer\Package\PackageInterface');
2013-08-09 19:24:58 +00:00
$package->expects($this->at(0))
->method('getSourceReference')
->will($this->returnValue($ref));
2013-08-09 19:24:58 +00:00
$package->expects($this->at(1))
->method('getPrettyVersion')
->will($this->returnValue($label));
2013-08-09 19:24:58 +00:00
$path = $this->testPath;
$downloader->doDownload($package, $path);
}
}