|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* This file is part of CaptainHook |
|
5
|
|
|
* |
|
6
|
|
|
* (c) Sebastian Feldmann <[email protected]> |
|
7
|
|
|
* |
|
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
9
|
|
|
* file that was distributed with this source code. |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
namespace CaptainHook\App\Console\Command\Hook; |
|
13
|
|
|
|
|
14
|
|
|
use CaptainHook\App\Console\Runtime\Resolver; |
|
15
|
|
|
use CaptainHook\App\Git\DummyRepo; |
|
16
|
|
|
use Symfony\Component\Console\Input\ArrayInput; |
|
17
|
|
|
use Symfony\Component\Console\Output\NullOutput; |
|
18
|
|
|
use PHPUnit\Framework\TestCase; |
|
19
|
|
|
|
|
20
|
|
|
class PostCommitTest extends TestCase |
|
21
|
|
|
{ |
|
22
|
|
|
public function testExecuteWithRelativeConfigPath(): void |
|
23
|
|
|
{ |
|
24
|
|
|
$cwd = getcwd(); |
|
25
|
|
|
chdir(CH_PATH_FILES); |
|
26
|
|
|
|
|
27
|
|
|
$repo = new DummyRepo(); |
|
28
|
|
|
$output = new NullOutput(); |
|
29
|
|
|
$input = new ArrayInput( |
|
30
|
|
|
[ |
|
31
|
|
|
'--configuration' => './config/valid.json', |
|
32
|
|
|
'--git-directory' => $repo->getGitDir() |
|
33
|
|
|
] |
|
34
|
|
|
); |
|
35
|
|
|
|
|
36
|
|
|
$cmd = new PostCommit(new Resolver()); |
|
37
|
|
|
$cmd->run($input, $output); |
|
38
|
|
|
|
|
39
|
|
|
chdir($cwd); |
|
40
|
|
|
|
|
41
|
|
|
$this->assertTrue(true); |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
public function testMissingBootstrapHandling(): void |
|
45
|
|
|
{ |
|
46
|
|
|
$repo = new DummyRepo(); |
|
47
|
|
|
$output = new NullOutput(); |
|
48
|
|
|
$input = new ArrayInput( |
|
49
|
|
|
[ |
|
50
|
|
|
'--configuration' => CH_PATH_FILES . '/config/valid.json', |
|
51
|
|
|
'--git-directory' => $repo->getGitDir(), |
|
52
|
|
|
'--bootstrap' => 'foo/bar/baz.php', |
|
53
|
|
|
] |
|
54
|
|
|
); |
|
55
|
|
|
|
|
56
|
|
|
$resolver = $this->getMockBuilder(Resolver::class) |
|
57
|
|
|
->disableOriginalConstructor() |
|
58
|
|
|
->getMock(); |
|
59
|
|
|
$resolver->method('isPharRelease')->willReturn(true); |
|
60
|
|
|
|
|
61
|
|
|
$cmd = new PostCommit($resolver); |
|
62
|
|
|
$this->assertEquals(1, $cmd->run($input, $output)); |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
public function testCrashingBootstrapHandling(): void |
|
66
|
|
|
{ |
|
67
|
|
|
if (version_compare(PHP_VERSION, '8.0', '<')) { |
|
68
|
|
|
$this->markTestSkipped( |
|
69
|
|
|
'Only available on PHP 8.0 and higher' |
|
70
|
|
|
); |
|
71
|
|
|
} |
|
72
|
|
|
$repo = new DummyRepo(); |
|
73
|
|
|
$output = new NullOutput(); |
|
74
|
|
|
$input = new ArrayInput( |
|
75
|
|
|
[ |
|
76
|
|
|
'--configuration' => CH_PATH_FILES . '/config/valid.json', |
|
77
|
|
|
'--git-directory' => $repo->getGitDir(), |
|
78
|
|
|
'--bootstrap' => '../bootstrap/crash.php', |
|
79
|
|
|
] |
|
80
|
|
|
); |
|
81
|
|
|
|
|
82
|
|
|
$resolver = $this->getMockBuilder(Resolver::class) |
|
83
|
|
|
->disableOriginalConstructor() |
|
84
|
|
|
->getMock(); |
|
85
|
|
|
$resolver->method('isPharRelease')->willReturn(true); |
|
86
|
|
|
|
|
87
|
|
|
$cmd = new PostCommit($resolver); |
|
88
|
|
|
$this->assertEquals(1, $cmd->run($input, $output)); |
|
89
|
|
|
} |
|
90
|
|
|
} |
|
91
|
|
|
|