2013-08-09 19:24:58 +00:00
|
|
|
<?php
|
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
|
|
|
*/
|
|
|
|
|
2013-08-15 17:16:15 +00:00
|
|
|
|
2013-08-09 19:24:58 +00:00
|
|
|
namespace Composer\Test\Util;
|
|
|
|
|
2013-08-15 17:16:15 +00:00
|
|
|
use Composer\Util\Perforce;
|
2013-08-09 19:24:58 +00:00
|
|
|
use Composer\Util\ProcessExecutor;
|
|
|
|
|
2013-08-15 17:16:15 +00:00
|
|
|
/**
|
|
|
|
* @author Matt Whittom <Matt.Whittom@veteransunited.com>
|
|
|
|
*/
|
2013-09-04 14:24:49 +00:00
|
|
|
class PerforceTest extends \PHPUnit_Framework_TestCase
|
|
|
|
{
|
2013-08-09 19:24:58 +00:00
|
|
|
|
|
|
|
protected $perforce;
|
|
|
|
protected $processExecutor;
|
|
|
|
|
2013-09-04 14:24:49 +00:00
|
|
|
public function setUp()
|
|
|
|
{
|
2013-08-09 19:24:58 +00:00
|
|
|
$this->processExecutor = $this->getMock('Composer\Util\ProcessExecutor');
|
2013-09-04 14:24:49 +00:00
|
|
|
$repoConfig = array(
|
|
|
|
"depot" => "depot",
|
|
|
|
"branch" => "branch",
|
|
|
|
"p4user" => "user",
|
|
|
|
"unique_perforce_client_name" => "TEST"
|
|
|
|
);
|
2013-08-22 14:49:22 +00:00
|
|
|
$this->perforce = new Perforce($repoConfig, "port", "path", $this->processExecutor, true);
|
2013-08-09 19:24:58 +00:00
|
|
|
}
|
|
|
|
|
2013-09-04 14:24:49 +00:00
|
|
|
public function testGetClientWithoutStream()
|
|
|
|
{
|
2013-08-15 17:16:15 +00:00
|
|
|
$client = $this->perforce->getClient();
|
|
|
|
$hostname = gethostname();
|
|
|
|
$timestamp = time();
|
|
|
|
|
2013-08-09 19:24:58 +00:00
|
|
|
$expected = "composer_perforce_TEST_depot";
|
|
|
|
$this->assertEquals($expected, $client);
|
|
|
|
}
|
|
|
|
|
2013-09-04 14:24:49 +00:00
|
|
|
public function testGetClientFromStream()
|
|
|
|
{
|
2013-08-15 17:16:15 +00:00
|
|
|
$this->setPerforceToStream();
|
|
|
|
|
|
|
|
$client = $this->perforce->getClient();
|
2013-08-09 19:24:58 +00:00
|
|
|
|
|
|
|
$expected = "composer_perforce_TEST_depot_branch";
|
|
|
|
$this->assertEquals($expected, $client);
|
|
|
|
}
|
|
|
|
|
2013-09-04 14:24:49 +00:00
|
|
|
public function testGetStreamWithoutStream()
|
|
|
|
{
|
2013-08-15 17:16:15 +00:00
|
|
|
$stream = $this->perforce->getStream();
|
2013-08-09 19:24:58 +00:00
|
|
|
$this->assertEquals("//depot", $stream);
|
|
|
|
}
|
|
|
|
|
2013-09-04 14:24:49 +00:00
|
|
|
public function testGetStreamWithStream()
|
|
|
|
{
|
2013-08-15 17:16:15 +00:00
|
|
|
$this->setPerforceToStream();
|
|
|
|
|
|
|
|
$stream = $this->perforce->getStream();
|
2013-08-09 19:24:58 +00:00
|
|
|
$this->assertEquals("//depot/branch", $stream);
|
|
|
|
}
|
|
|
|
|
2013-08-15 17:16:15 +00:00
|
|
|
|
2013-09-04 14:24:49 +00:00
|
|
|
public function testGetStreamWithoutLabelWithStreamWithoutLabel()
|
|
|
|
{
|
2013-08-15 17:16:15 +00:00
|
|
|
$stream = $this->perforce->getStreamWithoutLabel("//depot/branch");
|
2013-08-09 19:24:58 +00:00
|
|
|
$this->assertEquals("//depot/branch", $stream);
|
2013-08-15 17:16:15 +00:00
|
|
|
}
|
|
|
|
|
2013-09-04 14:24:49 +00:00
|
|
|
public function testGetStreamWithoutLabelWithStreamWithLabel()
|
|
|
|
{
|
2013-08-15 17:16:15 +00:00
|
|
|
$stream = $this->perforce->getStreamWithoutLabel("//depot/branching@label");
|
2013-08-09 19:24:58 +00:00
|
|
|
$this->assertEquals("//depot/branching", $stream);
|
|
|
|
}
|
|
|
|
|
2013-09-04 14:24:49 +00:00
|
|
|
public function testGetClientSpec()
|
|
|
|
{
|
2013-08-15 17:16:15 +00:00
|
|
|
$clientSpec = $this->perforce->getP4ClientSpec();
|
2013-08-09 19:24:58 +00:00
|
|
|
$expected = "path/composer_perforce_TEST_depot.p4.spec";
|
|
|
|
$this->assertEquals($expected, $clientSpec);
|
|
|
|
}
|
|
|
|
|
2013-09-04 14:24:49 +00:00
|
|
|
public function testGenerateP4Command()
|
|
|
|
{
|
2013-08-09 19:24:58 +00:00
|
|
|
$command = "do something";
|
2013-08-15 17:16:15 +00:00
|
|
|
$p4Command = $this->perforce->generateP4Command($command);
|
2013-08-09 19:24:58 +00:00
|
|
|
$expected = "p4 -u user -c composer_perforce_TEST_depot -p port do something";
|
|
|
|
$this->assertEquals($expected, $p4Command);
|
|
|
|
}
|
|
|
|
|
2013-09-04 14:24:49 +00:00
|
|
|
public function testQueryP4UserWithUserAlreadySet()
|
|
|
|
{
|
2013-08-09 19:24:58 +00:00
|
|
|
$io = $this->getMock('Composer\IO\IOInterface');
|
|
|
|
|
2013-09-04 14:24:49 +00:00
|
|
|
$repoConfig = array("depot" => "depot", "branch" => "branch", "p4user" => "TEST_USER");
|
2013-08-15 17:16:15 +00:00
|
|
|
$this->perforce = new Perforce($repoConfig, "port", "path", $this->processExecutor, true, "TEST");
|
|
|
|
|
2013-08-09 19:24:58 +00:00
|
|
|
$this->perforce->queryP4user($io);
|
|
|
|
$this->assertEquals("TEST_USER", $this->perforce->getUser());
|
|
|
|
}
|
|
|
|
|
2013-09-04 14:24:49 +00:00
|
|
|
public function testQueryP4UserWithUserSetInP4VariablesWithWindowsOS()
|
|
|
|
{
|
|
|
|
$repoConfig = array("depot" => "depot", "branch" => "branch");
|
2013-08-15 17:16:15 +00:00
|
|
|
$this->perforce = new Perforce($repoConfig, "port", "path", $this->processExecutor, true, "TEST");
|
2013-08-09 19:24:58 +00:00
|
|
|
|
|
|
|
$io = $this->getMock('Composer\IO\IOInterface');
|
|
|
|
$expectedCommand = "p4 set";
|
|
|
|
$this->processExecutor->expects($this->at(0))
|
2013-09-04 14:24:49 +00:00
|
|
|
->method('execute')
|
|
|
|
->with($this->equalTo($expectedCommand))
|
|
|
|
->will(
|
2013-09-06 17:14:22 +00:00
|
|
|
$this->returnCallback(
|
|
|
|
function ($command, &$output) {
|
|
|
|
$output = "P4USER=TEST_P4VARIABLE_USER\n";
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
)
|
|
|
|
);
|
2013-08-09 19:24:58 +00:00
|
|
|
|
|
|
|
$this->perforce->queryP4user($io);
|
|
|
|
$this->assertEquals("TEST_P4VARIABLE_USER", $this->perforce->getUser());
|
|
|
|
}
|
|
|
|
|
2013-09-04 14:24:49 +00:00
|
|
|
public function testQueryP4UserWithUserSetInP4VariablesNotWindowsOS()
|
|
|
|
{
|
|
|
|
$repoConfig = array("depot" => "depot", "branch" => "branch");
|
2013-08-15 17:16:15 +00:00
|
|
|
$this->perforce = new Perforce($repoConfig, "port", "path", $this->processExecutor, false, "TEST");
|
2013-08-09 19:24:58 +00:00
|
|
|
|
|
|
|
$io = $this->getMock('Composer\IO\IOInterface');
|
|
|
|
$expectedCommand = 'echo $P4USER';
|
|
|
|
$this->processExecutor->expects($this->at(0))
|
|
|
|
->method('execute')
|
|
|
|
->with($this->equalTo($expectedCommand))
|
2013-09-04 14:24:49 +00:00
|
|
|
->will(
|
2013-09-06 17:14:22 +00:00
|
|
|
$this->returnCallback(
|
|
|
|
function ($command, &$output) {
|
|
|
|
$output = "TEST_P4VARIABLE_USER\n";
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
)
|
|
|
|
);
|
2013-08-09 19:24:58 +00:00
|
|
|
|
|
|
|
$this->perforce->queryP4user($io);
|
|
|
|
$this->assertEquals("TEST_P4VARIABLE_USER", $this->perforce->getUser());
|
|
|
|
}
|
|
|
|
|
2013-09-04 14:24:49 +00:00
|
|
|
public function testQueryP4UserQueriesForUser()
|
|
|
|
{
|
|
|
|
$repoConfig = array("depot" => "depot", "branch" => "branch");
|
2013-08-15 17:16:15 +00:00
|
|
|
$this->perforce = new Perforce($repoConfig, "port", "path", $this->processExecutor, false, "TEST");
|
2013-08-09 19:24:58 +00:00
|
|
|
$io = $this->getMock('Composer\IO\IOInterface');
|
|
|
|
$expectedQuestion = "Enter P4 User:";
|
|
|
|
$io->expects($this->at(0))
|
2013-09-04 14:24:49 +00:00
|
|
|
->method('ask')
|
|
|
|
->with($this->equalTo($expectedQuestion))
|
|
|
|
->will($this->returnValue("TEST_QUERY_USER"));
|
2013-08-09 19:24:58 +00:00
|
|
|
|
|
|
|
$this->perforce->queryP4user($io);
|
|
|
|
$this->assertEquals("TEST_QUERY_USER", $this->perforce->getUser());
|
|
|
|
}
|
|
|
|
|
2013-09-04 14:24:49 +00:00
|
|
|
public function testQueryP4UserStoresResponseToQueryForUserWithWindows()
|
|
|
|
{
|
|
|
|
$repoConfig = array("depot" => "depot", "branch" => "branch");
|
2013-08-15 17:16:15 +00:00
|
|
|
$this->perforce = new Perforce($repoConfig, "port", "path", $this->processExecutor, true, "TEST");
|
2013-08-09 19:24:58 +00:00
|
|
|
|
|
|
|
$io = $this->getMock('Composer\IO\IOInterface');
|
|
|
|
$expectedQuestion = "Enter P4 User:";
|
|
|
|
$io->expects($this->at(0))
|
2013-09-04 14:24:49 +00:00
|
|
|
->method('ask')
|
|
|
|
->with($this->equalTo($expectedQuestion))
|
|
|
|
->will($this->returnValue("TEST_QUERY_USER"));
|
2013-08-09 19:24:58 +00:00
|
|
|
$expectedCommand = "p4 set P4USER=TEST_QUERY_USER";
|
|
|
|
$this->processExecutor->expects($this->at(1))
|
2013-09-04 14:24:49 +00:00
|
|
|
->method('execute')
|
|
|
|
->with($this->equalTo($expectedCommand))
|
|
|
|
->will($this->returnValue(0));
|
2013-08-09 19:24:58 +00:00
|
|
|
|
|
|
|
$this->perforce->queryP4user($io);
|
|
|
|
}
|
|
|
|
|
2013-09-04 14:24:49 +00:00
|
|
|
public function testQueryP4UserStoresResponseToQueryForUserWithoutWindows()
|
|
|
|
{
|
|
|
|
$repoConfig = array("depot" => "depot", "branch" => "branch");
|
2013-08-15 17:16:15 +00:00
|
|
|
$this->perforce = new Perforce($repoConfig, "port", "path", $this->processExecutor, false, "TEST");
|
2013-08-09 19:24:58 +00:00
|
|
|
|
|
|
|
$io = $this->getMock('Composer\IO\IOInterface');
|
|
|
|
$expectedQuestion = "Enter P4 User:";
|
|
|
|
$io->expects($this->at(0))
|
|
|
|
->method('ask')
|
|
|
|
->with($this->equalTo($expectedQuestion))
|
|
|
|
->will($this->returnValue("TEST_QUERY_USER"));
|
|
|
|
$expectedCommand = "export P4USER=TEST_QUERY_USER";
|
|
|
|
$this->processExecutor->expects($this->at(1))
|
|
|
|
->method('execute')
|
|
|
|
->with($this->equalTo($expectedCommand))
|
|
|
|
->will($this->returnValue(0));
|
|
|
|
|
|
|
|
$this->perforce->queryP4user($io);
|
|
|
|
}
|
|
|
|
|
2013-09-04 14:24:49 +00:00
|
|
|
public function testQueryP4PasswordWithPasswordAlreadySet()
|
|
|
|
{
|
|
|
|
$repoConfig = array(
|
|
|
|
"depot" => "depot",
|
|
|
|
"branch" => "branch",
|
|
|
|
"p4user" => "user",
|
|
|
|
"p4password" => "TEST_PASSWORD"
|
|
|
|
);
|
2013-08-15 17:16:15 +00:00
|
|
|
$this->perforce = new Perforce($repoConfig, "port", "path", $this->processExecutor, false, "TEST");
|
2013-08-09 19:24:58 +00:00
|
|
|
$io = $this->getMock('Composer\IO\IOInterface');
|
|
|
|
|
2013-08-15 17:16:15 +00:00
|
|
|
$password = $this->perforce->queryP4Password($io);
|
2013-08-09 19:24:58 +00:00
|
|
|
$this->assertEquals("TEST_PASSWORD", $password);
|
|
|
|
}
|
|
|
|
|
2013-09-04 14:24:49 +00:00
|
|
|
public function testQueryP4PasswordWithPasswordSetInP4VariablesWithWindowsOS()
|
|
|
|
{
|
2013-08-09 19:24:58 +00:00
|
|
|
$io = $this->getMock('Composer\IO\IOInterface');
|
2013-08-15 17:16:15 +00:00
|
|
|
|
2013-08-09 19:24:58 +00:00
|
|
|
$expectedCommand = "p4 set";
|
|
|
|
$this->processExecutor->expects($this->at(0))
|
2013-09-04 14:24:49 +00:00
|
|
|
->method('execute')
|
|
|
|
->with($this->equalTo($expectedCommand))
|
|
|
|
->will(
|
2013-09-06 17:14:22 +00:00
|
|
|
$this->returnCallback(
|
|
|
|
function ($command, &$output) {
|
|
|
|
$output = "P4PASSWD=TEST_P4VARIABLE_PASSWORD\n";
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
)
|
|
|
|
);
|
2013-08-09 19:24:58 +00:00
|
|
|
|
2013-08-15 17:16:15 +00:00
|
|
|
$password = $this->perforce->queryP4Password($io);
|
2013-08-09 19:24:58 +00:00
|
|
|
$this->assertEquals("TEST_P4VARIABLE_PASSWORD", $password);
|
|
|
|
}
|
|
|
|
|
2013-09-04 14:24:49 +00:00
|
|
|
public function testQueryP4PasswordWithPasswordSetInP4VariablesNotWindowsOS()
|
|
|
|
{
|
|
|
|
$repoConfig = array("depot" => "depot", "branch" => "branch", "p4user" => "user");
|
2013-08-15 17:16:15 +00:00
|
|
|
$this->perforce = new Perforce($repoConfig, "port", "path", $this->processExecutor, false, "TEST");
|
2013-08-09 19:24:58 +00:00
|
|
|
|
|
|
|
$io = $this->getMock('Composer\IO\IOInterface');
|
|
|
|
$expectedCommand = 'echo $P4PASSWD';
|
|
|
|
$this->processExecutor->expects($this->at(0))
|
|
|
|
->method('execute')
|
|
|
|
->with($this->equalTo($expectedCommand))
|
2013-09-04 14:24:49 +00:00
|
|
|
->will(
|
2013-09-06 17:14:22 +00:00
|
|
|
$this->returnCallback(
|
|
|
|
function ($command, &$output) {
|
|
|
|
$output = "TEST_P4VARIABLE_PASSWORD\n";
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
)
|
|
|
|
);
|
2013-08-09 19:24:58 +00:00
|
|
|
|
2013-08-15 17:16:15 +00:00
|
|
|
$password = $this->perforce->queryP4Password($io);
|
2013-08-09 19:24:58 +00:00
|
|
|
$this->assertEquals("TEST_P4VARIABLE_PASSWORD", $password);
|
|
|
|
}
|
|
|
|
|
2013-09-04 14:24:49 +00:00
|
|
|
public function testQueryP4PasswordQueriesForPassword()
|
|
|
|
{
|
2013-08-09 19:24:58 +00:00
|
|
|
$io = $this->getMock('Composer\IO\IOInterface');
|
|
|
|
$expectedQuestion = "Enter password for Perforce user user: ";
|
|
|
|
$io->expects($this->at(0))
|
2013-09-04 14:24:49 +00:00
|
|
|
->method('askAndHideAnswer')
|
|
|
|
->with($this->equalTo($expectedQuestion))
|
|
|
|
->will($this->returnValue("TEST_QUERY_PASSWORD"));
|
2013-08-09 19:24:58 +00:00
|
|
|
|
2013-08-15 17:16:15 +00:00
|
|
|
$password = $this->perforce->queryP4Password($io);
|
2013-08-09 19:24:58 +00:00
|
|
|
$this->assertEquals("TEST_QUERY_PASSWORD", $password);
|
|
|
|
}
|
|
|
|
|
2013-09-04 14:24:49 +00:00
|
|
|
public function testWriteP4ClientSpecWithoutStream()
|
|
|
|
{
|
2013-08-15 17:16:15 +00:00
|
|
|
$stream = fopen("php://memory", 'w+');
|
|
|
|
$this->perforce->writeClientSpecToFile($stream);
|
|
|
|
|
|
|
|
rewind($stream);
|
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));
|
2013-08-09 19:24:58 +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
|
|
|
}
|
|
|
|
|
2013-09-04 14:24:49 +00:00
|
|
|
public function testWriteP4ClientSpecWithStream()
|
|
|
|
{
|
2013-08-15 17:16:15 +00:00
|
|
|
$this->setPerforceToStream();
|
|
|
|
$stream = fopen("php://memory", 'w+');
|
|
|
|
|
|
|
|
$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));
|
2013-08-09 19:24:58 +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
|
|
|
}
|
|
|
|
|
2013-09-04 14:24:49 +00:00
|
|
|
public function testIsLoggedIn()
|
|
|
|
{
|
2013-08-15 17:16:15 +00:00
|
|
|
$expectedCommand = "p4 -u user -p port login -s";
|
2013-08-09 19:24:58 +00:00
|
|
|
$this->processExecutor->expects($this->at(0))
|
2013-09-04 14:24:49 +00:00
|
|
|
->method('execute')
|
|
|
|
->with($this->equalTo($expectedCommand), $this->equalTo(null))
|
|
|
|
->will($this->returnValue(0));
|
2013-08-09 19:24:58 +00:00
|
|
|
|
2013-08-15 17:16:15 +00:00
|
|
|
$this->perforce->isLoggedIn();
|
2013-08-09 19:24:58 +00:00
|
|
|
}
|
|
|
|
|
2013-09-04 14:24:49 +00:00
|
|
|
public function testConnectClient()
|
|
|
|
{
|
2013-08-15 17:16:15 +00:00
|
|
|
$expectedCommand = "p4 -u user -c composer_perforce_TEST_depot -p port client -i < path/composer_perforce_TEST_depot.p4.spec";
|
2013-08-09 19:24:58 +00:00
|
|
|
$this->processExecutor->expects($this->at(0))
|
|
|
|
->method('execute')
|
|
|
|
->with($this->equalTo($expectedCommand), $this->equalTo(null))
|
|
|
|
->will($this->returnValue(0));
|
|
|
|
|
|
|
|
$this->perforce->connectClient();
|
|
|
|
}
|
|
|
|
|
2013-09-04 14:24:49 +00:00
|
|
|
public function testGetBranchesWithStream()
|
|
|
|
{
|
2013-08-15 17:16:15 +00:00
|
|
|
$this->setPerforceToStream();
|
|
|
|
|
|
|
|
$expectedCommand = "p4 -u user -c composer_perforce_TEST_depot_branch -p port streams //depot/...";
|
2013-08-09 19:24:58 +00:00
|
|
|
$this->processExecutor->expects($this->at(0))
|
|
|
|
->method('execute')
|
|
|
|
->with($this->equalTo($expectedCommand))
|
2013-09-04 14:24:49 +00:00
|
|
|
->will(
|
2013-09-06 17:14:22 +00:00
|
|
|
$this->returnCallback(
|
|
|
|
function ($command, &$output) {
|
|
|
|
$output = "Stream //depot/branch mainline none 'branch'\n";
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
)
|
|
|
|
);
|
2013-08-09 19:24:58 +00:00
|
|
|
|
|
|
|
$branches = $this->perforce->getBranches();
|
|
|
|
$this->assertEquals("//depot/branch", $branches['master']);
|
|
|
|
}
|
|
|
|
|
2013-09-04 14:24:49 +00:00
|
|
|
public function testGetBranchesWithoutStream()
|
|
|
|
{
|
2013-08-09 19:24:58 +00:00
|
|
|
$branches = $this->perforce->getBranches();
|
|
|
|
$this->assertEquals("//depot", $branches['master']);
|
|
|
|
}
|
|
|
|
|
2013-09-04 14:24:49 +00:00
|
|
|
public function testGetTagsWithoutStream()
|
|
|
|
{
|
2013-08-15 17:16:15 +00:00
|
|
|
$expectedCommand = "p4 -u user -c composer_perforce_TEST_depot -p port labels";
|
2013-08-09 19:24:58 +00:00
|
|
|
$this->processExecutor->expects($this->at(0))
|
|
|
|
->method('execute')
|
|
|
|
->with($this->equalTo($expectedCommand))
|
2013-09-04 14:24:49 +00:00
|
|
|
->will(
|
2013-09-06 17:14:22 +00:00
|
|
|
$this->returnCallback(
|
|
|
|
function ($command, &$output) {
|
|
|
|
$output = "Label 0.0.1 2013/07/31 'First Label!'\nLabel 0.0.2 2013/08/01 'Second Label!'\n";
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
)
|
|
|
|
);
|
2013-08-09 19:24:58 +00:00
|
|
|
|
|
|
|
$tags = $this->perforce->getTags();
|
|
|
|
$this->assertEquals("//depot@0.0.1", $tags['0.0.1']);
|
|
|
|
$this->assertEquals("//depot@0.0.2", $tags['0.0.2']);
|
|
|
|
}
|
|
|
|
|
2013-09-04 14:24:49 +00:00
|
|
|
public function testGetTagsWithStream()
|
|
|
|
{
|
2013-08-15 17:16:15 +00:00
|
|
|
$this->setPerforceToStream();
|
|
|
|
|
|
|
|
$expectedCommand = "p4 -u user -c composer_perforce_TEST_depot_branch -p port labels";
|
2013-08-09 19:24:58 +00:00
|
|
|
$this->processExecutor->expects($this->at(0))
|
|
|
|
->method('execute')
|
|
|
|
->with($this->equalTo($expectedCommand))
|
2013-09-04 14:24:49 +00:00
|
|
|
->will(
|
2013-09-06 17:14:22 +00:00
|
|
|
$this->returnCallback(
|
|
|
|
function ($command, &$output) {
|
|
|
|
$output = "Label 0.0.1 2013/07/31 'First Label!'\nLabel 0.0.2 2013/08/01 'Second Label!'\n";
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
)
|
|
|
|
);
|
2013-08-09 19:24:58 +00:00
|
|
|
|
|
|
|
$tags = $this->perforce->getTags();
|
|
|
|
$this->assertEquals("//depot/branch@0.0.1", $tags['0.0.1']);
|
|
|
|
$this->assertEquals("//depot/branch@0.0.2", $tags['0.0.2']);
|
|
|
|
}
|
|
|
|
|
2013-09-04 14:24:49 +00:00
|
|
|
public function testCheckStreamWithoutStream()
|
|
|
|
{
|
2013-08-09 19:24:58 +00:00
|
|
|
$result = $this->perforce->checkStream("depot");
|
|
|
|
$this->assertFalse($result);
|
2013-08-15 17:16:15 +00:00
|
|
|
$this->assertFalse($this->perforce->isStream());
|
2013-08-09 19:24:58 +00:00
|
|
|
}
|
|
|
|
|
2013-09-04 14:24:49 +00:00
|
|
|
public function testCheckStreamWithStream()
|
|
|
|
{
|
2013-08-15 17:16:15 +00:00
|
|
|
$this->processExecutor->expects($this->any())->method('execute')
|
2013-09-04 14:24:49 +00:00
|
|
|
->will(
|
2013-09-06 17:14:22 +00:00
|
|
|
$this->returnCallback(
|
|
|
|
function ($command, &$output) {
|
|
|
|
$output = "Depot depot 2013/06/25 stream /p4/1/depots/depot/... 'Created by Me'";
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
)
|
|
|
|
);
|
2013-08-09 19:24:58 +00:00
|
|
|
$result = $this->perforce->checkStream("depot");
|
2013-08-15 17:16:15 +00:00
|
|
|
$this->assertTrue($result);
|
|
|
|
$this->assertTrue($this->perforce->isStream());
|
2013-08-09 19:24:58 +00:00
|
|
|
}
|
|
|
|
|
2013-09-04 14:24:49 +00:00
|
|
|
public function testGetComposerInformationWithoutLabelWithoutStream()
|
|
|
|
{
|
2013-08-15 17:16:15 +00:00
|
|
|
$expectedCommand = "p4 -u user -c composer_perforce_TEST_depot -p port print //depot/composer.json";
|
2013-08-09 19:24:58 +00:00
|
|
|
$this->processExecutor->expects($this->at(0))
|
|
|
|
->method('execute')
|
|
|
|
->with($this->equalTo($expectedCommand))
|
2013-09-04 14:24:49 +00:00
|
|
|
->will(
|
2013-09-06 17:14:22 +00:00
|
|
|
$this->returnCallback(
|
|
|
|
function ($command, &$output) {
|
|
|
|
$output = PerforceTest::getComposerJson();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
)
|
|
|
|
);
|
2013-08-09 19:24:58 +00:00
|
|
|
|
|
|
|
$result = $this->perforce->getComposerInformation("//depot");
|
|
|
|
$expected = array(
|
|
|
|
"name" => "test/perforce",
|
|
|
|
"description" => "Basic project for testing",
|
|
|
|
"minimum-stability" => "dev",
|
|
|
|
"autoload" => array("psr-0" => array())
|
|
|
|
);
|
|
|
|
$this->assertEquals($expected, $result);
|
|
|
|
}
|
|
|
|
|
2013-09-04 14:24:49 +00:00
|
|
|
public function testGetComposerInformationWithLabelWithoutStream()
|
|
|
|
{
|
2013-08-15 17:16:15 +00:00
|
|
|
$expectedCommand = "p4 -u user -p port files //depot/composer.json@0.0.1";
|
2013-08-09 19:24:58 +00:00
|
|
|
$this->processExecutor->expects($this->at(0))
|
|
|
|
->method('execute')
|
|
|
|
->with($this->equalTo($expectedCommand))
|
2013-09-04 14:24:49 +00:00
|
|
|
->will(
|
2013-09-06 17:14:22 +00:00
|
|
|
$this->returnCallback(
|
|
|
|
function ($command, &$output) {
|
|
|
|
$output = "//depot/composer.json#1 - branch change 10001 (text)";
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
)
|
|
|
|
);
|
2013-08-09 19:24:58 +00:00
|
|
|
|
2013-08-15 17:16:15 +00:00
|
|
|
$expectedCommand = "p4 -u user -c composer_perforce_TEST_depot -p port print //depot/composer.json@10001";
|
2013-08-09 19:24:58 +00:00
|
|
|
$this->processExecutor->expects($this->at(1))
|
|
|
|
->method('execute')
|
|
|
|
->with($this->equalTo($expectedCommand))
|
2013-09-04 14:24:49 +00:00
|
|
|
->will(
|
2013-09-06 17:14:22 +00:00
|
|
|
$this->returnCallback(
|
|
|
|
function ($command, &$output) {
|
|
|
|
$output = PerforceTest::getComposerJson();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
)
|
|
|
|
);
|
2013-08-09 19:24:58 +00:00
|
|
|
|
|
|
|
$result = $this->perforce->getComposerInformation("//depot@0.0.1");
|
|
|
|
|
|
|
|
$expected = array(
|
|
|
|
"name" => "test/perforce",
|
|
|
|
"description" => "Basic project for testing",
|
|
|
|
"minimum-stability" => "dev",
|
|
|
|
"autoload" => array("psr-0" => array())
|
|
|
|
);
|
|
|
|
$this->assertEquals($expected, $result);
|
|
|
|
}
|
|
|
|
|
2013-09-04 14:24:49 +00:00
|
|
|
public function testGetComposerInformationWithoutLabelWithStream()
|
|
|
|
{
|
2013-08-15 17:16:15 +00:00
|
|
|
$this->setPerforceToStream();
|
|
|
|
|
|
|
|
$expectedCommand = "p4 -u user -c composer_perforce_TEST_depot_branch -p port print //depot/branch/composer.json";
|
2013-08-09 19:24:58 +00:00
|
|
|
$this->processExecutor->expects($this->at(0))
|
|
|
|
->method('execute')
|
|
|
|
->with($this->equalTo($expectedCommand))
|
2013-09-04 14:24:49 +00:00
|
|
|
->will(
|
2013-09-06 17:14:22 +00:00
|
|
|
$this->returnCallback(
|
|
|
|
function ($command, &$output) {
|
|
|
|
$output = PerforceTest::getComposerJson();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
)
|
|
|
|
);
|
2013-08-09 19:24:58 +00:00
|
|
|
|
|
|
|
$result = $this->perforce->getComposerInformation("//depot/branch");
|
|
|
|
|
|
|
|
$expected = array(
|
|
|
|
"name" => "test/perforce",
|
|
|
|
"description" => "Basic project for testing",
|
|
|
|
"minimum-stability" => "dev",
|
|
|
|
"autoload" => array("psr-0" => array())
|
|
|
|
);
|
|
|
|
$this->assertEquals($expected, $result);
|
|
|
|
}
|
|
|
|
|
2013-09-04 14:24:49 +00:00
|
|
|
public function testGetComposerInformationWithLabelWithStream()
|
|
|
|
{
|
2013-08-15 17:16:15 +00:00
|
|
|
$this->setPerforceToStream();
|
|
|
|
$expectedCommand = "p4 -u user -p port files //depot/branch/composer.json@0.0.1";
|
2013-08-09 19:24:58 +00:00
|
|
|
$this->processExecutor->expects($this->at(0))
|
|
|
|
->method('execute')
|
|
|
|
->with($this->equalTo($expectedCommand))
|
2013-09-04 14:24:49 +00:00
|
|
|
->will(
|
2013-09-06 17:14:22 +00:00
|
|
|
$this->returnCallback(
|
|
|
|
function ($command, &$output) {
|
|
|
|
$output = "//depot/composer.json#1 - branch change 10001 (text)";
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
)
|
|
|
|
);
|
2013-08-09 19:24:58 +00:00
|
|
|
|
2013-08-15 17:16:15 +00:00
|
|
|
$expectedCommand = "p4 -u user -c composer_perforce_TEST_depot_branch -p port print //depot/branch/composer.json@10001";
|
2013-08-09 19:24:58 +00:00
|
|
|
$this->processExecutor->expects($this->at(1))
|
|
|
|
->method('execute')
|
|
|
|
->with($this->equalTo($expectedCommand))
|
2013-09-04 14:24:49 +00:00
|
|
|
->will(
|
2013-09-06 17:14:22 +00:00
|
|
|
$this->returnCallback(
|
|
|
|
function ($command, &$output) {
|
|
|
|
$output = PerforceTest::getComposerJson();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
)
|
|
|
|
);
|
2013-08-09 19:24:58 +00:00
|
|
|
|
|
|
|
$result = $this->perforce->getComposerInformation("//depot/branch@0.0.1");
|
|
|
|
|
|
|
|
$expected = array(
|
|
|
|
"name" => "test/perforce",
|
|
|
|
"description" => "Basic project for testing",
|
|
|
|
"minimum-stability" => "dev",
|
|
|
|
"autoload" => array("psr-0" => array())
|
|
|
|
);
|
|
|
|
$this->assertEquals($expected, $result);
|
|
|
|
}
|
|
|
|
|
2013-09-04 14:24:49 +00:00
|
|
|
public function testSyncCodeBaseWithoutStream()
|
|
|
|
{
|
2013-08-15 17:16:15 +00:00
|
|
|
$expectedCommand = "p4 -u user -c composer_perforce_TEST_depot -p port sync -f @label";
|
2013-08-09 19:24:58 +00:00
|
|
|
$this->processExecutor->expects($this->at(1))
|
|
|
|
->method('execute')
|
|
|
|
->with($this->equalTo($expectedCommand), $this->equalTo(null))
|
|
|
|
->will($this->returnValue(0));
|
|
|
|
|
|
|
|
$this->perforce->syncCodeBase("label");
|
|
|
|
}
|
|
|
|
|
2013-09-04 14:24:49 +00:00
|
|
|
public function testSyncCodeBaseWithStream()
|
|
|
|
{
|
2013-08-15 17:16:15 +00:00
|
|
|
$this->setPerforceToStream();
|
|
|
|
$expectedCommand = "p4 -u user -c composer_perforce_TEST_depot_branch -p port sync -f @label";
|
2013-09-04 14:24:49 +00:00
|
|
|
$this->processExecutor->expects($this->at(1))
|
|
|
|
->method('execute')
|
|
|
|
->with($this->equalTo($expectedCommand))
|
|
|
|
->will($this->returnValue(0));
|
2013-08-09 19:24:58 +00:00
|
|
|
|
|
|
|
$this->perforce->syncCodeBase("label");
|
|
|
|
}
|
|
|
|
|
2013-09-04 14:24:49 +00:00
|
|
|
public function testCheckServerExists()
|
|
|
|
{
|
2013-08-09 19:24:58 +00:00
|
|
|
$processExecutor = $this->getMock('Composer\Util\ProcessExecutor');
|
|
|
|
|
2013-08-15 17:16:15 +00:00
|
|
|
$expectedCommand = "p4 -p perforce.does.exist:port info -s";
|
2013-08-09 19:24:58 +00:00
|
|
|
$processExecutor->expects($this->at(0))
|
2013-09-04 14:24:49 +00:00
|
|
|
->method('execute')
|
|
|
|
->with($this->equalTo($expectedCommand), $this->equalTo(null))
|
|
|
|
->will($this->returnValue(0));
|
2013-08-09 19:24:58 +00:00
|
|
|
|
|
|
|
$result = $this->perforce->checkServerExists("perforce.does.exist:port", $processExecutor);
|
|
|
|
$this->assertTrue($result);
|
|
|
|
}
|
|
|
|
|
2013-09-04 14:24:49 +00:00
|
|
|
public function testCheckServerExistsWithFailure()
|
|
|
|
{
|
2013-08-09 19:24:58 +00:00
|
|
|
$processExecutor = $this->getMock('Composer\Util\ProcessExecutor');
|
|
|
|
|
2013-08-15 17:16:15 +00:00
|
|
|
$expectedCommand = "p4 -p perforce.does.not.exist:port info -s";
|
2013-08-09 19:24:58 +00:00
|
|
|
$processExecutor->expects($this->at(0))
|
2013-09-04 14:24:49 +00:00
|
|
|
->method('execute')
|
|
|
|
->with($this->equalTo($expectedCommand), $this->equalTo(null))
|
|
|
|
->will($this->returnValue("Perforce client error:"));
|
2013-08-09 19:24:58 +00:00
|
|
|
|
|
|
|
$result = $this->perforce->checkServerExists("perforce.does.not.exist:port", $processExecutor);
|
|
|
|
$this->assertTrue($result);
|
|
|
|
}
|
|
|
|
|
2013-09-04 14:24:49 +00:00
|
|
|
public static function getComposerJson()
|
|
|
|
{
|
2013-08-09 19:24:58 +00:00
|
|
|
$composer_json = array(
|
|
|
|
'{',
|
|
|
|
'"name": "test/perforce",',
|
|
|
|
'"description": "Basic project for testing",',
|
|
|
|
'"minimum-stability": "dev",',
|
|
|
|
'"autoload": {',
|
|
|
|
'"psr-0" : {',
|
|
|
|
'}',
|
|
|
|
'}',
|
|
|
|
'}'
|
|
|
|
);
|
|
|
|
|
|
|
|
return implode($composer_json);
|
|
|
|
}
|
|
|
|
|
2013-09-04 14:24:49 +00:00
|
|
|
private function getExpectedClientSpec($withStream)
|
|
|
|
{
|
2013-08-09 19:24:58 +00:00
|
|
|
$expectedArray = array(
|
|
|
|
"Client: composer_perforce_TEST_depot",
|
|
|
|
"\n",
|
|
|
|
"Update:",
|
|
|
|
"\n",
|
|
|
|
"Access:",
|
|
|
|
"Owner: user",
|
|
|
|
"\n",
|
|
|
|
"Description:",
|
|
|
|
" Created by user from composer.",
|
|
|
|
"\n",
|
|
|
|
"Root: path",
|
|
|
|
"\n",
|
|
|
|
"Options: noallwrite noclobber nocompress unlocked modtime rmdir",
|
|
|
|
"\n",
|
|
|
|
"SubmitOptions: revertunchanged",
|
|
|
|
"\n",
|
|
|
|
"LineEnd: local",
|
|
|
|
"\n"
|
|
|
|
);
|
|
|
|
if ($withStream) {
|
|
|
|
$expectedArray[] = "Stream:";
|
2013-08-15 17:16:15 +00:00
|
|
|
$expectedArray[] = " //depot/branch";
|
2013-09-04 14:24:49 +00:00
|
|
|
} else {
|
2013-08-09 19:24:58 +00:00
|
|
|
$expectedArray[] = "View: //depot/... //composer_perforce_TEST_depot/depot/...";
|
|
|
|
}
|
|
|
|
|
|
|
|
return $expectedArray;
|
|
|
|
}
|
|
|
|
|
2013-09-04 14:24:49 +00:00
|
|
|
private function setPerforceToStream()
|
|
|
|
{
|
2013-08-15 17:16:15 +00:00
|
|
|
$this->perforce->setStream("//depot/branch");
|
2013-08-09 19:24:58 +00:00
|
|
|
}
|
|
|
|
}
|