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

135 lines
4.5 KiB
PHP
Raw Normal View History

2013-07-24 15:06:35 +00:00
<?php
/*
* 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;
2013-08-13 15:54:35 +00:00
2013-07-24 15:06:35 +00:00
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->injectPerforce($perforce);
$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->injectPerforce($perforce);
$driver->initialize();
2013-07-24 15:06:35 +00:00
}
public function testHasComposerFile()
{
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', array('getComposerInformation'), $arguments);
$perforce->expects($this->at(0))
->method('getComposerInformation')
->with($this->equalTo('//TEST_DEPOT_CONFIG/TEST_IDENTIFIER'))
->will($this->returnValue('Some json stuff'));
2013-08-13 15:54:35 +00:00
$driver->injectPerforce($perforce);
$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);
}
}