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 Exception; |
17
|
|
|
use Symfony\Component\Console\Input\ArrayInput; |
18
|
|
|
use Symfony\Component\Console\Output\NullOutput; |
19
|
|
|
use PHPUnit\Framework\TestCase; |
|
|
|
|
20
|
|
|
|
21
|
|
|
class PreCommitTest extends TestCase |
22
|
|
|
{ |
23
|
|
|
/** |
24
|
|
|
* Tests PreCommit::run |
25
|
|
|
* |
26
|
|
|
* @throws \Exception |
27
|
|
|
*/ |
28
|
|
|
public function testExecuteLib(): void |
29
|
|
|
{ |
30
|
|
|
$repo = new DummyRepo(); |
31
|
|
|
$output = new NullOutput(); |
32
|
|
|
$input = new ArrayInput( |
33
|
|
|
[ |
34
|
|
|
'--configuration' => CH_PATH_FILES . '/config/valid.json', |
35
|
|
|
'--git-directory' => $repo->getGitDir() |
36
|
|
|
] |
37
|
|
|
); |
38
|
|
|
|
39
|
|
|
$cmd = new PreCommit(new Resolver()); |
40
|
|
|
$cmd->run($input, $output); |
41
|
|
|
|
42
|
|
|
$this->assertTrue(true); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* Tests PreCommit::run |
47
|
|
|
* |
48
|
|
|
* @throws \Exception |
49
|
|
|
*/ |
50
|
|
|
public function testExecutePhar(): void |
51
|
|
|
{ |
52
|
|
|
$resolver = $this->createMock(Resolver::class); |
53
|
|
|
$resolver->expects($this->once())->method('isPharRelease')->willReturn(true); |
54
|
|
|
|
55
|
|
|
$repo = new DummyRepo(); |
56
|
|
|
$output = new NullOutput(); |
57
|
|
|
$input = new ArrayInput( |
58
|
|
|
[ |
59
|
|
|
'--configuration' => CH_PATH_FILES . '/config/empty.json', |
60
|
|
|
'--git-directory' => $repo->getGitDir(), |
61
|
|
|
'--bootstrap' => '../bootstrap/constant.php' |
62
|
|
|
] |
63
|
|
|
); |
64
|
|
|
|
65
|
|
|
$cmd = new PreCommit($resolver); |
66
|
|
|
$cmd->run($input, $output); |
67
|
|
|
|
68
|
|
|
$this->assertTrue(true); |
69
|
|
|
$this->assertTrue(defined('CH_BOOTSTRAP_WORKED')); |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* Tests PreCommit::run |
74
|
|
|
* |
75
|
|
|
* @throws \Exception |
76
|
|
|
*/ |
77
|
|
|
public function testExecutePharBootstrapNotFound(): void |
78
|
|
|
{ |
79
|
|
|
$this->expectException(Exception::class); |
80
|
|
|
$this->expectExceptionMessage('bootstrap file not found'); |
81
|
|
|
|
82
|
|
|
$resolver = $this->createMock(Resolver::class); |
83
|
|
|
$resolver->expects($this->once())->method('isPharRelease')->willReturn(true); |
84
|
|
|
|
85
|
|
|
$repo = new DummyRepo(); |
86
|
|
|
$output = new NullOutput(); |
87
|
|
|
$input = new ArrayInput( |
88
|
|
|
[ |
89
|
|
|
'--configuration' => CH_PATH_FILES . '/config/empty.json', |
90
|
|
|
'--git-directory' => $repo->getGitDir(), |
91
|
|
|
'--bootstrap' => '../bootstrap/fail.php' |
92
|
|
|
] |
93
|
|
|
); |
94
|
|
|
|
95
|
|
|
$cmd = new PreCommit($resolver); |
96
|
|
|
$cmd->run($input, $output); |
97
|
|
|
|
98
|
|
|
$this->assertTrue(true); |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
/** |
102
|
|
|
* Tests PreCommit::run |
103
|
|
|
* |
104
|
|
|
* @throws \Exception |
105
|
|
|
*/ |
106
|
|
|
public function testExecuteFailingActionInDebugMode(): void |
107
|
|
|
{ |
108
|
|
|
$this->expectException(Exception::class); |
109
|
|
|
$this->expectExceptionMessage('sh: foobarbaz: command not found'); |
110
|
|
|
|
111
|
|
|
$output = $this->createMock(NullOutput::class); |
112
|
|
|
$output->expects($this->once())->method('isDebug')->willReturn(true); |
113
|
|
|
|
114
|
|
|
$resolver = new Resolver(); |
115
|
|
|
$repo = new DummyRepo(); |
116
|
|
|
$input = new ArrayInput( |
117
|
|
|
[ |
118
|
|
|
'--configuration' => CH_PATH_FILES . '/config/valid-but-failing.json', |
119
|
|
|
'--git-directory' => $repo->getGitDir(), |
120
|
|
|
'--bootstrap' => '../bootstrap/empty.php' |
121
|
|
|
] |
122
|
|
|
); |
123
|
|
|
|
124
|
|
|
$cmd = new PreCommit($resolver); |
125
|
|
|
$cmd->run($input, $output); |
126
|
|
|
|
127
|
|
|
$this->assertTrue(true); |
128
|
|
|
} |
129
|
|
|
|
130
|
|
|
/** |
131
|
|
|
* Tests PreCommit::run |
132
|
|
|
* |
133
|
|
|
* @throws \Exception |
134
|
|
|
*/ |
135
|
|
|
public function testExecuteFailingActionInVerboseMode(): void |
136
|
|
|
{ |
137
|
|
|
$output = $this->createMock(NullOutput::class); |
138
|
|
|
$output->expects($this->once())->method('isDebug')->willReturn(false); |
139
|
|
|
$output->expects($this->once())->method('isVerbose')->willReturn(true); |
140
|
|
|
$output->expects($this->atLeast(1))->method('writeLn'); |
141
|
|
|
|
142
|
|
|
$resolver = new Resolver(); |
143
|
|
|
$repo = new DummyRepo(); |
144
|
|
|
$input = new ArrayInput( |
145
|
|
|
[ |
146
|
|
|
'--configuration' => CH_PATH_FILES . '/config/valid-but-failing.json', |
147
|
|
|
'--git-directory' => $repo->getGitDir(), |
148
|
|
|
'--bootstrap' => '../bootstrap/empty.php' |
149
|
|
|
] |
150
|
|
|
); |
151
|
|
|
|
152
|
|
|
$cmd = new PreCommit($resolver); |
153
|
|
|
$this->assertEquals(1, $cmd->run($input, $output)); |
154
|
|
|
} |
155
|
|
|
} |
156
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths