2013-08-09 19:24:58 +00:00
|
|
|
<?php
|
2013-10-11 23:12:02 +00:00
|
|
|
|
2013-08-15 17:16:15 +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.
|
2013-08-09 19:24:58 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
namespace Composer\Test\Util;
|
|
|
|
|
2021-12-09 16:09:07 +00:00
|
|
|
use Composer\Json\JsonFile;
|
2021-12-09 21:14:04 +00:00
|
|
|
use Composer\Test\Mock\ProcessExecutorMock;
|
2013-08-15 17:16:15 +00:00
|
|
|
use Composer\Util\Perforce;
|
2020-02-07 03:18:45 +00:00
|
|
|
use Composer\Test\TestCase;
|
2018-08-25 15:45:08 +00:00
|
|
|
use Composer\Util\ProcessExecutor;
|
2013-08-09 19:24:58 +00:00
|
|
|
|
2013-08-15 17:16:15 +00:00
|
|
|
/**
|
|
|
|
* @author Matt Whittom <Matt.Whittom@veteransunited.com>
|
|
|
|
*/
|
2017-11-04 14:52:13 +00:00
|
|
|
class PerforceTest extends TestCase
|
2013-09-04 14:24:49 +00:00
|
|
|
{
|
2021-10-27 14:18:46 +00:00
|
|
|
/** @var Perforce */
|
2013-08-09 19:24:58 +00:00
|
|
|
protected $perforce;
|
2021-12-09 21:14:04 +00:00
|
|
|
/** @var ProcessExecutorMock */
|
2013-08-09 19:24:58 +00:00
|
|
|
protected $processExecutor;
|
2021-10-27 14:18:46 +00:00
|
|
|
/** @var array<string, string> */
|
2018-01-06 14:05:39 +00:00
|
|
|
protected $repoConfig;
|
2021-10-27 14:18:46 +00:00
|
|
|
/** @var \PHPUnit\Framework\MockObject\MockObject&\Composer\IO\IOInterface */
|
2014-03-14 19:45:31 +00:00
|
|
|
protected $io;
|
2013-08-09 19:24:58 +00:00
|
|
|
|
2017-03-08 14:07:29 +00:00
|
|
|
const TEST_DEPOT = 'depot';
|
|
|
|
const TEST_BRANCH = 'branch';
|
|
|
|
const TEST_P4USER = 'user';
|
2014-03-17 21:06:19 +00:00
|
|
|
const TEST_CLIENT_NAME = 'TEST';
|
2017-03-08 14:07:29 +00:00
|
|
|
const TEST_PORT = 'port';
|
|
|
|
const TEST_PATH = 'path';
|
2014-03-17 21:06:19 +00:00
|
|
|
|
2021-12-08 16:03:05 +00:00
|
|
|
protected function setUp(): void
|
2013-09-04 14:24:49 +00:00
|
|
|
{
|
2021-12-09 21:14:04 +00:00
|
|
|
$this->processExecutor = $this->getProcessExecutorMock();
|
2014-03-17 21:06:19 +00:00
|
|
|
$this->repoConfig = $this->getTestRepoConfig();
|
|
|
|
$this->io = $this->getMockIOInterface();
|
2014-03-25 13:30:44 +00:00
|
|
|
$this->createNewPerforceWithWindowsFlag(true);
|
2014-03-14 19:45:31 +00:00
|
|
|
}
|
|
|
|
|
2021-10-27 14:18:46 +00:00
|
|
|
/**
|
|
|
|
* @return array<string, string>
|
|
|
|
*/
|
2022-02-18 10:22:01 +00:00
|
|
|
public function getTestRepoConfig(): array
|
2014-03-17 21:06:19 +00:00
|
|
|
{
|
|
|
|
return array(
|
2017-03-08 14:07:29 +00:00
|
|
|
'depot' => self::TEST_DEPOT,
|
|
|
|
'branch' => self::TEST_BRANCH,
|
|
|
|
'p4user' => self::TEST_P4USER,
|
2015-09-28 09:51:14 +00:00
|
|
|
'unique_perforce_client_name' => self::TEST_CLIENT_NAME,
|
2014-03-17 21:06:19 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2021-10-27 14:18:46 +00:00
|
|
|
/**
|
|
|
|
* @return \PHPUnit\Framework\MockObject\MockObject&\Composer\IO\IOInterface
|
|
|
|
*/
|
2014-03-17 21:06:19 +00:00
|
|
|
public 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 14:18:46 +00:00
|
|
|
/**
|
|
|
|
* @param bool $flag
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2022-02-18 09:38:54 +00:00
|
|
|
protected function createNewPerforceWithWindowsFlag($flag): void
|
2014-03-25 13:30:44 +00:00
|
|
|
{
|
|
|
|
$this->perforce = new Perforce($this->repoConfig, self::TEST_PORT, self::TEST_PATH, $this->processExecutor, $flag, $this->io);
|
|
|
|
}
|
|
|
|
|
2022-02-18 09:38:54 +00:00
|
|
|
public function testGetClientWithoutStream(): void
|
2013-09-04 14:24:49 +00:00
|
|
|
{
|
2013-08-15 17:16:15 +00:00
|
|
|
$client = $this->perforce->getClient();
|
|
|
|
|
2013-09-09 19:48:24 +00:00
|
|
|
$expected = 'composer_perforce_TEST_depot';
|
2013-08-09 19:24:58 +00:00
|
|
|
$this->assertEquals($expected, $client);
|
|
|
|
}
|
|
|
|
|
2022-02-18 09:38:54 +00:00
|
|
|
public function testGetClientFromStream(): void
|
2013-09-04 14:24:49 +00:00
|
|
|
{
|
2013-08-15 17:16:15 +00:00
|
|
|
$this->setPerforceToStream();
|
|
|
|
|
|
|
|
$client = $this->perforce->getClient();
|
2013-08-09 19:24:58 +00:00
|
|
|
|
2013-09-09 19:48:24 +00:00
|
|
|
$expected = 'composer_perforce_TEST_depot_branch';
|
2013-08-09 19:24:58 +00:00
|
|
|
$this->assertEquals($expected, $client);
|
|
|
|
}
|
|
|
|
|
2022-02-18 09:38:54 +00:00
|
|
|
public function testGetStreamWithoutStream(): void
|
2013-09-04 14:24:49 +00:00
|
|
|
{
|
2013-08-15 17:16:15 +00:00
|
|
|
$stream = $this->perforce->getStream();
|
2013-08-09 19:24:58 +00:00
|
|
|
$this->assertEquals("//depot", $stream);
|
|
|
|
}
|
|
|
|
|
2022-02-18 09:38:54 +00:00
|
|
|
public function testGetStreamWithStream(): void
|
2013-09-04 14:24:49 +00:00
|
|
|
{
|
2013-08-15 17:16:15 +00:00
|
|
|
$this->setPerforceToStream();
|
|
|
|
|
|
|
|
$stream = $this->perforce->getStream();
|
2013-09-09 19:48:24 +00:00
|
|
|
$this->assertEquals('//depot/branch', $stream);
|
2013-08-09 19:24:58 +00:00
|
|
|
}
|
|
|
|
|
2022-02-18 09:38:54 +00:00
|
|
|
public function testGetStreamWithoutLabelWithStreamWithoutLabel(): void
|
2013-09-04 14:24:49 +00:00
|
|
|
{
|
2013-09-09 19:48:24 +00:00
|
|
|
$stream = $this->perforce->getStreamWithoutLabel('//depot/branch');
|
|
|
|
$this->assertEquals('//depot/branch', $stream);
|
2013-08-15 17:16:15 +00:00
|
|
|
}
|
|
|
|
|
2022-02-18 09:38:54 +00:00
|
|
|
public function testGetStreamWithoutLabelWithStreamWithLabel(): void
|
2013-09-04 14:24:49 +00:00
|
|
|
{
|
2013-09-09 19:48:24 +00:00
|
|
|
$stream = $this->perforce->getStreamWithoutLabel('//depot/branching@label');
|
|
|
|
$this->assertEquals('//depot/branching', $stream);
|
2013-08-09 19:24:58 +00:00
|
|
|
}
|
|
|
|
|
2022-02-18 09:38:54 +00:00
|
|
|
public function testGetClientSpec(): void
|
2013-09-04 14:24:49 +00:00
|
|
|
{
|
2013-08-15 17:16:15 +00:00
|
|
|
$clientSpec = $this->perforce->getP4ClientSpec();
|
2013-09-09 19:48:24 +00:00
|
|
|
$expected = 'path/composer_perforce_TEST_depot.p4.spec';
|
2013-08-09 19:24:58 +00:00
|
|
|
$this->assertEquals($expected, $clientSpec);
|
|
|
|
}
|
|
|
|
|
2022-02-18 09:38:54 +00:00
|
|
|
public function testGenerateP4Command(): void
|
2013-09-04 14:24:49 +00:00
|
|
|
{
|
2013-09-09 19:48:24 +00:00
|
|
|
$command = 'do something';
|
2013-08-15 17:16:15 +00:00
|
|
|
$p4Command = $this->perforce->generateP4Command($command);
|
2013-09-09 19:48:24 +00:00
|
|
|
$expected = 'p4 -u user -c composer_perforce_TEST_depot -p port do something';
|
2013-08-09 19:24:58 +00:00
|
|
|
$this->assertEquals($expected, $p4Command);
|
|
|
|
}
|
|
|
|
|
2022-02-18 09:38:54 +00:00
|
|
|
public function testQueryP4UserWithUserAlreadySet(): void
|
2013-09-04 14:24:49 +00:00
|
|
|
{
|
2014-03-17 21:06:19 +00:00
|
|
|
$this->perforce->queryP4user();
|
|
|
|
$this->assertEquals(self::TEST_P4USER, $this->perforce->getUser());
|
2013-08-09 19:24:58 +00:00
|
|
|
}
|
|
|
|
|
2022-02-18 09:38:54 +00:00
|
|
|
public function testQueryP4UserWithUserSetInP4VariablesWithWindowsOS(): void
|
2013-09-04 14:24:49 +00:00
|
|
|
{
|
2014-03-25 13:30:44 +00:00
|
|
|
$this->createNewPerforceWithWindowsFlag(true);
|
2014-03-17 21:06:19 +00:00
|
|
|
$this->perforce->setUser(null);
|
2021-12-09 21:14:04 +00:00
|
|
|
$this->processExecutor->expects(
|
|
|
|
[['cmd' => 'p4 set', 'stdout' => 'P4USER=TEST_P4VARIABLE_USER' . PHP_EOL, 'return' => 0]],
|
|
|
|
true
|
|
|
|
);
|
|
|
|
|
2014-03-17 21:06:19 +00:00
|
|
|
$this->perforce->queryP4user();
|
2013-09-09 19:48:24 +00:00
|
|
|
$this->assertEquals('TEST_P4VARIABLE_USER', $this->perforce->getUser());
|
2013-08-09 19:24:58 +00:00
|
|
|
}
|
|
|
|
|
2022-02-18 09:38:54 +00:00
|
|
|
public function testQueryP4UserWithUserSetInP4VariablesNotWindowsOS(): void
|
2013-09-04 14:24:49 +00:00
|
|
|
{
|
2014-03-25 13:30:44 +00:00
|
|
|
$this->createNewPerforceWithWindowsFlag(false);
|
2014-03-17 21:06:19 +00:00
|
|
|
$this->perforce->setUser(null);
|
2021-12-09 21:14:04 +00:00
|
|
|
|
|
|
|
$this->processExecutor->expects(
|
|
|
|
[['cmd' => 'echo $P4USER', 'stdout' => 'TEST_P4VARIABLE_USER' . PHP_EOL, 'return' => 0]],
|
|
|
|
true
|
|
|
|
);
|
|
|
|
|
2014-03-17 21:06:19 +00:00
|
|
|
$this->perforce->queryP4user();
|
2013-09-09 19:48:24 +00:00
|
|
|
$this->assertEquals('TEST_P4VARIABLE_USER', $this->perforce->getUser());
|
2013-08-09 19:24:58 +00:00
|
|
|
}
|
|
|
|
|
2022-02-18 09:38:54 +00:00
|
|
|
public function testQueryP4UserQueriesForUser(): void
|
2013-09-04 14:24:49 +00:00
|
|
|
{
|
2014-03-17 21:06:19 +00:00
|
|
|
$this->perforce->setUser(null);
|
2013-09-09 19:48:24 +00:00
|
|
|
$expectedQuestion = 'Enter P4 User:';
|
2021-12-09 16:09:07 +00:00
|
|
|
$this->io->method('ask')
|
2014-03-17 21:06:19 +00:00
|
|
|
->with($this->equalTo($expectedQuestion))
|
2021-12-09 16:09:07 +00:00
|
|
|
->willReturn('TEST_QUERY_USER');
|
2014-03-17 21:06:19 +00:00
|
|
|
$this->perforce->queryP4user();
|
2013-09-09 19:48:24 +00:00
|
|
|
$this->assertEquals('TEST_QUERY_USER', $this->perforce->getUser());
|
2013-08-09 19:24:58 +00:00
|
|
|
}
|
|
|
|
|
2022-02-18 09:38:54 +00:00
|
|
|
public function testQueryP4UserStoresResponseToQueryForUserWithWindows(): void
|
2013-09-04 14:24:49 +00:00
|
|
|
{
|
2014-03-25 13:30:44 +00:00
|
|
|
$this->createNewPerforceWithWindowsFlag(true);
|
2014-03-17 21:06:19 +00:00
|
|
|
$this->perforce->setUser(null);
|
2013-09-09 19:48:24 +00:00
|
|
|
$expectedQuestion = 'Enter P4 User:';
|
2017-03-08 14:07:29 +00:00
|
|
|
$expectedCommand = 'p4 set P4USER=TEST_QUERY_USER';
|
2021-12-09 16:09:07 +00:00
|
|
|
$this->io->expects($this->once())
|
2014-03-17 21:06:19 +00:00
|
|
|
->method('ask')
|
|
|
|
->with($this->equalTo($expectedQuestion))
|
2021-12-09 16:09:07 +00:00
|
|
|
->willReturn('TEST_QUERY_USER');
|
2021-12-09 21:14:04 +00:00
|
|
|
|
|
|
|
$this->processExecutor->expects(
|
|
|
|
[
|
|
|
|
'p4 set',
|
2022-02-18 07:50:11 +00:00
|
|
|
$expectedCommand,
|
2021-12-09 21:14:04 +00:00
|
|
|
],
|
|
|
|
true
|
|
|
|
);
|
|
|
|
|
2014-03-17 21:06:19 +00:00
|
|
|
$this->perforce->queryP4user();
|
2013-08-09 19:24:58 +00:00
|
|
|
}
|
|
|
|
|
2022-02-18 09:38:54 +00:00
|
|
|
public function testQueryP4UserStoresResponseToQueryForUserWithoutWindows(): void
|
2013-09-04 14:24:49 +00:00
|
|
|
{
|
2014-03-25 13:30:44 +00:00
|
|
|
$this->createNewPerforceWithWindowsFlag(false);
|
2014-03-17 21:06:19 +00:00
|
|
|
$this->perforce->setUser(null);
|
2013-09-09 19:48:24 +00:00
|
|
|
$expectedQuestion = 'Enter P4 User:';
|
2017-03-08 14:07:29 +00:00
|
|
|
$expectedCommand = 'export P4USER=TEST_QUERY_USER';
|
2021-12-09 16:09:07 +00:00
|
|
|
$this->io->expects($this->once())
|
2014-03-17 21:06:19 +00:00
|
|
|
->method('ask')
|
|
|
|
->with($this->equalTo($expectedQuestion))
|
2021-12-09 16:09:07 +00:00
|
|
|
->willReturn('TEST_QUERY_USER');
|
2021-12-09 21:14:04 +00:00
|
|
|
$this->processExecutor->expects(
|
|
|
|
[
|
|
|
|
'echo $P4USER',
|
2022-02-18 07:50:11 +00:00
|
|
|
$expectedCommand,
|
2021-12-09 21:14:04 +00:00
|
|
|
],
|
|
|
|
true
|
|
|
|
);
|
2014-03-17 21:06:19 +00:00
|
|
|
$this->perforce->queryP4user();
|
2013-08-09 19:24:58 +00:00
|
|
|
}
|
|
|
|
|
2022-02-18 09:38:54 +00:00
|
|
|
public function testQueryP4PasswordWithPasswordAlreadySet(): void
|
2013-09-04 14:24:49 +00:00
|
|
|
{
|
|
|
|
$repoConfig = array(
|
2017-03-08 14:07:29 +00:00
|
|
|
'depot' => 'depot',
|
|
|
|
'branch' => 'branch',
|
|
|
|
'p4user' => 'user',
|
2015-09-28 09:51:14 +00:00
|
|
|
'p4password' => 'TEST_PASSWORD',
|
2013-09-04 14:24:49 +00:00
|
|
|
);
|
2018-01-06 14:05:39 +00:00
|
|
|
$this->perforce = new Perforce($repoConfig, 'port', 'path', $this->processExecutor, false, $this->getMockIOInterface());
|
2014-03-17 21:06:19 +00:00
|
|
|
$password = $this->perforce->queryP4Password();
|
2013-09-09 19:48:24 +00:00
|
|
|
$this->assertEquals('TEST_PASSWORD', $password);
|
2013-08-09 19:24:58 +00:00
|
|
|
}
|
|
|
|
|
2022-02-18 09:38:54 +00:00
|
|
|
public function testQueryP4PasswordWithPasswordSetInP4VariablesWithWindowsOS(): void
|
2013-09-04 14:24:49 +00:00
|
|
|
{
|
2014-03-25 13:30:44 +00:00
|
|
|
$this->createNewPerforceWithWindowsFlag(true);
|
2021-12-09 21:14:04 +00:00
|
|
|
|
|
|
|
$this->processExecutor->expects(
|
|
|
|
[['cmd' => 'p4 set', 'stdout' => 'P4PASSWD=TEST_P4VARIABLE_PASSWORD' . PHP_EOL, 'return' => 0]],
|
|
|
|
true
|
|
|
|
);
|
|
|
|
|
2014-03-17 21:06:19 +00:00
|
|
|
$password = $this->perforce->queryP4Password();
|
2013-09-09 19:48:24 +00:00
|
|
|
$this->assertEquals('TEST_P4VARIABLE_PASSWORD', $password);
|
2013-08-09 19:24:58 +00:00
|
|
|
}
|
|
|
|
|
2022-02-18 09:38:54 +00:00
|
|
|
public function testQueryP4PasswordWithPasswordSetInP4VariablesNotWindowsOS(): void
|
2013-09-04 14:24:49 +00:00
|
|
|
{
|
2014-03-25 13:30:44 +00:00
|
|
|
$this->createNewPerforceWithWindowsFlag(false);
|
2014-06-10 14:02:44 +00:00
|
|
|
|
2021-12-09 21:14:04 +00:00
|
|
|
$this->processExecutor->expects(
|
|
|
|
[['cmd' => 'echo $P4PASSWD', 'stdout' => 'TEST_P4VARIABLE_PASSWORD' . PHP_EOL, 'return' => 0]],
|
|
|
|
true
|
|
|
|
);
|
2014-03-17 21:06:19 +00:00
|
|
|
|
|
|
|
$password = $this->perforce->queryP4Password();
|
2013-09-09 19:48:24 +00:00
|
|
|
$this->assertEquals('TEST_P4VARIABLE_PASSWORD', $password);
|
2013-08-09 19:24:58 +00:00
|
|
|
}
|
|
|
|
|
2022-02-18 09:38:54 +00:00
|
|
|
public function testQueryP4PasswordQueriesForPassword(): void
|
2013-09-04 14:24:49 +00:00
|
|
|
{
|
2013-09-09 19:48:24 +00:00
|
|
|
$expectedQuestion = 'Enter password for Perforce user user: ';
|
2021-12-09 16:09:07 +00:00
|
|
|
$this->io->expects($this->once())
|
2013-10-11 23:21:34 +00:00
|
|
|
->method('askAndHideAnswer')
|
|
|
|
->with($this->equalTo($expectedQuestion))
|
2021-12-09 16:09:07 +00:00
|
|
|
->willReturn('TEST_QUERY_PASSWORD');
|
2013-08-09 19:24:58 +00:00
|
|
|
|
2014-03-17 21:06:19 +00:00
|
|
|
$password = $this->perforce->queryP4Password();
|
2013-09-09 19:48:24 +00:00
|
|
|
$this->assertEquals('TEST_QUERY_PASSWORD', $password);
|
2013-08-09 19:24:58 +00:00
|
|
|
}
|
|
|
|
|
2022-02-18 09:38:54 +00:00
|
|
|
public function testWriteP4ClientSpecWithoutStream(): void
|
2013-09-04 14:24:49 +00:00
|
|
|
{
|
2013-09-09 19:48:24 +00:00
|
|
|
$stream = fopen('php://memory', 'w+');
|
2022-01-01 13:39:32 +00:00
|
|
|
if (false === $stream) {
|
|
|
|
self::fail('Could not open memory stream');
|
|
|
|
}
|
2013-08-15 17:16:15 +00:00
|
|
|
$this->perforce->writeClientSpecToFile($stream);
|
|
|
|
|
|
|
|
rewind($stream);
|
2013-09-09 19:48:24 +00:00
|
|
|
|
2013-09-04 14:24:49 +00:00
|
|
|
$expectedArray = $this->getExpectedClientSpec(false);
|
2013-08-09 19:24:58 +00:00
|
|
|
try {
|
|
|
|
foreach ($expectedArray as $expected) {
|
2013-08-15 17:16:15 +00:00
|
|
|
$this->assertStringStartsWith($expected, fgets($stream));
|
2013-08-09 19:24:58 +00:00
|
|
|
}
|
2013-08-15 17:16:15 +00:00
|
|
|
$this->assertFalse(fgets($stream));
|
2018-01-06 14:05:39 +00:00
|
|
|
} catch (\Exception $e) {
|
2013-08-15 17:16:15 +00:00
|
|
|
fclose($stream);
|
2013-08-09 19:24:58 +00:00
|
|
|
throw $e;
|
|
|
|
}
|
2013-08-15 17:16:15 +00:00
|
|
|
fclose($stream);
|
2013-08-09 19:24:58 +00:00
|
|
|
}
|
|
|
|
|
2022-02-18 09:38:54 +00:00
|
|
|
public function testWriteP4ClientSpecWithStream(): void
|
2013-09-04 14:24:49 +00:00
|
|
|
{
|
2013-08-15 17:16:15 +00:00
|
|
|
$this->setPerforceToStream();
|
2013-09-09 19:48:24 +00:00
|
|
|
$stream = fopen('php://memory', 'w+');
|
2022-01-01 13:39:32 +00:00
|
|
|
if (false === $stream) {
|
|
|
|
self::fail('Could not open memory stream');
|
|
|
|
}
|
2013-08-15 17:16:15 +00:00
|
|
|
|
|
|
|
$this->perforce->writeClientSpecToFile($stream);
|
|
|
|
rewind($stream);
|
|
|
|
|
2013-09-04 14:24:49 +00:00
|
|
|
$expectedArray = $this->getExpectedClientSpec(true);
|
2013-08-09 19:24:58 +00:00
|
|
|
try {
|
|
|
|
foreach ($expectedArray as $expected) {
|
2013-08-15 17:16:15 +00:00
|
|
|
$this->assertStringStartsWith($expected, fgets($stream));
|
2013-08-09 19:24:58 +00:00
|
|
|
}
|
2013-08-15 17:16:15 +00:00
|
|
|
$this->assertFalse(fgets($stream));
|
2018-01-06 14:05:39 +00:00
|
|
|
} catch (\Exception $e) {
|
2013-08-15 17:16:15 +00:00
|
|
|
fclose($stream);
|
2013-08-09 19:24:58 +00:00
|
|
|
throw $e;
|
|
|
|
}
|
2013-08-15 17:16:15 +00:00
|
|
|
fclose($stream);
|
2013-08-09 19:24:58 +00:00
|
|
|
}
|
|
|
|
|
2022-02-18 09:38:54 +00:00
|
|
|
public function testIsLoggedIn(): void
|
2013-09-04 14:24:49 +00:00
|
|
|
{
|
2021-12-09 21:14:04 +00:00
|
|
|
$this->processExecutor->expects(
|
|
|
|
[['cmd' => 'p4 -u user -p port login -s']],
|
|
|
|
true
|
|
|
|
);
|
2013-08-15 17:16:15 +00:00
|
|
|
$this->perforce->isLoggedIn();
|
2013-08-09 19:24:58 +00:00
|
|
|
}
|
|
|
|
|
2022-02-18 09:38:54 +00:00
|
|
|
public function testConnectClient(): void
|
2013-09-04 14:24:49 +00:00
|
|
|
{
|
2021-12-09 21:14:04 +00:00
|
|
|
$this->processExecutor->expects(
|
|
|
|
['p4 -u user -c composer_perforce_TEST_depot -p port client -i < path/composer_perforce_TEST_depot.p4.spec'],
|
|
|
|
true
|
|
|
|
);
|
2013-08-09 19:24:58 +00:00
|
|
|
|
|
|
|
$this->perforce->connectClient();
|
|
|
|
}
|
|
|
|
|
2022-02-18 09:38:54 +00:00
|
|
|
public function testGetBranchesWithStream(): void
|
2013-09-04 14:24:49 +00:00
|
|
|
{
|
2013-08-15 17:16:15 +00:00
|
|
|
$this->setPerforceToStream();
|
|
|
|
|
2021-12-09 21:14:04 +00:00
|
|
|
$this->processExecutor->expects(
|
|
|
|
[
|
|
|
|
[
|
|
|
|
'cmd' => 'p4 -u user -c composer_perforce_TEST_depot_branch -p port streams '.ProcessExecutor::escape('//depot/...'),
|
2022-02-18 07:50:11 +00:00
|
|
|
'stdout' => 'Stream //depot/branch mainline none \'branch\'' . PHP_EOL,
|
2021-12-09 21:14:04 +00:00
|
|
|
],
|
|
|
|
[
|
|
|
|
'cmd' => 'p4 -u user -p port changes '.ProcessExecutor::escape('//depot/branch/...'),
|
2022-02-18 07:50:11 +00:00
|
|
|
'stdout' => 'Change 1234 on 2014/03/19 by Clark.Stuth@Clark.Stuth_test_client \'test changelist\'',
|
2021-12-09 21:14:04 +00:00
|
|
|
],
|
|
|
|
],
|
|
|
|
true
|
|
|
|
);
|
2013-08-09 19:24:58 +00:00
|
|
|
|
|
|
|
$branches = $this->perforce->getBranches();
|
2014-03-21 18:42:00 +00:00
|
|
|
$this->assertEquals('//depot/branch@1234', $branches['master']);
|
2013-08-09 19:24:58 +00:00
|
|
|
}
|
|
|
|
|
2022-02-18 09:38:54 +00:00
|
|
|
public function testGetBranchesWithoutStream(): void
|
2013-09-04 14:24:49 +00:00
|
|
|
{
|
2021-12-09 21:14:04 +00:00
|
|
|
$this->processExecutor->expects(
|
|
|
|
[
|
|
|
|
[
|
|
|
|
'cmd' => 'p4 -u user -p port changes '.ProcessExecutor::escape('//depot/...'),
|
2022-02-18 07:50:11 +00:00
|
|
|
'stdout' => 'Change 5678 on 2014/03/19 by Clark.Stuth@Clark.Stuth_test_client \'test changelist\'',
|
2021-12-09 21:14:04 +00:00
|
|
|
],
|
|
|
|
],
|
|
|
|
true
|
|
|
|
);
|
2014-06-10 14:02:44 +00:00
|
|
|
|
2013-08-09 19:24:58 +00:00
|
|
|
$branches = $this->perforce->getBranches();
|
2014-03-21 18:42:00 +00:00
|
|
|
$this->assertEquals('//depot@5678', $branches['master']);
|
2013-08-09 19:24:58 +00:00
|
|
|
}
|
|
|
|
|
2022-02-18 09:38:54 +00:00
|
|
|
public function testGetTagsWithoutStream(): void
|
2013-09-04 14:24:49 +00:00
|
|
|
{
|
2021-12-09 21:14:04 +00:00
|
|
|
$this->processExecutor->expects(
|
|
|
|
[
|
|
|
|
[
|
|
|
|
'cmd' => 'p4 -u user -c composer_perforce_TEST_depot -p port labels',
|
2022-02-18 07:50:11 +00:00
|
|
|
'stdout' => 'Label 0.0.1 2013/07/31 \'First Label!\'' . PHP_EOL . 'Label 0.0.2 2013/08/01 \'Second Label!\'' . PHP_EOL,
|
2021-12-09 21:14:04 +00:00
|
|
|
],
|
|
|
|
],
|
|
|
|
true
|
|
|
|
);
|
2013-08-09 19:24:58 +00:00
|
|
|
|
|
|
|
$tags = $this->perforce->getTags();
|
2013-09-09 19:48:24 +00:00
|
|
|
$this->assertEquals('//depot@0.0.1', $tags['0.0.1']);
|
|
|
|
$this->assertEquals('//depot@0.0.2', $tags['0.0.2']);
|
2013-08-09 19:24:58 +00:00
|
|
|
}
|
|
|
|
|
2022-02-18 09:38:54 +00:00
|
|
|
public function testGetTagsWithStream(): void
|
2013-09-04 14:24:49 +00:00
|
|
|
{
|
2013-08-15 17:16:15 +00:00
|
|
|
$this->setPerforceToStream();
|
|
|
|
|
2021-12-09 21:14:04 +00:00
|
|
|
$this->processExecutor->expects(
|
|
|
|
[
|
|
|
|
[
|
|
|
|
'cmd' => 'p4 -u user -c composer_perforce_TEST_depot_branch -p port labels',
|
2022-02-18 07:50:11 +00:00
|
|
|
'stdout' => 'Label 0.0.1 2013/07/31 \'First Label!\'' . PHP_EOL . 'Label 0.0.2 2013/08/01 \'Second Label!\'' . PHP_EOL,
|
2021-12-09 21:14:04 +00:00
|
|
|
],
|
|
|
|
],
|
|
|
|
true
|
|
|
|
);
|
2013-08-09 19:24:58 +00:00
|
|
|
|
|
|
|
$tags = $this->perforce->getTags();
|
2013-09-09 19:48:24 +00:00
|
|
|
$this->assertEquals('//depot/branch@0.0.1', $tags['0.0.1']);
|
|
|
|
$this->assertEquals('//depot/branch@0.0.2', $tags['0.0.2']);
|
2013-08-09 19:24:58 +00:00
|
|
|
}
|
|
|
|
|
2022-02-18 09:38:54 +00:00
|
|
|
public function testCheckStreamWithoutStream(): void
|
2013-09-04 14:24:49 +00:00
|
|
|
{
|
2021-10-27 14:18:46 +00:00
|
|
|
$result = $this->perforce->checkStream();
|
2013-08-09 19:24:58 +00:00
|
|
|
$this->assertFalse($result);
|
2013-08-15 17:16:15 +00:00
|
|
|
$this->assertFalse($this->perforce->isStream());
|
2013-08-09 19:24:58 +00:00
|
|
|
}
|
|
|
|
|
2022-02-18 09:38:54 +00:00
|
|
|
public function testCheckStreamWithStream(): void
|
2013-09-04 14:24:49 +00:00
|
|
|
{
|
2021-12-09 21:14:04 +00:00
|
|
|
$this->processExecutor->expects(
|
|
|
|
[
|
|
|
|
[
|
|
|
|
'cmd' => 'p4 -u user -p port depots',
|
2022-02-18 07:50:11 +00:00
|
|
|
'stdout' => 'Depot depot 2013/06/25 stream /p4/1/depots/depot/... \'Created by Me\'',
|
2021-12-09 21:14:04 +00:00
|
|
|
],
|
|
|
|
],
|
|
|
|
true
|
|
|
|
);
|
2013-10-11 23:21:34 +00:00
|
|
|
|
2021-10-27 14:18:46 +00:00
|
|
|
$result = $this->perforce->checkStream();
|
2013-08-15 17:16:15 +00:00
|
|
|
$this->assertTrue($result);
|
|
|
|
$this->assertTrue($this->perforce->isStream());
|
2013-08-09 19:24:58 +00:00
|
|
|
}
|
|
|
|
|
2022-02-18 09:38:54 +00:00
|
|
|
public function testGetComposerInformationWithoutLabelWithoutStream(): void
|
2013-09-04 14:24:49 +00:00
|
|
|
{
|
2021-12-09 21:14:04 +00:00
|
|
|
$this->processExecutor->expects(
|
|
|
|
[
|
|
|
|
[
|
|
|
|
'cmd' => 'p4 -u user -c composer_perforce_TEST_depot -p port print '.ProcessExecutor::escape('//depot/composer.json'),
|
2022-02-18 07:50:11 +00:00
|
|
|
'stdout' => PerforceTest::getComposerJson(),
|
2021-12-09 21:14:04 +00:00
|
|
|
],
|
|
|
|
],
|
|
|
|
true
|
|
|
|
);
|
2013-08-09 19:24:58 +00:00
|
|
|
|
2013-09-09 19:48:24 +00:00
|
|
|
$result = $this->perforce->getComposerInformation('//depot');
|
2013-08-09 19:24:58 +00:00
|
|
|
$expected = array(
|
2017-03-08 14:07:29 +00:00
|
|
|
'name' => 'test/perforce',
|
|
|
|
'description' => 'Basic project for testing',
|
2013-09-09 19:48:24 +00:00
|
|
|
'minimum-stability' => 'dev',
|
2017-03-08 14:07:29 +00:00
|
|
|
'autoload' => array('psr-0' => array()),
|
2013-08-09 19:24:58 +00:00
|
|
|
);
|
|
|
|
$this->assertEquals($expected, $result);
|
|
|
|
}
|
|
|
|
|
2022-02-18 09:38:54 +00:00
|
|
|
public function testGetComposerInformationWithLabelWithoutStream(): void
|
2013-09-04 14:24:49 +00:00
|
|
|
{
|
2021-12-09 21:14:04 +00:00
|
|
|
$this->processExecutor->expects(
|
|
|
|
[
|
|
|
|
[
|
|
|
|
'cmd' => 'p4 -u user -p port files '.ProcessExecutor::escape('//depot/composer.json@0.0.1'),
|
2022-02-18 07:50:11 +00:00
|
|
|
'stdout' => '//depot/composer.json#1 - branch change 10001 (text)',
|
2021-12-09 21:14:04 +00:00
|
|
|
],
|
|
|
|
[
|
|
|
|
'cmd' => 'p4 -u user -c composer_perforce_TEST_depot -p port print '.ProcessExecutor::escape('//depot/composer.json@10001'),
|
2022-02-18 07:50:11 +00:00
|
|
|
'stdout' => PerforceTest::getComposerJson(),
|
2021-12-09 21:14:04 +00:00
|
|
|
],
|
|
|
|
],
|
|
|
|
true
|
|
|
|
);
|
2013-08-09 19:24:58 +00:00
|
|
|
|
2013-09-09 19:48:24 +00:00
|
|
|
$result = $this->perforce->getComposerInformation('//depot@0.0.1');
|
2013-08-09 19:24:58 +00:00
|
|
|
|
|
|
|
$expected = array(
|
2017-03-08 14:07:29 +00:00
|
|
|
'name' => 'test/perforce',
|
|
|
|
'description' => 'Basic project for testing',
|
2013-09-09 19:48:24 +00:00
|
|
|
'minimum-stability' => 'dev',
|
2017-03-08 14:07:29 +00:00
|
|
|
'autoload' => array('psr-0' => array()),
|
2013-08-09 19:24:58 +00:00
|
|
|
);
|
|
|
|
$this->assertEquals($expected, $result);
|
|
|
|
}
|
|
|
|
|
2022-02-18 09:38:54 +00:00
|
|
|
public function testGetComposerInformationWithoutLabelWithStream(): void
|
2013-09-04 14:24:49 +00:00
|
|
|
{
|
2013-08-15 17:16:15 +00:00
|
|
|
$this->setPerforceToStream();
|
|
|
|
|
2021-12-09 21:14:04 +00:00
|
|
|
$this->processExecutor->expects(
|
|
|
|
[
|
|
|
|
[
|
|
|
|
'cmd' => 'p4 -u user -c composer_perforce_TEST_depot_branch -p port print '.ProcessExecutor::escape('//depot/branch/composer.json'),
|
2022-02-18 07:50:11 +00:00
|
|
|
'stdout' => PerforceTest::getComposerJson(),
|
2021-12-09 21:14:04 +00:00
|
|
|
],
|
|
|
|
],
|
|
|
|
true
|
|
|
|
);
|
2013-08-09 19:24:58 +00:00
|
|
|
|
2013-09-09 19:48:24 +00:00
|
|
|
$result = $this->perforce->getComposerInformation('//depot/branch');
|
2013-08-09 19:24:58 +00:00
|
|
|
|
|
|
|
$expected = array(
|
2017-03-08 14:07:29 +00:00
|
|
|
'name' => 'test/perforce',
|
|
|
|
'description' => 'Basic project for testing',
|
2013-09-09 19:48:24 +00:00
|
|
|
'minimum-stability' => 'dev',
|
2017-03-08 14:07:29 +00:00
|
|
|
'autoload' => array('psr-0' => array()),
|
2013-08-09 19:24:58 +00:00
|
|
|
);
|
|
|
|
$this->assertEquals($expected, $result);
|
|
|
|
}
|
|
|
|
|
2022-02-18 09:38:54 +00:00
|
|
|
public function testGetComposerInformationWithLabelWithStream(): void
|
2013-09-04 14:24:49 +00:00
|
|
|
{
|
2021-12-09 21:14:04 +00:00
|
|
|
$this->processExecutor->expects(
|
|
|
|
[
|
|
|
|
[
|
|
|
|
'cmd' => 'p4 -u user -p port files '.ProcessExecutor::escape('//depot/branch/composer.json@0.0.1'),
|
|
|
|
'stdout' => '//depot/composer.json#1 - branch change 10001 (text)',
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'cmd' => 'p4 -u user -c composer_perforce_TEST_depot_branch -p port print '.ProcessExecutor::escape('//depot/branch/composer.json@10001'),
|
|
|
|
'stdout' => PerforceTest::getComposerJson(),
|
|
|
|
],
|
|
|
|
],
|
|
|
|
true
|
|
|
|
);
|
2013-08-09 19:24:58 +00:00
|
|
|
|
2021-12-09 16:09:07 +00:00
|
|
|
$this->setPerforceToStream();
|
2013-08-09 19:24:58 +00:00
|
|
|
|
2013-09-09 19:48:24 +00:00
|
|
|
$result = $this->perforce->getComposerInformation('//depot/branch@0.0.1');
|
2013-08-09 19:24:58 +00:00
|
|
|
|
|
|
|
$expected = array(
|
2017-03-08 14:07:29 +00:00
|
|
|
'name' => 'test/perforce',
|
|
|
|
'description' => 'Basic project for testing',
|
2013-09-09 19:48:24 +00:00
|
|
|
'minimum-stability' => 'dev',
|
2017-03-08 14:07:29 +00:00
|
|
|
'autoload' => array('psr-0' => array()),
|
2013-08-09 19:24:58 +00:00
|
|
|
);
|
|
|
|
$this->assertEquals($expected, $result);
|
|
|
|
}
|
|
|
|
|
2022-02-18 09:38:54 +00:00
|
|
|
public function testSyncCodeBaseWithoutStream(): void
|
2013-09-04 14:24:49 +00:00
|
|
|
{
|
2021-12-09 21:14:04 +00:00
|
|
|
$this->processExecutor->expects(
|
|
|
|
['p4 -u user -c composer_perforce_TEST_depot -p port sync -f @label'],
|
|
|
|
true
|
|
|
|
);
|
2013-08-09 19:24:58 +00:00
|
|
|
|
2013-09-09 19:48:24 +00:00
|
|
|
$this->perforce->syncCodeBase('label');
|
2013-08-09 19:24:58 +00:00
|
|
|
}
|
|
|
|
|
2022-02-18 09:38:54 +00:00
|
|
|
public function testSyncCodeBaseWithStream(): void
|
2013-09-04 14:24:49 +00:00
|
|
|
{
|
2013-08-15 17:16:15 +00:00
|
|
|
$this->setPerforceToStream();
|
2021-12-09 21:14:04 +00:00
|
|
|
|
|
|
|
$this->processExecutor->expects(
|
|
|
|
['p4 -u user -c composer_perforce_TEST_depot_branch -p port sync -f @label'],
|
|
|
|
true
|
|
|
|
);
|
2013-08-09 19:24:58 +00:00
|
|
|
|
2013-09-09 19:48:24 +00:00
|
|
|
$this->perforce->syncCodeBase('label');
|
2013-08-09 19:24:58 +00:00
|
|
|
}
|
|
|
|
|
2022-02-18 09:38:54 +00:00
|
|
|
public function testCheckServerExists(): void
|
2013-09-04 14:24:49 +00:00
|
|
|
{
|
2021-12-09 21:14:04 +00:00
|
|
|
$this->processExecutor->expects(
|
|
|
|
['p4 -p '.ProcessExecutor::escape('perforce.does.exist:port').' info -s'],
|
|
|
|
true
|
|
|
|
);
|
2013-08-09 19:24:58 +00:00
|
|
|
|
2021-12-09 21:14:04 +00:00
|
|
|
$result = $this->perforce->checkServerExists('perforce.does.exist:port', $this->processExecutor);
|
2013-08-09 19:24:58 +00:00
|
|
|
$this->assertTrue($result);
|
|
|
|
}
|
2014-06-10 14:02:44 +00:00
|
|
|
|
2013-10-14 12:53:57 +00:00
|
|
|
/**
|
|
|
|
* Test if "p4" command is missing.
|
2014-06-10 14:02:44 +00:00
|
|
|
*
|
2013-10-14 12:53:57 +00:00
|
|
|
* @covers \Composer\Util\Perforce::checkServerExists
|
2014-06-10 14:02:44 +00:00
|
|
|
*
|
2013-10-14 12:53:57 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
2022-02-18 09:38:54 +00:00
|
|
|
public function testCheckServerClientError(): void
|
2013-10-14 12:53:57 +00:00
|
|
|
{
|
2018-04-12 08:24:56 +00:00
|
|
|
$processExecutor = $this->getMockBuilder('Composer\Util\ProcessExecutor')->getMock();
|
2013-10-14 12:53:57 +00:00
|
|
|
|
2018-08-25 15:45:08 +00:00
|
|
|
$expectedCommand = 'p4 -p '.ProcessExecutor::escape('perforce.does.exist:port').' info -s';
|
2021-12-09 16:09:07 +00:00
|
|
|
$processExecutor->expects($this->once())
|
2013-10-14 12:53:57 +00:00
|
|
|
->method('execute')
|
2013-10-14 16:04:09 +00:00
|
|
|
->with($this->equalTo($expectedCommand), $this->equalTo(null))
|
2021-12-09 16:09:07 +00:00
|
|
|
->willReturn(127);
|
2014-06-10 14:02:44 +00:00
|
|
|
|
2013-10-14 12:53:57 +00:00
|
|
|
$result = $this->perforce->checkServerExists('perforce.does.exist:port', $processExecutor);
|
|
|
|
$this->assertFalse($result);
|
|
|
|
}
|
2013-08-09 19:24:58 +00:00
|
|
|
|
2021-10-27 14:18:46 +00:00
|
|
|
/**
|
|
|
|
* @return string
|
|
|
|
*/
|
2022-02-18 10:22:01 +00:00
|
|
|
public static function getComposerJson(): string
|
2013-09-04 14:24:49 +00:00
|
|
|
{
|
2021-12-09 16:09:07 +00:00
|
|
|
return JsonFile::encode([
|
|
|
|
'name' => 'test/perforce',
|
|
|
|
'description' => 'Basic project for testing',
|
|
|
|
'minimum-stability' => 'dev',
|
|
|
|
'autoload' => [
|
2022-02-18 07:50:11 +00:00
|
|
|
'psr-0' => [],
|
|
|
|
],
|
2021-12-09 16:09:07 +00:00
|
|
|
], JSON_FORCE_OBJECT);
|
2013-08-09 19:24:58 +00:00
|
|
|
}
|
|
|
|
|
2021-10-27 14:18:46 +00:00
|
|
|
/**
|
|
|
|
* @param bool $withStream
|
|
|
|
*
|
|
|
|
* @return string[]
|
|
|
|
*/
|
2022-02-18 10:22:01 +00:00
|
|
|
private function getExpectedClientSpec($withStream): array
|
2013-09-04 14:24:49 +00:00
|
|
|
{
|
2013-08-09 19:24:58 +00:00
|
|
|
$expectedArray = array(
|
2013-09-09 19:48:24 +00:00
|
|
|
'Client: composer_perforce_TEST_depot',
|
|
|
|
PHP_EOL,
|
|
|
|
'Update:',
|
|
|
|
PHP_EOL,
|
|
|
|
'Access:',
|
|
|
|
'Owner: user',
|
|
|
|
PHP_EOL,
|
|
|
|
'Description:',
|
|
|
|
' Created by user from composer.',
|
|
|
|
PHP_EOL,
|
|
|
|
'Root: path',
|
|
|
|
PHP_EOL,
|
|
|
|
'Options: noallwrite noclobber nocompress unlocked modtime rmdir',
|
|
|
|
PHP_EOL,
|
|
|
|
'SubmitOptions: revertunchanged',
|
|
|
|
PHP_EOL,
|
|
|
|
'LineEnd: local',
|
2015-09-28 09:51:14 +00:00
|
|
|
PHP_EOL,
|
2013-08-09 19:24:58 +00:00
|
|
|
);
|
|
|
|
if ($withStream) {
|
2013-09-09 19:48:24 +00:00
|
|
|
$expectedArray[] = 'Stream:';
|
|
|
|
$expectedArray[] = ' //depot/branch';
|
2013-09-04 14:24:49 +00:00
|
|
|
} else {
|
2013-09-13 20:01:00 +00:00
|
|
|
$expectedArray[] = 'View: //depot/... //composer_perforce_TEST_depot/...';
|
2013-08-09 19:24:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return $expectedArray;
|
|
|
|
}
|
|
|
|
|
2021-10-27 14:18:46 +00:00
|
|
|
/**
|
|
|
|
* @return void
|
|
|
|
*/
|
2022-02-18 09:38:54 +00:00
|
|
|
private function setPerforceToStream(): void
|
2013-09-04 14:24:49 +00:00
|
|
|
{
|
2013-09-09 19:48:24 +00:00
|
|
|
$this->perforce->setStream('//depot/branch');
|
2013-08-09 19:24:58 +00:00
|
|
|
}
|
2014-03-18 19:39:47 +00:00
|
|
|
|
2022-02-18 09:38:54 +00:00
|
|
|
public function testCleanupClientSpecShouldDeleteClient(): void
|
2014-03-18 19:39:47 +00:00
|
|
|
{
|
2018-04-12 08:24:56 +00:00
|
|
|
$fs = $this->getMockBuilder('Composer\Util\Filesystem')->getMock();
|
2014-03-18 19:39:47 +00:00
|
|
|
$this->perforce->setFilesystem($fs);
|
|
|
|
|
|
|
|
$testClient = $this->perforce->getClient();
|
2021-12-09 21:14:04 +00:00
|
|
|
$this->processExecutor->expects(
|
|
|
|
['p4 -u ' . self::TEST_P4USER . ' -p ' . self::TEST_PORT . ' client -d ' . ProcessExecutor::escape($testClient)],
|
|
|
|
true
|
|
|
|
);
|
2014-03-18 19:39:47 +00:00
|
|
|
|
|
|
|
$fs->expects($this->once())->method('remove')->with($this->perforce->getP4ClientSpec());
|
|
|
|
|
|
|
|
$this->perforce->cleanupClientSpec();
|
|
|
|
}
|
2013-08-09 19:24:58 +00:00
|
|
|
}
|