2016-10-03 11:17:07 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 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\HgDriver;
|
2022-04-13 13:54:58 +00:00
|
|
|
use Composer\Test\Mock\ProcessExecutorMock;
|
2018-11-12 14:23:32 +00:00
|
|
|
use Composer\Test\TestCase;
|
2016-10-03 11:17:07 +00:00
|
|
|
use Composer\Util\Filesystem;
|
|
|
|
use Composer\Config;
|
2022-04-13 13:54:58 +00:00
|
|
|
use Composer\Util\ProcessExecutor;
|
2016-10-03 11:17:07 +00:00
|
|
|
|
|
|
|
class HgDriverTest extends TestCase
|
|
|
|
{
|
|
|
|
/** @type \Composer\IO\IOInterface|\PHPUnit_Framework_MockObject_MockObject */
|
|
|
|
private $io;
|
2016-10-03 11:35:48 +00:00
|
|
|
/** @type Config */
|
2016-10-03 11:17:07 +00:00
|
|
|
private $config;
|
|
|
|
/** @type string */
|
|
|
|
private $home;
|
|
|
|
|
|
|
|
public function setUp()
|
|
|
|
{
|
2018-04-12 08:24:56 +00:00
|
|
|
$this->io = $this->getMockBuilder('Composer\IO\IOInterface')->getMock();
|
2016-10-03 11:17:07 +00:00
|
|
|
$this->home = $this->getUniqueTmpDirectory();
|
|
|
|
$this->config = new Config();
|
|
|
|
$this->config->merge(array(
|
|
|
|
'config' => array(
|
|
|
|
'home' => $this->home,
|
|
|
|
),
|
|
|
|
));
|
|
|
|
}
|
|
|
|
|
|
|
|
public function tearDown()
|
|
|
|
{
|
|
|
|
$fs = new Filesystem;
|
|
|
|
$fs->removeDirectory($this->home);
|
|
|
|
}
|
|
|
|
|
2016-10-03 11:35:48 +00:00
|
|
|
/**
|
|
|
|
* @dataProvider supportsDataProvider
|
|
|
|
*/
|
|
|
|
public function testSupports($repositoryUrl)
|
2016-10-03 11:17:07 +00:00
|
|
|
{
|
|
|
|
$this->assertTrue(
|
2016-10-03 11:35:48 +00:00
|
|
|
HgDriver::supports($this->io, $this->config, $repositoryUrl)
|
2016-10-03 11:17:07 +00:00
|
|
|
);
|
2016-10-03 11:35:48 +00:00
|
|
|
}
|
2016-10-03 11:17:07 +00:00
|
|
|
|
2016-10-03 11:35:48 +00:00
|
|
|
public function supportsDataProvider()
|
|
|
|
{
|
|
|
|
return array(
|
|
|
|
array('ssh://bitbucket.org/user/repo'),
|
|
|
|
array('ssh://hg@bitbucket.org/user/repo'),
|
|
|
|
array('ssh://user@bitbucket.org/user/repo'),
|
|
|
|
array('https://bitbucket.org/user/repo'),
|
|
|
|
array('https://user@bitbucket.org/user/repo'),
|
2016-10-03 11:17:07 +00:00
|
|
|
);
|
|
|
|
}
|
2022-04-13 13:54:58 +00:00
|
|
|
|
|
|
|
public function testGetBranchesFilterInvalidBranchNames()
|
|
|
|
{
|
|
|
|
$process = $this->getMockBuilder('Composer\Util\ProcessExecutor')->getMock();
|
|
|
|
$process->expects($this->any())
|
|
|
|
->method('execute')
|
|
|
|
->will($this->returnValue(0));
|
|
|
|
|
|
|
|
$driver = new HgDriver(array('url' => 'https://example.org/acme.git'), $this->io, $this->config, $process);
|
|
|
|
|
|
|
|
$stdout = <<<HG_BRANCHES
|
|
|
|
default 1:dbf6c8acb640
|
|
|
|
--help 1:dbf6c8acb640
|
|
|
|
HG_BRANCHES;
|
|
|
|
|
|
|
|
$stdout1 = <<<HG_BOOKMARKS
|
|
|
|
help 1:dbf6c8acb641
|
|
|
|
--help 1:dbf6c8acb641
|
|
|
|
|
|
|
|
HG_BOOKMARKS;
|
|
|
|
|
|
|
|
$process->expects($this->at(0))
|
|
|
|
->method('execute')
|
|
|
|
->with('hg branches');
|
|
|
|
$process->expects($this->at(1))
|
|
|
|
->method('splitLines')
|
|
|
|
->will($this->returnValue(preg_split('{\r?\n}', trim($stdout))));
|
|
|
|
$process->expects($this->at(2))
|
|
|
|
->method('execute')
|
|
|
|
->with('hg bookmarks');
|
|
|
|
$process->expects($this->at(3))
|
|
|
|
->method('splitLines')
|
|
|
|
->will($this->returnValue(preg_split('{\r?\n}', trim($stdout1))));
|
|
|
|
|
|
|
|
$branches = $driver->getBranches();
|
|
|
|
$this->assertSame(array(
|
|
|
|
'help' => 'dbf6c8acb641',
|
|
|
|
'default' => 'dbf6c8acb640',
|
|
|
|
), $branches);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testFileGetContentInvalidIdentifier()
|
|
|
|
{
|
|
|
|
$this->setExpectedException('\RuntimeException');
|
|
|
|
|
|
|
|
$process = $this->getMockBuilder('Composer\Util\ProcessExecutor')->getMock();
|
|
|
|
$process->expects($this->any())
|
|
|
|
->method('execute')
|
|
|
|
->will($this->returnValue(0));
|
|
|
|
$driver = new HgDriver(array('url' => 'https://example.org/acme.git'), $this->io, $this->config, $process);
|
|
|
|
|
|
|
|
$this->assertNull($driver->getFileContent('file.txt', 'h'));
|
|
|
|
|
|
|
|
$driver->getFileContent('file.txt', '-h');
|
|
|
|
}
|
2016-10-03 11:17:07 +00:00
|
|
|
}
|