1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* Moodle component manager. |
5
|
|
|
* |
6
|
|
|
* @author Luke Carrier <[email protected]> |
7
|
|
|
* @copyright 2016 Luke Carrier |
8
|
|
|
* @license GPL-3.0+ |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
namespace ComponentManager\Test\VersionControl\Git; |
12
|
|
|
|
13
|
|
|
use ComponentManager\Exception\VersionControlException; |
14
|
|
|
use ComponentManager\VersionControl\Git\Command\Command; |
15
|
|
|
use ComponentManager\VersionControl\Git\GitVersionControl; |
16
|
|
|
use PHPUnit\Framework\TestCase; |
17
|
|
|
use Symfony\Component\Process\Process; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* @coversDefaultClass \ComponentManager\VersionControl\GitVersionControl |
21
|
|
|
*/ |
22
|
|
|
class GitVersionControlTest extends TestCase { |
23
|
|
|
public function testCreateProcess() { |
24
|
|
|
$repo = new GitVersionControl('git', getcwd()); |
25
|
|
|
$process = $repo->createProcess(['help']); |
26
|
|
|
|
27
|
|
|
$this->assertEquals(getcwd(), $process->getWorkingDirectory()); |
28
|
|
|
$this->assertEquals('\'git\' \'help\'', $process->getCommandLine()); |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
public function testRunCommand() { |
32
|
|
|
$repo = new GitVersionControl('git', getcwd()); |
33
|
|
|
$command = $this->createMock(Command::class); |
34
|
|
|
$command->method('getCommandLine') |
35
|
|
|
->willReturn(['help']); |
36
|
|
|
$process = $repo->runCommand($command); |
37
|
|
|
|
38
|
|
|
$this->assertInstanceOf(Process::class, $process); |
39
|
|
|
$this->assertEquals(0, $process->getExitCode()); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
public function testRunCommandThrows() { |
43
|
|
|
$repo = new GitVersionControl('git', 'getcwd'); |
44
|
|
|
$command = $this->createMock(Command::class); |
45
|
|
|
$command->method('getCommandLine') |
46
|
|
|
->willReturn(['completely-invalid-command']); |
47
|
|
|
|
48
|
|
|
$this->expectException(VersionControlException::class); |
49
|
|
|
$this->expectExceptionCode(999); |
50
|
|
|
|
51
|
|
|
$repo->runCommand($command, 999); |
52
|
|
|
} |
53
|
|
|
} |
54
|
|
|
|