1
0
Fork 0
composer/tests/Composer/Test/Repository/Vcs/PerforceDriverTest.php

147 lines
4.9 KiB
PHP
Raw Normal View History

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>
*/
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
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');
$this->remoteFileSystem = $this->getMockBuilder('Composer\Util\RemoteFilesystem')->disableOriginalConstructor()
->getMock();
2013-07-24 15:06:35 +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
}
public function testInitializeCapturesVariablesFromRepoConfig()
{
2013-08-13 15:54:35 +00:00
$this->setUp();
$repoConfig = array(
'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
);
$driver = new PerforceDriver($repoConfig, $this->io, $this->config, $this->process, $this->remoteFileSystem);
$process = $this->getMock('Composer\Util\ProcessExecutor');
$arguments = array(
array('depot' => 'TEST_DEPOT', 'branch' => 'TEST_BRANCH'),
'port' => 'TEST_PORT',
'path' => $this->testPath,
$process,
true,
'TEST'
);
2013-08-13 15:54:35 +00:00
$perforce = $this->getMock('Composer\Util\Perforce', null, $arguments);
$driver->setPerforce($perforce);
2013-08-13 15:54:35 +00:00
$driver->initialize();
$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
}
public function testInitializeLogsInAndConnectsClient()
{
2013-08-13 15:54:35 +00:00
$this->setUp();
$repoConfig = array(
'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
);
$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))
->method('p4Login')
->with($this->io);
2013-08-13 15:54:35 +00:00
$perforce->expects($this->at(1))
->method('checkStream')
->with($this->equalTo('TEST_DEPOT_CONFIG'));
2013-08-13 15:54:35 +00:00
$perforce->expects($this->at(2))
->method('writeP4ClientSpec');
2013-08-13 15:54:35 +00:00
$perforce->expects($this->at(3))
->method('connectClient');
2013-08-13 15:54:35 +00:00
$driver->setPerforce($perforce);
2013-08-13 15:54:35 +00:00
$driver->initialize();
2013-07-24 15:06:35 +00:00
}
public function testHasComposerFile()
{
$repoConfig = array(
'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
);
$driver = new PerforceDriver($repoConfig, $this->io, $this->config, $this->process, $this->remoteFileSystem);
$process = $this->getMock('Composer\Util\ProcessExecutor');
$arguments = array(
array('depot' => 'TEST_DEPOT', 'branch' => 'TEST_BRANCH'),
'port' => 'TEST_PORT',
'path' => $this->testPath,
$process,
true,
'TEST'
);
2013-08-13 15:54:35 +00:00
$perforce = $this->getMock('Composer\Util\Perforce', array('getComposerInformation'), $arguments);
$perforce->expects($this->at(0))
->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();
$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-16 08:07:10 +00:00
/**
* Test that supports() simply return false.
*
2013-10-16 08:07:10 +00:00
* @covers \Composer\Repository\Vcs\PerforceDriver::supports
*
2013-10-16 08:07:10 +00:00
* @return void
*/
public function testSupportsReturnsFalseNoDeepCheck()
{
$this->expectOutputString('');
$this->assertFalse(PerforceDriver::supports($this->io, $this->config, 'existing.url'));
2013-10-16 08:07:10 +00:00
}
2013-07-24 15:06:35 +00:00
}