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
|
|
|
/** |
28
|
|
|
* Tests Rulebook::execute |
29
|
|
|
* |
30
|
|
|
* @throws \Exception |
31
|
|
|
*/ |
32
|
|
|
public function testExecuteEmptyRules(): void |
33
|
|
|
{ |
34
|
|
|
$io = new NullIO(); |
35
|
|
|
$config = new Config(CH_PATH_FILES . '/captainhook.json'); |
36
|
|
|
$action = new Config\Action(Rules::class); |
37
|
|
|
$repo = $this->createRepositoryMock(); |
38
|
|
|
$repo->method('getCommitMsg')->willReturn(new CommitMessage('Foo bar baz')); |
|
|
|
|
39
|
|
|
|
40
|
|
|
$standard = new Rules(); |
41
|
|
|
$standard->execute($config, $io, $repo, $action); |
42
|
|
|
|
43
|
|
|
$this->assertTrue(true); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* Tests Rulebook::execute |
48
|
|
|
* |
49
|
|
|
* @throws \Exception |
50
|
|
|
*/ |
51
|
|
|
public function testNoValidationOnMerging(): void |
52
|
|
|
{ |
53
|
|
|
$io = new NullIO(); |
54
|
|
|
$config = new Config(CH_PATH_FILES . '/captainhook.json'); |
55
|
|
|
$action = new Config\Action(Rules::class); |
56
|
|
|
$repo = $this->createRepositoryMock(); |
57
|
|
|
$repo->expects($this->once())->method('isMerging')->willReturn(true); |
58
|
|
|
|
59
|
|
|
$standard = new Rules(); |
60
|
|
|
$standard->execute($config, $io, $repo, $action); |
61
|
|
|
|
62
|
|
|
$this->assertTrue(true); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* Tests Rulebook::execute |
67
|
|
|
*/ |
68
|
|
|
public function testExecuteClassNotFound(): void |
69
|
|
|
{ |
70
|
|
|
$this->expectException(Exception::class); |
71
|
|
|
|
72
|
|
|
$io = new NullIO(); |
73
|
|
|
$config = new Config(CH_PATH_FILES . '/captainhook.json'); |
74
|
|
|
$repo = $this->createRepositoryMock(); |
75
|
|
|
$action = new Config\Action(Rules::class, [Foo::class]); |
|
|
|
|
76
|
|
|
|
77
|
|
|
$standard = new Rules(); |
78
|
|
|
$standard->execute($config, $io, $repo, $action); |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* Tests Rulebook::execute |
83
|
|
|
* |
84
|
|
|
* @throws \Exception |
85
|
|
|
*/ |
86
|
|
|
public function testExecuteInvalidClass(): void |
87
|
|
|
{ |
88
|
|
|
$this->expectException(Exception::class); |
89
|
|
|
|
90
|
|
|
$io = new NullIO(); |
91
|
|
|
$config = new Config(CH_PATH_FILES . '/captainhook.json'); |
92
|
|
|
$action = new Config\Action(Rules::class, [Validator::class]); |
|
|
|
|
93
|
|
|
$repo = $this->createRepositoryMock(); |
94
|
|
|
|
95
|
|
|
$standard = new Rules(); |
96
|
|
|
$standard->execute($config, $io, $repo, $action); |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
/** |
100
|
|
|
* Tests Rulebook::execute |
101
|
|
|
* |
102
|
|
|
* @throws \Exception |
103
|
|
|
*/ |
104
|
|
|
public function testExecuteValidRule(): void |
105
|
|
|
{ |
106
|
|
|
$io = new NullIO(); |
107
|
|
|
$config = new Config(CH_PATH_FILES . '/captainhook.json'); |
108
|
|
|
$action = new Config\Action(Rules::class, [CapitalizeSubject::class]); |
109
|
|
|
$repo = $this->createRepositoryMock(); |
110
|
|
|
$repo->method('getCommitMsg')->willReturn(new CommitMessage('Foo bar baz')); |
111
|
|
|
|
112
|
|
|
$standard = new Rules(); |
113
|
|
|
$standard->execute($config, $io, $repo, $action); |
114
|
|
|
|
115
|
|
|
$this->assertTrue(true); |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
/** |
119
|
|
|
* Tests Rulebook::execute |
120
|
|
|
* |
121
|
|
|
* @throws \Exception |
122
|
|
|
*/ |
123
|
|
|
public function testExecuteValidRuleWithArguments(): void |
124
|
|
|
{ |
125
|
|
|
$io = new NullIO(); |
126
|
|
|
$config = new Config(CH_PATH_FILES . '/captainhook.json'); |
127
|
|
|
$action = new Config\Action(Rules::class, [[LimitSubjectLength::class, [10]]]); |
128
|
|
|
$repo = $this->createRepositoryMock(); |
129
|
|
|
$repo->method('getCommitMsg')->willReturn(new CommitMessage('Foo bar baz')); |
130
|
|
|
|
131
|
|
|
try { |
132
|
|
|
$standard = new Rules(); |
133
|
|
|
$standard->execute($config, $io, $repo, $action); |
134
|
|
|
|
135
|
|
|
// exception should be thrown before this |
136
|
|
|
$this->assterTrue(false); |
137
|
|
|
} catch (Exception $e) { |
138
|
|
|
$this->assertTrue(true); |
139
|
|
|
} |
140
|
|
|
} |
141
|
|
|
|
142
|
|
|
/** |
143
|
|
|
* Tests Rule::execute |
144
|
|
|
* |
145
|
|
|
* @throws \Exception |
146
|
|
|
*/ |
147
|
|
|
public function testNoRule(): 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, [NoRule::class]); |
154
|
|
|
$repo = $this->createRepositoryMock(); |
155
|
|
|
$repo->method('getCommitMsg')->willReturn(new CommitMessage('Foo bar baz')); |
156
|
|
|
|
157
|
|
|
$standard = new Rules(); |
158
|
|
|
$standard->execute($config, $io, $repo, $action); |
159
|
|
|
} |
160
|
|
|
|
161
|
|
|
/** |
162
|
|
|
* Tests Rule::execute |
163
|
|
|
* |
164
|
|
|
* @throws \Exception |
165
|
|
|
*/ |
166
|
|
|
public function testInvalidComplexRule(): void |
167
|
|
|
{ |
168
|
|
|
$this->expectException(Exception::class); |
169
|
|
|
|
170
|
|
|
$io = new NullIO(); |
171
|
|
|
$config = new Config(CH_PATH_FILES . '/captainhook.json'); |
172
|
|
|
$action = new Config\Action(Rules::class, [[LimitSubjectLength::class, 'foo']]); |
173
|
|
|
$repo = $this->createRepositoryMock(); |
174
|
|
|
|
175
|
|
|
$standard = new Rules(); |
176
|
|
|
$standard->execute($config, $io, $repo, $action); |
177
|
|
|
} |
178
|
|
|
} |
179
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.