2013-07-24 15:06:35 +00:00
|
|
|
<?php
|
2013-10-11 23:12:02 +00:00
|
|
|
|
2013-07-24 15:06:35 +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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace Composer\Test\Repository\Vcs;
|
|
|
|
|
|
|
|
use Composer\Repository\Vcs\PerforceDriver;
|
|
|
|
use Composer\Util\Filesystem;
|
|
|
|
use Composer\Config;
|
|
|
|
|
2013-08-15 19:45:42 +00:00
|
|
|
/**
|
|
|
|
* @author Matt Whittom <Matt.Whittom@veteransunited.com>
|
|
|
|
*/
|
2013-09-04 14:24:49 +00:00
|
|
|
class PerforceDriverTest extends \PHPUnit_Framework_TestCase
|
|
|
|
{
|
2013-07-24 15:06:35 +00:00
|
|
|
private $config;
|
|
|
|
private $io;
|
2013-08-13 15:54:35 +00:00
|
|
|
private $process;
|
|
|
|
private $remoteFileSystem;
|
|
|
|
private $testPath;
|
2013-07-24 15:06:35 +00:00
|
|
|
|
2013-09-04 14:24:49 +00:00
|
|
|
public function setUp()
|
|
|
|
{
|
2013-08-13 15:54:35 +00:00
|
|
|
$this->testPath = sys_get_temp_dir() . '/composer-test';
|
2013-07-24 15:06:35 +00:00
|
|
|
$this->config = new Config();
|
2013-08-13 15:54:35 +00:00
|
|
|
$this->config->merge(
|
|
|
|
array(
|
|
|
|
'config' => array(
|
|
|
|
'home' => $this->testPath,
|
|
|
|
),
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
|
|
|
$this->io = $this->getMock('Composer\IO\IOInterface');
|
|
|
|
$this->process = $this->getMock('Composer\Util\ProcessExecutor');
|
2013-09-04 14:24:49 +00:00
|
|
|
$this->remoteFileSystem = $this->getMockBuilder('Composer\Util\RemoteFilesystem')->disableOriginalConstructor()
|
|
|
|
->getMock();
|
2013-07-24 15:06:35 +00:00
|
|
|
}
|
|
|
|
|
2013-09-04 14:24:49 +00:00
|
|
|
public function tearDown()
|
|
|
|
{
|
2013-07-24 15:06:35 +00:00
|
|
|
$fs = new Filesystem;
|
2013-08-13 15:54:35 +00:00
|
|
|
$fs->removeDirectory($this->testPath);
|
2013-07-24 15:06:35 +00:00
|
|
|
}
|
|
|
|
|
2013-09-04 14:24:49 +00:00
|
|
|
public function testInitializeCapturesVariablesFromRepoConfig()
|
|
|
|
{
|
2013-08-13 15:54:35 +00:00
|
|
|
$this->setUp();
|
2013-09-09 17:45:50 +00:00
|
|
|
$repoConfig = array(
|
2013-09-04 14:24:49 +00:00
|
|
|
'url' => 'TEST_PERFORCE_URL',
|
|
|
|
'depot' => 'TEST_DEPOT_CONFIG',
|
2013-08-13 15:54:35 +00:00
|
|
|
'branch' => 'TEST_BRANCH_CONFIG'
|
2013-07-24 15:06:35 +00:00
|
|
|
);
|
2013-09-09 17:45:50 +00:00
|
|
|
$driver = new PerforceDriver($repoConfig, $this->io, $this->config, $this->process, $this->remoteFileSystem);
|
2013-08-15 17:16:15 +00:00
|
|
|
$process = $this->getMock('Composer\Util\ProcessExecutor');
|
2013-09-04 14:24:49 +00:00
|
|
|
$arguments = array(
|
|
|
|
array('depot' => 'TEST_DEPOT', 'branch' => 'TEST_BRANCH'),
|
|
|
|
'port' => 'TEST_PORT',
|
|
|
|
'path' => $this->testPath,
|
|
|
|
$process,
|
|
|
|
true,
|
2013-09-09 19:48:24 +00:00
|
|
|
'TEST'
|
2013-09-04 14:24:49 +00:00
|
|
|
);
|
2013-08-13 15:54:35 +00:00
|
|
|
$perforce = $this->getMock('Composer\Util\Perforce', null, $arguments);
|
2013-10-11 23:21:34 +00:00
|
|
|
$driver->setPerforce($perforce);
|
2013-08-13 15:54:35 +00:00
|
|
|
$driver->initialize();
|
2013-09-09 19:48:24 +00:00
|
|
|
$this->assertEquals('TEST_PERFORCE_URL', $driver->getUrl());
|
|
|
|
$this->assertEquals('TEST_DEPOT_CONFIG', $driver->getDepot());
|
|
|
|
$this->assertEquals('TEST_BRANCH_CONFIG', $driver->getBranch());
|
2013-07-24 15:06:35 +00:00
|
|
|
}
|
|
|
|
|
2013-09-04 14:24:49 +00:00
|
|
|
public function testInitializeLogsInAndConnectsClient()
|
|
|
|
{
|
2013-08-13 15:54:35 +00:00
|
|
|
$this->setUp();
|
2013-09-09 17:45:50 +00:00
|
|
|
$repoConfig = array(
|
2013-09-04 14:24:49 +00:00
|
|
|
'url' => 'TEST_PERFORCE_URL',
|
|
|
|
'depot' => 'TEST_DEPOT_CONFIG',
|
2013-08-13 15:54:35 +00:00
|
|
|
'branch' => 'TEST_BRANCH_CONFIG'
|
2013-07-24 15:06:35 +00:00
|
|
|
);
|
2013-09-09 17:45:50 +00:00
|
|
|
$driver = new PerforceDriver($repoConfig, $this->io, $this->config, $this->process, $this->remoteFileSystem);
|
2013-08-13 15:54:35 +00:00
|
|
|
$perforce = $this->getMockBuilder('Composer\Util\Perforce')->disableOriginalConstructor()->getMock();
|
|
|
|
$perforce->expects($this->at(0))
|
2013-10-11 23:21:34 +00:00
|
|
|
->method('p4Login')
|
|
|
|
->with($this->io);
|
2013-08-13 15:54:35 +00:00
|
|
|
$perforce->expects($this->at(1))
|
2013-10-11 23:21:34 +00:00
|
|
|
->method('checkStream')
|
|
|
|
->with($this->equalTo('TEST_DEPOT_CONFIG'));
|
2013-08-13 15:54:35 +00:00
|
|
|
$perforce->expects($this->at(2))
|
2013-10-11 23:21:34 +00:00
|
|
|
->method('writeP4ClientSpec');
|
2013-08-13 15:54:35 +00:00
|
|
|
$perforce->expects($this->at(3))
|
2013-10-11 23:21:34 +00:00
|
|
|
->method('connectClient');
|
2013-08-13 15:54:35 +00:00
|
|
|
|
2013-10-11 23:21:34 +00:00
|
|
|
$driver->setPerforce($perforce);
|
2013-08-13 15:54:35 +00:00
|
|
|
$driver->initialize();
|
2013-07-24 15:06:35 +00:00
|
|
|
}
|
|
|
|
|
2013-09-04 14:24:49 +00:00
|
|
|
public function testHasComposerFile()
|
|
|
|
{
|
2013-09-09 17:45:50 +00:00
|
|
|
$repoConfig = array(
|
2013-09-04 14:24:49 +00:00
|
|
|
'url' => 'TEST_PERFORCE_URL',
|
|
|
|
'depot' => 'TEST_DEPOT_CONFIG',
|
2013-08-13 15:54:35 +00:00
|
|
|
'branch' => 'TEST_BRANCH_CONFIG'
|
2013-07-24 15:06:35 +00:00
|
|
|
);
|
2013-09-09 17:45:50 +00:00
|
|
|
$driver = new PerforceDriver($repoConfig, $this->io, $this->config, $this->process, $this->remoteFileSystem);
|
2013-08-15 17:16:15 +00:00
|
|
|
$process = $this->getMock('Composer\Util\ProcessExecutor');
|
2013-09-04 14:24:49 +00:00
|
|
|
$arguments = array(
|
|
|
|
array('depot' => 'TEST_DEPOT', 'branch' => 'TEST_BRANCH'),
|
|
|
|
'port' => 'TEST_PORT',
|
|
|
|
'path' => $this->testPath,
|
|
|
|
$process,
|
|
|
|
true,
|
2013-09-09 19:48:24 +00:00
|
|
|
'TEST'
|
2013-09-04 14:24:49 +00:00
|
|
|
);
|
2013-08-13 15:54:35 +00:00
|
|
|
$perforce = $this->getMock('Composer\Util\Perforce', array('getComposerInformation'), $arguments);
|
|
|
|
$perforce->expects($this->at(0))
|
2013-10-11 23:21:34 +00:00
|
|
|
->method('getComposerInformation')
|
|
|
|
->with($this->equalTo('//TEST_DEPOT_CONFIG/TEST_IDENTIFIER'))
|
|
|
|
->will($this->returnValue('Some json stuff'));
|
|
|
|
$driver->setPerforce($perforce);
|
2013-08-13 15:54:35 +00:00
|
|
|
$driver->initialize();
|
2013-09-09 19:48:24 +00:00
|
|
|
$identifier = 'TEST_IDENTIFIER';
|
2013-08-13 15:54:35 +00:00
|
|
|
$result = $driver->hasComposerFile($identifier);
|
2013-07-24 15:06:35 +00:00
|
|
|
$this->assertTrue($result);
|
|
|
|
}
|
2013-10-28 19:57:02 +00:00
|
|
|
|
2013-10-16 08:07:10 +00:00
|
|
|
/**
|
|
|
|
* Test that supports() simply return false.
|
2013-10-28 19:57:02 +00:00
|
|
|
*
|
2013-10-16 08:07:10 +00:00
|
|
|
* @covers \Composer\Repository\Vcs\PerforceDriver::supports
|
2013-10-28 19:57:02 +00:00
|
|
|
*
|
2013-10-16 08:07:10 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testSupportsReturnsFalseNoDeepCheck()
|
|
|
|
{
|
|
|
|
$this->expectOutputString('');
|
2013-10-28 19:57:02 +00:00
|
|
|
$this->assertFalse(PerforceDriver::supports($this->io, 'existing.url', $this->config));
|
2013-10-16 08:07:10 +00:00
|
|
|
}
|
2013-07-24 15:06:35 +00:00
|
|
|
}
|