1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* This file is part of CaptainHook. |
4
|
|
|
* |
5
|
|
|
* (c) Sebastian Feldmann <[email protected]> |
6
|
|
|
* |
7
|
|
|
* For the full copyright and license information, please view the LICENSE |
8
|
|
|
* file that was distributed with this source code. |
9
|
|
|
*/ |
10
|
|
|
namespace CaptainHook\App\Config; |
11
|
|
|
|
12
|
|
|
use PHPUnit\Framework\TestCase; |
13
|
|
|
|
14
|
|
|
class UtilTest extends TestCase |
15
|
|
|
{ |
16
|
|
|
/** |
17
|
|
|
* Tests Util::validateJsonConfiguration |
18
|
|
|
*/ |
19
|
|
|
public function testEnabledMissing(): void |
20
|
|
|
{ |
21
|
|
|
$this->expectException(\Exception::class); |
22
|
|
|
|
23
|
|
|
Util::validateJsonConfiguration(['pre-commit' => ['actions' => []]]); |
24
|
|
|
} |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* Tests Util::validateJsonConfiguration |
28
|
|
|
*/ |
29
|
|
|
public function testActionsMissing(): void |
30
|
|
|
{ |
31
|
|
|
$this->expectException(\Exception::class); |
32
|
|
|
|
33
|
|
|
Util::validateJsonConfiguration(['pre-commit' => ['enabled' => true]]); |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* Tests Util::validateJsonConfiguration |
38
|
|
|
*/ |
39
|
|
|
public function testActionsNoArray(): void |
40
|
|
|
{ |
41
|
|
|
$this->expectException(\Exception::class); |
42
|
|
|
|
43
|
|
|
Util::validateJsonConfiguration(['pre-commit' => ['enabled' => true, 'actions' => false]]); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* Tests Util::validateJsonConfiguration |
48
|
|
|
*/ |
49
|
|
|
public function testActionMissing(): void |
50
|
|
|
{ |
51
|
|
|
$this->expectException(\Exception::class); |
52
|
|
|
|
53
|
|
|
Util::validateJsonConfiguration( |
54
|
|
|
[ |
55
|
|
|
'pre-commit' => [ |
56
|
|
|
'enabled' => true, |
57
|
|
|
'actions' => [ |
58
|
|
|
['options' => []] |
59
|
|
|
] |
60
|
|
|
] |
61
|
|
|
] |
62
|
|
|
); |
63
|
|
|
|
64
|
|
|
$this->assertTrue(true); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* Tests Util::validateJsonConfiguration |
69
|
|
|
*/ |
70
|
|
|
public function testActionEmpty(): void |
71
|
|
|
{ |
72
|
|
|
$this->expectException(\Exception::class); |
73
|
|
|
|
74
|
|
|
Util::validateJsonConfiguration( |
75
|
|
|
[ |
76
|
|
|
'pre-commit' => [ |
77
|
|
|
'enabled' => true, |
78
|
|
|
'actions' => [ |
79
|
|
|
['action' => ''] |
80
|
|
|
] |
81
|
|
|
] |
82
|
|
|
] |
83
|
|
|
); |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* Tests Util::validateJsonConfiguration |
88
|
|
|
*/ |
89
|
|
|
public function testConditionExecMissing(): void |
90
|
|
|
{ |
91
|
|
|
$this->expectException(\Exception::class); |
92
|
|
|
|
93
|
|
|
Util::validateJsonConfiguration( |
94
|
|
|
[ |
95
|
|
|
'pre-commit' => [ |
96
|
|
|
'enabled' => true, |
97
|
|
|
'actions' => [ |
98
|
|
|
[ |
99
|
|
|
'action' => 'foo', |
100
|
|
|
'conditions' => [ |
101
|
|
|
[ |
102
|
|
|
'args' => [ |
103
|
|
|
'foo' => 'fiz', |
104
|
|
|
'bar' => 'baz' |
105
|
|
|
] |
106
|
|
|
] |
107
|
|
|
] |
108
|
|
|
] |
109
|
|
|
] |
110
|
|
|
] |
111
|
|
|
] |
112
|
|
|
); |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
/** |
116
|
|
|
* Tests Util::validateJsonConfiguration |
117
|
|
|
*/ |
118
|
|
|
public function testConditionArgsNoArray(): void |
119
|
|
|
{ |
120
|
|
|
$this->expectException(\Exception::class); |
121
|
|
|
|
122
|
|
|
Util::validateJsonConfiguration( |
123
|
|
|
[ |
124
|
|
|
'pre-commit' => [ |
125
|
|
|
'enabled' => true, |
126
|
|
|
'actions' => [ |
127
|
|
|
[ |
128
|
|
|
'action' => 'foo', |
129
|
|
|
'conditions' => [ |
130
|
|
|
[ |
131
|
|
|
'exec' => '\\Foo', |
132
|
|
|
'args' => 'fooBarBaz' |
133
|
|
|
] |
134
|
|
|
] |
135
|
|
|
] |
136
|
|
|
] |
137
|
|
|
] |
138
|
|
|
] |
139
|
|
|
); |
140
|
|
|
} |
141
|
|
|
|
142
|
|
|
|
143
|
|
|
/** |
144
|
|
|
* Tests Util::validateJsonConfiguration |
145
|
|
|
*/ |
146
|
|
|
public function testValid(): void |
147
|
|
|
{ |
148
|
|
|
Util::validateJsonConfiguration( |
149
|
|
|
[ |
150
|
|
|
'pre-commit' => [ |
151
|
|
|
'enabled' => true, |
152
|
|
|
'actions' => [ |
153
|
|
|
['action' => 'foo'] |
154
|
|
|
] |
155
|
|
|
] |
156
|
|
|
] |
157
|
|
|
); |
158
|
|
|
|
159
|
|
|
$this->assertTrue(true); |
160
|
|
|
} |
161
|
|
|
|
162
|
|
|
/** |
163
|
|
|
* Tests Util::validateJsonConfiguration |
164
|
|
|
*/ |
165
|
|
|
public function testValidWithCondition(): void |
166
|
|
|
{ |
167
|
|
|
Util::validateJsonConfiguration( |
168
|
|
|
[ |
169
|
|
|
'pre-commit' => [ |
170
|
|
|
'enabled' => true, |
171
|
|
|
'actions' => [ |
172
|
|
|
[ |
173
|
|
|
'action' => 'foo', |
174
|
|
|
'conditions' => [ |
175
|
|
|
[ |
176
|
|
|
'exec' => '\\Fiz\\Baz', |
177
|
|
|
'args' => [ |
178
|
|
|
'foo' => 'fiz', |
179
|
|
|
'bar' => 'baz' |
180
|
|
|
] |
181
|
|
|
] |
182
|
|
|
] |
183
|
|
|
] |
184
|
|
|
] |
185
|
|
|
] |
186
|
|
|
] |
187
|
|
|
); |
188
|
|
|
|
189
|
|
|
$this->assertTrue(true); |
190
|
|
|
} |
191
|
|
|
} |
192
|
|
|
|