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

118 lines
4.2 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>
*
* Contributor: matt-whittom
* Date: 7/17/13
*
* 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-13 15:54:35 +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-08-13 15:54:35 +00:00
public function setUp() {
$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
}
2013-08-13 15:54: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
}
2013-08-13 15:54:35 +00:00
//Test:
//hasComposerFile
2013-07-24 15:06:35 +00:00
2013-08-13 15:54:35 +00:00
public function testInitializeCapturesVariablesFromRepoConfig() {
$this->setUp();
2013-07-24 15:06:35 +00:00
$repo_config = array(
2013-08-13 15:54:35 +00:00
'url' => 'TEST_PERFORCE_URL',
'depot' => 'TEST_DEPOT_CONFIG',
'branch' => 'TEST_BRANCH_CONFIG'
2013-07-24 15:06:35 +00:00
);
2013-08-13 15:54:35 +00:00
$driver = new TestingPerforceDriver($repo_config, $this->io, $this->config, $this->process, $this->remoteFileSystem);
$arguments = array(array('depot'=>'TEST_DEPOT', 'branch'=>'TEST_BRANCH'), 'port'=>'TEST_PORT', 'path'=>$this->testPath);
$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
}
2013-08-13 15:54:35 +00:00
public function testInitializeLogsInAndConnectsClient() {
$this->setUp();
2013-07-24 15:06:35 +00:00
$repo_config = array(
2013-08-13 15:54:35 +00:00
'url' => 'TEST_PERFORCE_URL',
'depot' => 'TEST_DEPOT_CONFIG',
'branch' => 'TEST_BRANCH_CONFIG'
2013-07-24 15:06:35 +00:00
);
2013-08-13 15:54:35 +00:00
$driver = new TestingPerforceDriver($repo_config, $this->io, $this->config, $this->process, $this->remoteFileSystem);
$perforce = $this->getMockBuilder('Composer\Util\Perforce')->disableOriginalConstructor()->getMock();
$perforce->expects($this->at(0))
->method('p4Login')
->with($this->io);
$perforce->expects($this->at(1))
->method('checkStream')
->with($this->equalTo("TEST_DEPOT_CONFIG"));
$perforce->expects($this->at(2))
->method('writeP4ClientSpec');
$perforce->expects($this->at(3))
->method('connectClient');
$driver->injectPerforce($perforce);
$driver->initialize();
2013-07-24 15:06:35 +00:00
}
2013-08-13 15:54:35 +00:00
public function testHasComposerFile() {
$this->setUp();
2013-07-24 15:06:35 +00:00
$repo_config = array(
2013-08-13 15:54:35 +00:00
'url' => 'TEST_PERFORCE_URL',
'depot' => 'TEST_DEPOT_CONFIG',
'branch' => 'TEST_BRANCH_CONFIG'
2013-07-24 15:06:35 +00:00
);
2013-08-13 15:54:35 +00:00
$driver = new TestingPerforceDriver($repo_config, $this->io, $this->config, $this->process, $this->remoteFileSystem);
$arguments = array(array('depot'=>'TEST_DEPOT', 'branch'=>'TEST_BRANCH'), 'port'=>'TEST_PORT', 'path'=>$this->testPath);
$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->injectPerforce($perforce);
$driver->initialize();
$identifier = "TEST_IDENTIFIER";
$result = $driver->hasComposerFile($identifier);
2013-07-24 15:06:35 +00:00
$this->assertTrue($result);
}
}