1
0
Fork 0
composer/tests/Composer/Test/Repository/Vcs/HgDriverTest.php

117 lines
3.3 KiB
PHP
Raw Normal View History

2022-02-23 15:58:18 +00:00
<?php declare(strict_types=1);
/*
* 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;
use Composer\Test\Mock\ProcessExecutorMock;
use Composer\Test\TestCase;
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 */
private $io;
2021-10-16 08:16:06 +00:00
/** @var Config */
private $config;
2021-10-16 08:16:06 +00:00
/** @var string */
private $home;
2021-12-08 16:03:05 +00:00
public function setUp(): void
{
$this->io = $this->getMockBuilder('Composer\IO\IOInterface')->getMock();
$this->home = $this->getUniqueTmpDirectory();
$this->config = new Config();
$this->config->merge(array(
'config' => array(
'home' => $this->home,
),
));
}
protected function tearDown(): void
{
parent::tearDown();
$fs = new Filesystem;
$fs->removeDirectory($this->home);
}
2016-10-03 11:35:48 +00:00
/**
* @dataProvider supportsDataProvider
*
* @param string $repositoryUrl
2016-10-03 11:35:48 +00:00
*/
2022-02-22 15:47:09 +00:00
public function testSupports(string $repositoryUrl): void
{
$this->assertTrue(
2016-10-03 11:35:48 +00:00
HgDriver::supports($this->io, $this->config, $repositoryUrl)
);
2016-10-03 11:35:48 +00:00
}
2022-02-21 12:42:28 +00:00
public function supportsDataProvider(): array
2016-10-03 11:35:48 +00:00
{
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'),
);
}
public function testGetBranchesFilterInvalidBranchNames(): void
{
$process = $this->getProcessExecutorMock();
$driver = new HgDriver(array('url' => 'https://example.org/acme.git'), $this->io, $this->config, $this->getMockBuilder('Composer\Util\HttpDownloader')->disableOriginalConstructor()->getMock(), $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(array(array(
'cmd' => 'hg branches',
'stdout' => $stdout,
), array(
'cmd' => 'hg bookmarks',
'stdout' => $stdout1,
)));
$branches = $driver->getBranches();
$this->assertSame(array(
'help' => 'dbf6c8acb641',
'default' => 'dbf6c8acb640',
), $branches);
}
public function testFileGetContentInvalidIdentifier(): void
{
$this->expectException('\RuntimeException');
$process = $this->getProcessExecutorMock();
$driver = new HgDriver(array('url' => 'https://example.org/acme.git'), $this->io, $this->config, $this->getMockBuilder('Composer\Util\HttpDownloader')->disableOriginalConstructor()->getMock(), $process);
$this->assertNull($driver->getFileContent('file.txt', 'h'));
$driver->getFileContent('file.txt', '-h');
}
}