* Jordi Boggiano * * 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 { /** @var \Composer\IO\IOInterface&\PHPUnit\Framework\MockObject\MockObject */ private $io; /** @var Config */ private $config; /** @var string */ private $home; public function setUp() { $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, ), )); } public function tearDown() { $fs = new Filesystem; $fs->removeDirectory($this->home); } /** * @dataProvider supportsDataProvider * * @param string $repositoryUrl */ public function testSupports($repositoryUrl) { $this->assertTrue( HgDriver::supports($this->io, $this->config, $repositoryUrl) ); } 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'), ); } public function testGetBranchesFilterInvalidBranchNames() { $process = new ProcessExecutorMock; $driver = new HgDriver(array('url' => 'https://example.org/acme.git'), $this->io, $this->config, $this->getMockBuilder('Composer\Util\HttpDownloader')->disableOriginalConstructor()->getMock(), $process); $stdout = <<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() { $this->expectException('\RuntimeException'); $process = new ProcessExecutorMock; $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'); } }