2022-02-23 15:58:18 +00:00
|
|
|
<?php declare(strict_types=1);
|
2016-10-03 11:17:07 +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\HgDriver;
|
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;
|
|
|
|
|
|
|
|
class HgDriverTest extends TestCase
|
|
|
|
{
|
2021-10-16 08:16:06 +00:00
|
|
|
/** @var \Composer\IO\IOInterface&\PHPUnit\Framework\MockObject\MockObject */
|
2016-10-03 11:17:07 +00:00
|
|
|
private $io;
|
2021-10-16 08:16:06 +00:00
|
|
|
/** @var Config */
|
2016-10-03 11:17:07 +00:00
|
|
|
private $config;
|
2021-10-16 08:16:06 +00:00
|
|
|
/** @var string */
|
2016-10-03 11:17:07 +00:00
|
|
|
private $home;
|
|
|
|
|
2021-12-08 16:03:05 +00:00
|
|
|
public function setUp(): void
|
2016-10-03 11:17:07 +00:00
|
|
|
{
|
2018-04-12 08:24:56 +00:00
|
|
|
$this->io = $this->getMockBuilder('Composer\IO\IOInterface')->getMock();
|
2022-05-11 14:05:35 +00:00
|
|
|
$this->home = self::getUniqueTmpDirectory();
|
2016-10-03 11:17:07 +00:00
|
|
|
$this->config = new Config();
|
2022-08-17 12:20:07 +00:00
|
|
|
$this->config->merge([
|
|
|
|
'config' => [
|
2016-10-03 11:17:07 +00:00
|
|
|
'home' => $this->home,
|
2022-08-17 12:20:07 +00:00
|
|
|
],
|
|
|
|
]);
|
2016-10-03 11:17:07 +00:00
|
|
|
}
|
|
|
|
|
2021-12-09 16:09:07 +00:00
|
|
|
protected function tearDown(): void
|
2016-10-03 11:17:07 +00:00
|
|
|
{
|
2021-12-09 16:09:07 +00:00
|
|
|
parent::tearDown();
|
2016-10-03 11:17:07 +00:00
|
|
|
$fs = new Filesystem;
|
|
|
|
$fs->removeDirectory($this->home);
|
|
|
|
}
|
|
|
|
|
2016-10-03 11:35:48 +00:00
|
|
|
/**
|
|
|
|
* @dataProvider supportsDataProvider
|
|
|
|
*/
|
2022-02-22 15:47:09 +00:00
|
|
|
public function testSupports(string $repositoryUrl): void
|
2016-10-03 11:17:07 +00:00
|
|
|
{
|
2024-05-29 21:12:06 +00:00
|
|
|
self::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
|
|
|
|
2022-11-24 13:39:08 +00:00
|
|
|
public static function supportsDataProvider(): array
|
2016-10-03 11:35:48 +00:00
|
|
|
{
|
2022-08-17 12:20:07 +00:00
|
|
|
return [
|
|
|
|
['ssh://bitbucket.org/user/repo'],
|
|
|
|
['ssh://hg@bitbucket.org/user/repo'],
|
|
|
|
['ssh://user@bitbucket.org/user/repo'],
|
|
|
|
['https://bitbucket.org/user/repo'],
|
|
|
|
['https://user@bitbucket.org/user/repo'],
|
|
|
|
];
|
2016-10-03 11:17:07 +00:00
|
|
|
}
|
2022-04-13 13:54:58 +00:00
|
|
|
|
2022-04-13 14:18:25 +00:00
|
|
|
public function testGetBranchesFilterInvalidBranchNames(): void
|
2022-04-13 13:54:58 +00:00
|
|
|
{
|
2022-04-13 14:18:25 +00:00
|
|
|
$process = $this->getProcessExecutorMock();
|
2022-04-13 13:54:58 +00:00
|
|
|
|
2022-08-17 12:20:07 +00:00
|
|
|
$driver = new HgDriver(['url' => 'https://example.org/acme.git'], $this->io, $this->config, $this->getMockBuilder('Composer\Util\HttpDownloader')->disableOriginalConstructor()->getMock(), $process);
|
2022-04-13 13:54:58 +00:00
|
|
|
|
|
|
|
$stdout = <<<HG_BRANCHES
|
|
|
|
default 1:dbf6c8acb640
|
|
|
|
--help 1:dbf6c8acb640
|
|
|
|
HG_BRANCHES;
|
|
|
|
|
|
|
|
$stdout1 = <<<HG_BOOKMARKS
|
|
|
|
help 1:dbf6c8acb641
|
|
|
|
--help 1:dbf6c8acb641
|
|
|
|
|
|
|
|
HG_BOOKMARKS;
|
|
|
|
|
|
|
|
$process
|
2022-08-17 12:20:07 +00:00
|
|
|
->expects([[
|
2024-11-06 12:49:06 +00:00
|
|
|
'cmd' => ['hg', 'branches'],
|
2022-04-13 13:54:58 +00:00
|
|
|
'stdout' => $stdout,
|
2022-08-17 12:20:07 +00:00
|
|
|
], [
|
2024-11-06 12:49:06 +00:00
|
|
|
'cmd' => ['hg', 'bookmarks'],
|
2022-04-13 13:54:58 +00:00
|
|
|
'stdout' => $stdout1,
|
2022-08-17 12:20:07 +00:00
|
|
|
]]);
|
2022-04-13 13:54:58 +00:00
|
|
|
|
|
|
|
$branches = $driver->getBranches();
|
2024-05-29 21:12:06 +00:00
|
|
|
self::assertSame([
|
2022-04-13 13:54:58 +00:00
|
|
|
'help' => 'dbf6c8acb641',
|
|
|
|
'default' => 'dbf6c8acb640',
|
2022-08-17 12:20:07 +00:00
|
|
|
], $branches);
|
2022-04-13 13:54:58 +00:00
|
|
|
}
|
|
|
|
|
2022-04-13 14:18:25 +00:00
|
|
|
public function testFileGetContentInvalidIdentifier(): void
|
2022-04-13 13:54:58 +00:00
|
|
|
{
|
2022-04-13 15:10:07 +00:00
|
|
|
self::expectException('\RuntimeException');
|
2022-04-13 13:54:58 +00:00
|
|
|
|
2022-04-13 14:18:25 +00:00
|
|
|
$process = $this->getProcessExecutorMock();
|
2022-08-17 12:20:07 +00:00
|
|
|
$driver = new HgDriver(['url' => 'https://example.org/acme.git'], $this->io, $this->config, $this->getMockBuilder('Composer\Util\HttpDownloader')->disableOriginalConstructor()->getMock(), $process);
|
2022-04-13 13:54:58 +00:00
|
|
|
|
2024-05-29 21:12:06 +00:00
|
|
|
self::assertNull($driver->getFileContent('file.txt', 'h'));
|
2022-04-13 13:54:58 +00:00
|
|
|
|
|
|
|
$driver->getFileContent('file.txt', '-h');
|
|
|
|
}
|
2016-10-03 11:17:07 +00:00
|
|
|
}
|