File: HgDriverTest.php

package info (click to toggle)
composer 2.8.11-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 10,752 kB
  • sloc: php: 77,487; makefile: 59; xml: 39
file content (112 lines) | stat: -rw-r--r-- 3,258 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
<?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\TestCase;
use Composer\Util\Filesystem;
use Composer\Config;
use PHPUnit\Framework\Attributes\DataProvider;

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(): void
    {
        $this->io = $this->getMockBuilder('Composer\IO\IOInterface')->getMock();
        $this->home = self::getUniqueTmpDirectory();
        $this->config = new Config();
        $this->config->merge([
            'config' => [
                'home' => $this->home,
            ],
        ]);
    }

    protected function tearDown(): void
    {
        parent::tearDown();
        $fs = new Filesystem;
        $fs->removeDirectory($this->home);
    }

    #[DataProvider('supportsDataProvider')]
    public function testSupports(string $repositoryUrl): void
    {
        self::assertTrue(
            HgDriver::supports($this->io, $this->config, $repositoryUrl)
        );
    }

    public static function supportsDataProvider(): array
    {
        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'],
        ];
    }

    public function testGetBranchesFilterInvalidBranchNames(): void
    {
        $process = $this->getProcessExecutorMock();

        $driver = new HgDriver(['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([[
                'cmd' => ['hg', 'branches'],
                'stdout' => $stdout,
            ], [
                'cmd' => ['hg', 'bookmarks'],
                'stdout' => $stdout1,
            ]]);

        $branches = $driver->getBranches();
        self::assertSame([
            'help' => 'dbf6c8acb641',
            'default' => 'dbf6c8acb640',
        ], $branches);
    }

    public function testFileGetContentInvalidIdentifier(): void
    {
        self::expectException('\RuntimeException');

        $process = $this->getProcessExecutorMock();
        $driver = new HgDriver(['url' => 'https://example.org/acme.git'], $this->io, $this->config, $this->getMockBuilder('Composer\Util\HttpDownloader')->disableOriginalConstructor()->getMock(), $process);

        self::assertNull($driver->getFileContent('file.txt', 'h'));

        $driver->getFileContent('file.txt', '-h');
    }
}