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

175 lines
5.8 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\Test\TestCase;
2013-07-24 15:06:35 +00:00
use Composer\Util\Filesystem;
use Composer\Config;
use Composer\Util\Perforce;
use Composer\Test\Mock\ProcessExecutorMock;
2013-07-24 15:06:35 +00:00
2013-08-15 19:45:42 +00:00
/**
* @author Matt Whittom <Matt.Whittom@veteransunited.com>
*/
class PerforceDriverTest extends TestCase
{
protected $config;
protected $io;
protected $process;
protected $httpDownloader;
protected $testPath;
protected $driver;
protected $repoConfig;
protected $perforce;
2017-03-08 14:07:29 +00:00
const TEST_URL = 'TEST_PERFORCE_URL';
const TEST_DEPOT = 'TEST_DEPOT_CONFIG';
const TEST_BRANCH = 'TEST_BRANCH_CONFIG';
2013-07-24 15:06:35 +00:00
protected function setUp()
{
2017-03-08 14:07:29 +00:00
$this->testPath = $this->getUniqueTmpDirectory();
$this->config = $this->getTestConfig($this->testPath);
$this->repoConfig = $this->getTestRepoConfig();
$this->io = $this->getMockIOInterface();
$this->process = new ProcessExecutorMock;
$this->httpDownloader = $this->getMockHttpDownloader();
2017-03-08 14:07:29 +00:00
$this->perforce = $this->getMockPerforce();
$this->driver = new PerforceDriver($this->repoConfig, $this->io, $this->config, $this->httpDownloader, $this->process);
$this->overrideDriverInternalPerforce($this->perforce);
2013-07-24 15:06:35 +00:00
}
protected function tearDown()
{
//cleanup directory under test path
2013-07-24 15:06:35 +00:00
$fs = new Filesystem;
2013-08-13 15:54:35 +00:00
$fs->removeDirectory($this->testPath);
2017-03-08 14:07:29 +00:00
$this->driver = null;
$this->perforce = null;
$this->httpDownloader = null;
2017-03-08 14:07:29 +00:00
$this->process = null;
$this->io = null;
$this->repoConfig = null;
$this->config = null;
$this->testPath = null;
2013-07-24 15:06:35 +00:00
}
protected function overrideDriverInternalPerforce(Perforce $perforce)
{
$reflectionClass = new \ReflectionClass($this->driver);
$property = $reflectionClass->getProperty('perforce');
$property->setAccessible(true);
$property->setValue($this->driver, $perforce);
}
protected function getTestConfig($testPath)
{
$config = new Config();
2014-10-17 17:46:01 +00:00
$config->merge(array('config' => array('home' => $testPath)));
2014-06-10 14:02:44 +00:00
return $config;
}
protected function getTestRepoConfig()
{
return array(
2017-03-08 14:07:29 +00:00
'url' => self::TEST_URL,
'depot' => self::TEST_DEPOT,
'branch' => self::TEST_BRANCH,
);
}
protected function getMockIOInterface()
{
return $this->getMockBuilder('Composer\IO\IOInterface')->getMock();
}
protected function getMockHttpDownloader()
{
return $this->getMockBuilder('Composer\Util\HttpDownloader')->disableOriginalConstructor()->getMock();
}
protected function getMockPerforce()
{
2014-03-18 19:39:47 +00:00
$methods = array('p4login', 'checkStream', 'writeP4ClientSpec', 'connectClient', 'getComposerInformation', 'cleanupClientSpec');
2014-06-10 14:02:44 +00:00
return $this->getMockBuilder('Composer\Util\Perforce')->disableOriginalConstructor()->getMock();
}
public function testInitializeCapturesVariablesFromRepoConfig()
{
$driver = new PerforceDriver($this->repoConfig, $this->io, $this->config, $this->httpDownloader, $this->process);
2013-08-13 15:54:35 +00:00
$driver->initialize();
$this->assertEquals(self::TEST_URL, $driver->getUrl());
$this->assertEquals(self::TEST_DEPOT, $driver->getDepot());
$this->assertEquals(self::TEST_BRANCH, $driver->getBranch());
2013-07-24 15:06:35 +00:00
}
public function testInitializeLogsInAndConnectsClient()
{
$this->perforce->expects($this->at(0))->method('p4Login');
$this->perforce->expects($this->at(1))->method('checkStream');
$this->perforce->expects($this->at(2))->method('writeP4ClientSpec');
$this->perforce->expects($this->at(3))->method('connectClient');
$this->driver->initialize();
}
/**
* @depends testInitializeCapturesVariablesFromRepoConfig
* @depends testInitializeLogsInAndConnectsClient
*/
public function testHasComposerFileReturnsFalseOnNoComposerFile()
{
$identifier = 'TEST_IDENTIFIER';
$formatted_depot_path = '//' . self::TEST_DEPOT . '/' . $identifier;
2014-03-18 18:52:54 +00:00
$this->perforce->expects($this->any())->method('getComposerInformation')->with($this->equalTo($formatted_depot_path))->will($this->returnValue(array()));
$this->driver->initialize();
$result = $this->driver->hasComposerFile($identifier);
$this->assertFalse($result);
2013-07-24 15:06:35 +00:00
}
/**
* @depends testInitializeCapturesVariablesFromRepoConfig
* @depends testInitializeLogsInAndConnectsClient
*/
public function testHasComposerFileReturnsTrueWithOneOrMoreComposerFiles()
{
$identifier = 'TEST_IDENTIFIER';
$formatted_depot_path = '//' . self::TEST_DEPOT . '/' . $identifier;
2014-03-18 18:52:54 +00:00
$this->perforce->expects($this->any())->method('getComposerInformation')->with($this->equalTo($formatted_depot_path))->will($this->returnValue(array('')));
$this->driver->initialize();
$result = $this->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
}
2014-03-18 19:39:47 +00:00
public function testCleanup()
{
$this->perforce->expects($this->once())->method('cleanupClientSpec');
$this->driver->cleanup();
}
2013-07-24 15:06:35 +00:00
}