1
0
Fork 0
mirror of https://github.com/composer/composer synced 2025-05-09 00:22:53 +00:00

almost all unit tests passing after IOInterface dependency refactor. no longer passing IOInterface into any Perforce methods

This commit is contained in:
Clark Stuth 2014-03-17 16:06:19 -05:00
parent 0f7b078d6c
commit 24dd42267f
6 changed files with 239 additions and 229 deletions

View file

@ -21,113 +21,129 @@ use Composer\Config;
*/
class PerforceDriverTest extends \PHPUnit_Framework_TestCase
{
private $config;
private $io;
private $process;
private $remoteFileSystem;
private $testPath;
protected $config;
protected $io;
protected $process;
protected $remoteFileSystem;
protected $testPath;
protected $driver;
protected $repoConfig;
const TEST_URL = 'TEST_PERFORCE_URL';
const TEST_DEPOT = 'TEST_DEPOT_CONFIG';
const TEST_BRANCH = 'TEST_BRANCH_CONFIG';
public function setUp()
{
$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');
$this->process = $this->getMock('Composer\Util\ProcessExecutor');
$this->remoteFileSystem = $this->getMockBuilder('Composer\Util\RemoteFilesystem')->disableOriginalConstructor()
->getMock();
$this->testPath = sys_get_temp_dir() . '/composer-test';
$this->config = $this->getTestConfig($this->testPath);
$this->repoConfig = $this->getTestRepoConfig();
$this->io = $this->getMockIOInterface();
$this->process = $this->getMockProcessExecutor();
$this->remoteFileSystem = $this->getMockRemoteFilesystem();
$this->perforce = $this->getMockPerforce();
$this->driver = new PerforceDriver($this->repoConfig, $this->io, $this->config, $this->process, $this->remoteFileSystem);
}
public function tearDown()
{
//cleanup directory under test path
$fs = new Filesystem;
$fs->removeDirectory($this->testPath);
$this->driver = null;
$this->perforce = null;
$this->remoteFileSystem = null;
$this->process = null;
$this->io = null;
$this->repoConfig = null;
$this->config = null;
$this->testPath = null;
}
protected function getTestConfig($testPath)
{
$config = new Config();
$config->merge(array('config'=>array('home'=>$testPath)));
return $config;
}
protected function getTestRepoConfig()
{
return array(
'url' => self::TEST_URL,
'depot' => self::TEST_DEPOT,
'branch' => self::TEST_BRANCH,
);
}
protected function getMockIOInterface()
{
return $this->getMock('Composer\IO\IOInterface');
}
protected function getMockProcessExecutor()
{
return $this->getMock('Composer\Util\ProcessExecutor');
}
protected function getMockRemoteFilesystem()
{
return $this->getMockBuilder('Composer\Util\RemoteFilesystem')->disableOriginalConstructor()->getMock();
}
protected function getMockPerforce()
{
$methods = array('p4login', 'checkStream', 'writeP4ClientSpec', 'connectClient', 'getComposerInformation');
return $this->getMockBuilder('Composer\Util\Perforce', $methods)->disableOriginalConstructor()->getMock();
}
public function testInitializeCapturesVariablesFromRepoConfig()
{
$this->setUp();
$repoConfig = array(
'url' => 'TEST_PERFORCE_URL',
'depot' => 'TEST_DEPOT_CONFIG',
'branch' => 'TEST_BRANCH_CONFIG'
);
$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'
);
$perforce = $this->getMock('Composer\Util\Perforce', null, $arguments);
$driver->setPerforce($perforce);
$driver = new PerforceDriver($this->repoConfig, $this->io, $this->config, $this->process, $this->remoteFileSystem);
$driver->setPerforce($this->perforce);
$driver->initialize();
$this->assertEquals('TEST_PERFORCE_URL', $driver->getUrl());
$this->assertEquals('TEST_DEPOT_CONFIG', $driver->getDepot());
$this->assertEquals('TEST_BRANCH_CONFIG', $driver->getBranch());
$this->assertEquals(self::TEST_URL, $driver->getUrl());
$this->assertEquals(self::TEST_DEPOT, $driver->getDepot());
$this->assertEquals(self::TEST_BRANCH, $driver->getBranch());
}
public function testInitializeLogsInAndConnectsClient()
{
$this->setUp();
$repoConfig = array(
'url' => 'TEST_PERFORCE_URL',
'depot' => 'TEST_DEPOT_CONFIG',
'branch' => 'TEST_BRANCH_CONFIG'
);
$driver = new PerforceDriver($repoConfig, $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->setPerforce($perforce);
$driver->initialize();
$this->driver->setPerforce($this->perforce);
$this->perforce->expects($this->at(0))->method('p4Login')->with($this->identicalTo($this->io));
$this->perforce->expects($this->at(1))->method('checkStream')->with($this->equalTo(self::TEST_DEPOT));
$this->perforce->expects($this->at(2))->method('writeP4ClientSpec');
$this->perforce->expects($this->at(3))->method('connectClient');
$this->driver->initialize();
}
public function testHasComposerFile()
/**
* @depends testInitializeCapturesVariablesFromRepoConfig
* @depends testInitializeLogsInAndConnectsClient
*/
public function testHasComposerFileReturnsFalseOnNoComposerFile()
{
$repoConfig = array(
'url' => 'TEST_PERFORCE_URL',
'depot' => 'TEST_DEPOT_CONFIG',
'branch' => 'TEST_BRANCH_CONFIG'
);
$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'
);
$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);
$driver->initialize();
$identifier = 'TEST_IDENTIFIER';
$result = $driver->hasComposerFile($identifier);
$formatted_depot_path = '//' . self::TEST_DEPOT . '/' . $identifier;
$this->driver->setPerforce($this->perforce);
$this->perforce->expects($this->at(0))->method('getComposerInformation')->with($this->equalTo($formatted_depot_path))->will($this->returnValue(array()));
$this->driver->initialize();
$result = $this->driver->hasComposerFile($identifier);
$this->assertFalse($result);
}
/**
* @depends testInitializeCapturesVariablesFromRepoConfig
* @depends testInitializeLogsInAndConnectsClient
*/
public function testHasComposerFileReturnsTrueWithOneOrMoreComposerFiles()
{
$identifier = 'TEST_IDENTIFIER';
$formatted_depot_path = '//' . self::TEST_DEPOT . '/' . $identifier;
$this->driver->setPerforce($this->perforce);
$this->perforce->expects($this->at(0))->method('getComposerInformation')->with($this->equalTo($formatted_depot_path))->will($this->returnValue(array('')));
$this->driver->initialize();
$result = $this->driver->hasComposerFile($identifier);
$this->assertTrue($result);
}