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;
|
2018-11-12 14:23:32 +00:00
|
|
|
use Composer\Test\TestCase;
|
2013-07-24 15:06:35 +00:00
|
|
|
use Composer\Util\Filesystem;
|
|
|
|
use Composer\Config;
|
2014-03-25 13:30:44 +00:00
|
|
|
use Composer\Util\Perforce;
|
2021-08-19 11:00:30 +00:00
|
|
|
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>
|
|
|
|
*/
|
2016-01-21 12:01:55 +00:00
|
|
|
class PerforceDriverTest extends TestCase
|
2013-09-04 14:24:49 +00:00
|
|
|
{
|
2021-10-16 08:16:06 +00:00
|
|
|
/**
|
|
|
|
* @var Config
|
|
|
|
*/
|
2014-03-17 21:06:19 +00:00
|
|
|
protected $config;
|
2021-10-16 08:16:06 +00:00
|
|
|
/**
|
|
|
|
* @var \Composer\IO\IOInterface&\PHPUnit\Framework\MockObject\MockObject
|
|
|
|
*/
|
2014-03-17 21:06:19 +00:00
|
|
|
protected $io;
|
2021-10-16 08:16:06 +00:00
|
|
|
/**
|
|
|
|
* @var ProcessExecutorMock
|
|
|
|
*/
|
2014-03-17 21:06:19 +00:00
|
|
|
protected $process;
|
2021-10-16 08:16:06 +00:00
|
|
|
/**
|
|
|
|
* @var \Composer\Util\HttpDownloader&\PHPUnit\Framework\MockObject\MockObject
|
|
|
|
*/
|
2018-10-31 11:44:54 +00:00
|
|
|
protected $httpDownloader;
|
2021-10-16 08:16:06 +00:00
|
|
|
/**
|
|
|
|
* @var string
|
|
|
|
*/
|
2014-03-17 21:06:19 +00:00
|
|
|
protected $testPath;
|
2021-10-16 08:16:06 +00:00
|
|
|
/**
|
|
|
|
* @var PerforceDriver
|
|
|
|
*/
|
2014-03-17 21:06:19 +00:00
|
|
|
protected $driver;
|
2021-10-16 08:16:06 +00:00
|
|
|
/**
|
|
|
|
* @var array<string, string>
|
|
|
|
*/
|
2014-03-17 21:06:19 +00:00
|
|
|
protected $repoConfig;
|
2021-10-16 08:16:06 +00:00
|
|
|
/**
|
|
|
|
* @var Perforce&\PHPUnit\Framework\MockObject\MockObject
|
|
|
|
*/
|
2016-01-21 12:01:55 +00:00
|
|
|
protected $perforce;
|
2014-03-17 21:06:19 +00:00
|
|
|
|
2017-03-08 14:07:29 +00:00
|
|
|
const TEST_URL = 'TEST_PERFORCE_URL';
|
|
|
|
const TEST_DEPOT = 'TEST_DEPOT_CONFIG';
|
2014-03-17 21:06:19 +00:00
|
|
|
const TEST_BRANCH = 'TEST_BRANCH_CONFIG';
|
2013-07-24 15:06:35 +00:00
|
|
|
|
2021-12-08 16:03:05 +00:00
|
|
|
protected function setUp(): void
|
2013-09-04 14:24:49 +00:00
|
|
|
{
|
2017-03-08 14:07:29 +00:00
|
|
|
$this->testPath = $this->getUniqueTmpDirectory();
|
|
|
|
$this->config = $this->getTestConfig($this->testPath);
|
2021-10-16 08:16:06 +00:00
|
|
|
$this->repoConfig = array(
|
|
|
|
'url' => self::TEST_URL,
|
|
|
|
'depot' => self::TEST_DEPOT,
|
|
|
|
'branch' => self::TEST_BRANCH,
|
|
|
|
);
|
2017-03-08 14:07:29 +00:00
|
|
|
$this->io = $this->getMockIOInterface();
|
2021-12-09 16:09:07 +00:00
|
|
|
$this->process = $this->getProcessExecutorMock();
|
2018-10-31 11:44:54 +00:00
|
|
|
$this->httpDownloader = $this->getMockHttpDownloader();
|
2017-03-08 14:07:29 +00:00
|
|
|
$this->perforce = $this->getMockPerforce();
|
2018-11-12 14:34:54 +00:00
|
|
|
$this->driver = new PerforceDriver($this->repoConfig, $this->io, $this->config, $this->httpDownloader, $this->process);
|
2014-03-25 13:30:44 +00:00
|
|
|
$this->overrideDriverInternalPerforce($this->perforce);
|
2013-07-24 15:06:35 +00:00
|
|
|
}
|
|
|
|
|
2021-12-08 16:03:05 +00:00
|
|
|
protected function tearDown(): void
|
2013-09-04 14:24:49 +00:00
|
|
|
{
|
2021-12-09 16:09:07 +00:00
|
|
|
parent::tearDown();
|
2014-03-17 21:06:19 +00:00
|
|
|
//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);
|
2013-07-24 15:06:35 +00:00
|
|
|
}
|
|
|
|
|
2021-10-27 13:29:52 +00:00
|
|
|
/**
|
|
|
|
* @return void
|
|
|
|
*/
|
2022-02-18 09:38:54 +00:00
|
|
|
protected function overrideDriverInternalPerforce(Perforce $perforce): void
|
2014-03-25 13:30:44 +00:00
|
|
|
{
|
|
|
|
$reflectionClass = new \ReflectionClass($this->driver);
|
|
|
|
$property = $reflectionClass->getProperty('perforce');
|
|
|
|
$property->setAccessible(true);
|
|
|
|
$property->setValue($this->driver, $perforce);
|
|
|
|
}
|
|
|
|
|
2021-10-27 13:29:52 +00:00
|
|
|
/**
|
|
|
|
* @param string $testPath
|
|
|
|
*
|
|
|
|
* @return Config
|
|
|
|
*/
|
2014-03-17 21:06:19 +00:00
|
|
|
protected function getTestConfig($testPath)
|
2013-09-04 14:24:49 +00:00
|
|
|
{
|
2014-03-17 21:06:19 +00:00
|
|
|
$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
|
|
|
|
2014-03-17 21:06:19 +00:00
|
|
|
return $config;
|
|
|
|
}
|
|
|
|
|
2021-10-27 13:29:52 +00:00
|
|
|
/**
|
|
|
|
* @return \PHPUnit\Framework\MockObject\MockObject&\Composer\IO\IOInterface
|
|
|
|
*/
|
2014-03-17 21:06:19 +00:00
|
|
|
protected function getMockIOInterface()
|
|
|
|
{
|
2018-04-12 08:24:56 +00:00
|
|
|
return $this->getMockBuilder('Composer\IO\IOInterface')->getMock();
|
2014-03-17 21:06:19 +00:00
|
|
|
}
|
|
|
|
|
2021-10-27 13:29:52 +00:00
|
|
|
/**
|
|
|
|
* @return \PHPUnit\Framework\MockObject\MockObject&\Composer\Util\HttpDownloader
|
|
|
|
*/
|
2018-10-31 11:44:54 +00:00
|
|
|
protected function getMockHttpDownloader()
|
2014-03-17 21:06:19 +00:00
|
|
|
{
|
2018-10-31 11:44:54 +00:00
|
|
|
return $this->getMockBuilder('Composer\Util\HttpDownloader')->disableOriginalConstructor()->getMock();
|
2014-03-17 21:06:19 +00:00
|
|
|
}
|
|
|
|
|
2021-10-27 13:29:52 +00:00
|
|
|
/**
|
|
|
|
* @return \PHPUnit\Framework\MockObject\MockObject&\Composer\Util\Perforce
|
|
|
|
*/
|
2014-03-17 21:06:19 +00:00
|
|
|
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
|
|
|
|
2019-02-18 12:03:34 +00:00
|
|
|
return $this->getMockBuilder('Composer\Util\Perforce')->disableOriginalConstructor()->getMock();
|
2014-03-17 21:06:19 +00:00
|
|
|
}
|
|
|
|
|
2022-02-18 09:38:54 +00:00
|
|
|
public function testInitializeCapturesVariablesFromRepoConfig(): void
|
2014-03-17 21:06:19 +00:00
|
|
|
{
|
2018-11-12 14:34:54 +00:00
|
|
|
$driver = new PerforceDriver($this->repoConfig, $this->io, $this->config, $this->httpDownloader, $this->process);
|
2013-08-13 15:54:35 +00:00
|
|
|
$driver->initialize();
|
2014-03-17 21:06:19 +00:00
|
|
|
$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
|
|
|
}
|
|
|
|
|
2022-02-18 09:38:54 +00:00
|
|
|
public function testInitializeLogsInAndConnectsClient(): void
|
2013-09-04 14:24:49 +00:00
|
|
|
{
|
2021-12-09 16:09:07 +00:00
|
|
|
$this->perforce->expects($this->once())->method('p4Login');
|
|
|
|
$this->perforce->expects($this->once())->method('checkStream');
|
|
|
|
$this->perforce->expects($this->once())->method('writeP4ClientSpec');
|
|
|
|
$this->perforce->expects($this->once())->method('connectClient');
|
2014-03-17 21:06:19 +00:00
|
|
|
$this->driver->initialize();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @depends testInitializeCapturesVariablesFromRepoConfig
|
|
|
|
* @depends testInitializeLogsInAndConnectsClient
|
|
|
|
*/
|
2022-02-18 09:38:54 +00:00
|
|
|
public function testHasComposerFileReturnsFalseOnNoComposerFile(): void
|
2014-03-17 21:06:19 +00:00
|
|
|
{
|
|
|
|
$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()));
|
2014-03-17 21:06:19 +00:00
|
|
|
$this->driver->initialize();
|
|
|
|
$result = $this->driver->hasComposerFile($identifier);
|
|
|
|
$this->assertFalse($result);
|
2013-07-24 15:06:35 +00:00
|
|
|
}
|
|
|
|
|
2014-03-17 21:06:19 +00:00
|
|
|
/**
|
|
|
|
* @depends testInitializeCapturesVariablesFromRepoConfig
|
|
|
|
* @depends testInitializeLogsInAndConnectsClient
|
|
|
|
*/
|
2022-02-18 09:38:54 +00:00
|
|
|
public function testHasComposerFileReturnsTrueWithOneOrMoreComposerFiles(): void
|
2013-09-04 14:24:49 +00:00
|
|
|
{
|
2013-09-09 19:48:24 +00:00
|
|
|
$identifier = 'TEST_IDENTIFIER';
|
2014-03-17 21:06:19 +00:00
|
|
|
$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('')));
|
2014-03-17 21:06:19 +00:00
|
|
|
$this->driver->initialize();
|
|
|
|
$result = $this->driver->hasComposerFile($identifier);
|
2013-07-24 15:06:35 +00:00
|
|
|
$this->assertTrue($result);
|
|
|
|
}
|
2013-10-28 19:57:02 +00:00
|
|
|
|
2013-10-16 08:07:10 +00:00
|
|
|
/**
|
|
|
|
* Test that supports() simply return false.
|
2013-10-28 19:57:02 +00:00
|
|
|
*
|
2013-10-16 08:07:10 +00:00
|
|
|
* @covers \Composer\Repository\Vcs\PerforceDriver::supports
|
2013-10-28 19:57:02 +00:00
|
|
|
*
|
2013-10-16 08:07:10 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
2022-02-18 09:38:54 +00:00
|
|
|
public function testSupportsReturnsFalseNoDeepCheck(): void
|
2013-10-16 08:07:10 +00:00
|
|
|
{
|
|
|
|
$this->expectOutputString('');
|
2013-10-29 15:00:00 +00:00
|
|
|
$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
|
|
|
|
2022-02-18 09:38:54 +00:00
|
|
|
public function testCleanup(): void
|
2014-03-18 19:39:47 +00:00
|
|
|
{
|
|
|
|
$this->perforce->expects($this->once())->method('cleanupClientSpec');
|
|
|
|
$this->driver->cleanup();
|
|
|
|
}
|
2013-07-24 15:06:35 +00:00
|
|
|
}
|