|
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\Hook\Message\Action; |
|
13
|
|
|
|
|
14
|
|
|
use CaptainHook\App\Config; |
|
15
|
|
|
use CaptainHook\App\Console\IO\NullIO; |
|
16
|
|
|
use CaptainHook\App\Hook\Message\Rule\CapitalizeSubject; |
|
17
|
|
|
use CaptainHook\App\Hook\Message\Rule\LimitSubjectLength; |
|
18
|
|
|
use CaptainHook\App\Mockery; |
|
19
|
|
|
use Exception; |
|
20
|
|
|
use SebastianFeldmann\Git\CommitMessage; |
|
21
|
|
|
use PHPUnit\Framework\TestCase; |
|
22
|
|
|
|
|
23
|
|
|
class RulesTest extends TestCase |
|
24
|
|
|
{ |
|
25
|
|
|
use Mockery; |
|
26
|
|
|
|
|
27
|
|
|
public function testExecuteEmptyRules(): void |
|
28
|
|
|
{ |
|
29
|
|
|
$io = new NullIO(); |
|
30
|
|
|
$config = new Config(CH_PATH_FILES . '/captainhook.json'); |
|
31
|
|
|
$action = new Config\Action(Rules::class); |
|
32
|
|
|
$repo = $this->createRepositoryMock(); |
|
33
|
|
|
$repo->method('getCommitMsg')->willReturn(new CommitMessage('Foo bar baz')); |
|
34
|
|
|
|
|
35
|
|
|
$standard = new Rules(); |
|
36
|
|
|
$standard->execute($config, $io, $repo, $action); |
|
37
|
|
|
|
|
38
|
|
|
$this->assertTrue(true); |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
public function testNoValidationOnMerging(): void |
|
42
|
|
|
{ |
|
43
|
|
|
$io = new NullIO(); |
|
44
|
|
|
$config = new Config(CH_PATH_FILES . '/captainhook.json'); |
|
45
|
|
|
$action = new Config\Action(Rules::class); |
|
46
|
|
|
$repo = $this->createRepositoryMock(); |
|
47
|
|
|
$repo->expects($this->once())->method('isMerging')->willReturn(true); |
|
48
|
|
|
|
|
49
|
|
|
$standard = new Rules(); |
|
50
|
|
|
$standard->execute($config, $io, $repo, $action); |
|
51
|
|
|
|
|
52
|
|
|
$this->assertTrue(true); |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
public function testExecuteClassNotFound(): void |
|
56
|
|
|
{ |
|
57
|
|
|
$this->expectException(Exception::class); |
|
58
|
|
|
|
|
59
|
|
|
$io = new NullIO(); |
|
60
|
|
|
$config = new Config(CH_PATH_FILES . '/captainhook.json'); |
|
61
|
|
|
$repo = $this->createRepositoryMock(); |
|
62
|
|
|
$action = new Config\Action(Rules::class, [Foo::class]); |
|
|
|
|
|
|
63
|
|
|
|
|
64
|
|
|
$standard = new Rules(); |
|
65
|
|
|
$standard->execute($config, $io, $repo, $action); |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
public function testExecuteInvalidClass(): void |
|
69
|
|
|
{ |
|
70
|
|
|
$this->expectException(Exception::class); |
|
71
|
|
|
|
|
72
|
|
|
$io = new NullIO(); |
|
73
|
|
|
$config = new Config(CH_PATH_FILES . '/captainhook.json'); |
|
74
|
|
|
$action = new Config\Action(Rules::class, [Validator::class]); |
|
|
|
|
|
|
75
|
|
|
$repo = $this->createRepositoryMock(); |
|
76
|
|
|
|
|
77
|
|
|
$standard = new Rules(); |
|
78
|
|
|
$standard->execute($config, $io, $repo, $action); |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
public function testExecuteValidRule(): void |
|
82
|
|
|
{ |
|
83
|
|
|
$io = new NullIO(); |
|
84
|
|
|
$config = new Config(CH_PATH_FILES . '/captainhook.json'); |
|
85
|
|
|
$action = new Config\Action(Rules::class, [CapitalizeSubject::class]); |
|
86
|
|
|
$repo = $this->createRepositoryMock(); |
|
87
|
|
|
$repo->method('getCommitMsg')->willReturn(new CommitMessage('Foo bar baz')); |
|
88
|
|
|
|
|
89
|
|
|
$standard = new Rules(); |
|
90
|
|
|
$standard->execute($config, $io, $repo, $action); |
|
91
|
|
|
|
|
92
|
|
|
$this->assertTrue(true); |
|
93
|
|
|
} |
|
94
|
|
|
|
|
95
|
|
|
public function testExecuteValidRuleWithArguments(): void |
|
96
|
|
|
{ |
|
97
|
|
|
$io = new NullIO(); |
|
98
|
|
|
$config = new Config(CH_PATH_FILES . '/captainhook.json'); |
|
99
|
|
|
$action = new Config\Action(Rules::class, [[LimitSubjectLength::class, [10]]]); |
|
100
|
|
|
$repo = $this->createRepositoryMock(); |
|
101
|
|
|
$repo->method('getCommitMsg')->willReturn(new CommitMessage('Foo bar baz')); |
|
102
|
|
|
|
|
103
|
|
|
try { |
|
104
|
|
|
$standard = new Rules(); |
|
105
|
|
|
$standard->execute($config, $io, $repo, $action); |
|
106
|
|
|
|
|
107
|
|
|
// exception should be thrown before this |
|
108
|
|
|
$this->assterTrue(false); |
|
109
|
|
|
} catch (Exception $e) { |
|
110
|
|
|
$this->assertTrue(true); |
|
111
|
|
|
} |
|
112
|
|
|
} |
|
113
|
|
|
|
|
114
|
|
|
public function testExecuteLimitSubjectLengthRuleWithUnicode(): void |
|
115
|
|
|
{ |
|
116
|
|
|
$io = new NullIO(); |
|
117
|
|
|
$config = new Config(CH_PATH_FILES . '/captainhook.json'); |
|
118
|
|
|
$action = new Config\Action(Rules::class, [[LimitSubjectLength::class, [10]]]); |
|
119
|
|
|
$repo = $this->createRepositoryMock(); |
|
120
|
|
|
$repo->method('getCommitMsg')->willReturn(new CommitMessage('Föö bäü¿')); |
|
121
|
|
|
|
|
122
|
|
|
try { |
|
123
|
|
|
$standard = new Rules(); |
|
124
|
|
|
$standard->execute($config, $io, $repo, $action); |
|
125
|
|
|
|
|
126
|
|
|
// no exception should be thrown |
|
127
|
|
|
$this->assertTrue(true); |
|
128
|
|
|
} catch (Exception $e) { |
|
129
|
|
|
$this->assertTrue(false); |
|
130
|
|
|
} |
|
131
|
|
|
} |
|
132
|
|
|
|
|
133
|
|
|
public function testNoRule(): void |
|
134
|
|
|
{ |
|
135
|
|
|
$this->expectException(Exception::class); |
|
136
|
|
|
|
|
137
|
|
|
$io = new NullIO(); |
|
138
|
|
|
$config = new Config(CH_PATH_FILES . '/captainhook.json'); |
|
139
|
|
|
$action = new Config\Action(Rules::class, [NoRule::class]); |
|
140
|
|
|
$repo = $this->createRepositoryMock(); |
|
141
|
|
|
$repo->method('getCommitMsg')->willReturn(new CommitMessage('Foo bar baz')); |
|
142
|
|
|
|
|
143
|
|
|
$standard = new Rules(); |
|
144
|
|
|
$standard->execute($config, $io, $repo, $action); |
|
145
|
|
|
} |
|
146
|
|
|
|
|
147
|
|
|
public function testInvalidComplexRule(): void |
|
148
|
|
|
{ |
|
149
|
|
|
$this->expectException(Exception::class); |
|
150
|
|
|
|
|
151
|
|
|
$io = new NullIO(); |
|
152
|
|
|
$config = new Config(CH_PATH_FILES . '/captainhook.json'); |
|
153
|
|
|
$action = new Config\Action(Rules::class, [[LimitSubjectLength::class, 'foo']]); |
|
154
|
|
|
$repo = $this->createRepositoryMock(); |
|
155
|
|
|
|
|
156
|
|
|
$standard = new Rules(); |
|
157
|
|
|
$standard->execute($config, $io, $repo, $action); |
|
158
|
|
|
} |
|
159
|
|
|
} |
|
160
|
|
|
|
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