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\Runner\Config; |
13
|
|
|
|
14
|
|
|
use CaptainHook\App\Config\Mockery as ConfigMockery; |
15
|
|
|
use CaptainHook\App\Console\IO\Mockery as IOMockery; |
16
|
|
|
use CaptainHook\App\Mockery as CHMockery; |
17
|
|
|
use Exception; |
18
|
|
|
use org\bovigo\vfs\vfsStream; |
19
|
|
|
use PHPUnit\Framework\TestCase; |
|
|
|
|
20
|
|
|
|
21
|
|
|
class EditorTest extends TestCase |
22
|
|
|
{ |
23
|
|
|
use ConfigMockery; |
24
|
|
|
use IOMockery; |
25
|
|
|
use CHMockery; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* Tests Editor::run |
29
|
|
|
* |
30
|
|
|
* @throws \Exception |
31
|
|
|
*/ |
32
|
|
|
public function testInvalidHook(): void |
33
|
|
|
{ |
34
|
|
|
$this->expectException(Exception::class); |
35
|
|
|
|
36
|
|
|
$io = $this->createIOMock(); |
37
|
|
|
$config = $this->createConfigMock(); |
38
|
|
|
|
39
|
|
|
$runner = new Editor($io, $config); |
40
|
|
|
$runner->setHook('foo') |
41
|
|
|
->setChange('EnableHook') |
42
|
|
|
->run(); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* Tests Editor::run |
47
|
|
|
*/ |
48
|
|
|
public function testNoHook(): void |
49
|
|
|
{ |
50
|
|
|
$this->expectException(Exception::class); |
51
|
|
|
|
52
|
|
|
$io = $this->createIOMock(); |
53
|
|
|
$config = $this->createConfigMock(); |
54
|
|
|
$config->expects($this->once())->method('isLoadedFromFile')->willReturn(true); |
|
|
|
|
55
|
|
|
|
56
|
|
|
$runner = new Editor($io, $config); |
57
|
|
|
$runner->setChange('EnableHook') |
58
|
|
|
->run(); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* Tests Editor::run |
63
|
|
|
* |
64
|
|
|
* @throws \Exception |
65
|
|
|
*/ |
66
|
|
|
public function testNoChange(): void |
67
|
|
|
{ |
68
|
|
|
$this->expectException(Exception::class); |
69
|
|
|
|
70
|
|
|
$io = $this->createIOMock(); |
71
|
|
|
$config = $this->createConfigMock(); |
72
|
|
|
$config->expects($this->once())->method('isLoadedFromFile')->willReturn(true); |
73
|
|
|
|
74
|
|
|
$runner = new Editor($io, $config); |
75
|
|
|
$runner->setHook('pre-commit') |
76
|
|
|
->run(); |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* Tests Editor::run |
81
|
|
|
* |
82
|
|
|
* @throws \Exception |
83
|
|
|
*/ |
84
|
|
|
public function testInvalidChange(): void |
85
|
|
|
{ |
86
|
|
|
$this->expectException(Exception::class); |
87
|
|
|
$this->expectExceptionMessage('Invalid change requested'); |
88
|
|
|
|
89
|
|
|
$io = $this->createIOMock(); |
90
|
|
|
$config = $this->createConfigMock(true); |
91
|
|
|
|
92
|
|
|
$runner = new Editor($io, $config); |
93
|
|
|
$runner->setChange('InvalidChange') |
94
|
|
|
->setHook('pre-commit') |
95
|
|
|
->run(); |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
/** |
99
|
|
|
* Tests Editor::run |
100
|
|
|
* |
101
|
|
|
* @throws \Exception |
102
|
|
|
*/ |
103
|
|
|
public function testMissingHook(): void |
104
|
|
|
{ |
105
|
|
|
$this->expectException(Exception::class); |
106
|
|
|
$this->expectExceptionMessage('No hook set'); |
107
|
|
|
|
108
|
|
|
$io = $this->createIOMock(); |
109
|
|
|
$config = $this->createConfigMock(true); |
110
|
|
|
|
111
|
|
|
$runner = new Editor($io, $config); |
112
|
|
|
$runner->setChange('EnableHook') |
113
|
|
|
->run(); |
114
|
|
|
} |
115
|
|
|
|
116
|
|
|
/** |
117
|
|
|
* Tests Editor::run |
118
|
|
|
* |
119
|
|
|
* @throws \Exception |
120
|
|
|
*/ |
121
|
|
|
public function testMissingChange(): void |
122
|
|
|
{ |
123
|
|
|
$this->expectException(Exception::class); |
124
|
|
|
$this->expectExceptionMessage('No change set'); |
125
|
|
|
|
126
|
|
|
$io = $this->createIOMock(); |
127
|
|
|
$config = $this->createConfigMock(true); |
128
|
|
|
|
129
|
|
|
$runner = new Editor($io, $config); |
130
|
|
|
$runner->setHook('pre-commit') |
131
|
|
|
->run(); |
132
|
|
|
} |
133
|
|
|
|
134
|
|
|
/** |
135
|
|
|
* Tests Editor::run |
136
|
|
|
* |
137
|
|
|
* @throws \Exception |
138
|
|
|
*/ |
139
|
|
|
public function testNoConfiguration() |
140
|
|
|
{ |
141
|
|
|
$this->expectException(Exception::class); |
142
|
|
|
|
143
|
|
|
$io = $this->createIOMock(); |
144
|
|
|
$config = $this->createConfigMock(); |
145
|
|
|
$config->expects($this->once())->method('isLoadedFromFile')->willReturn(false); |
146
|
|
|
|
147
|
|
|
$runner = new Editor($io, $config); |
148
|
|
|
$runner->setChange('AddAction') |
149
|
|
|
->setHook('pre-commit') |
150
|
|
|
->run(); |
151
|
|
|
} |
152
|
|
|
|
153
|
|
|
/** |
154
|
|
|
* Tests Editor::run |
155
|
|
|
*/ |
156
|
|
|
public function testConfigureFileExtend() |
157
|
|
|
{ |
158
|
|
|
$configDir = vfsStream::setup('root', null, ['captainhook.json' => '{}']); |
159
|
|
|
|
160
|
|
|
$io = $this->createIOMock(); |
161
|
|
|
$config = $this->createConfigMock(true, $configDir->url() . '/captainhook.json'); |
162
|
|
|
$config->method('getHookConfig')->willReturn($this->createHookConfigMock()); |
|
|
|
|
163
|
|
|
$io->method('ask')->will($this->onConsecutiveCalls('y', 'y', '\\Foo\\Bar', 'y', 'n')); |
|
|
|
|
164
|
|
|
$io->expects($this->once())->method('askAndValidate')->willReturn('foo:bar'); |
|
|
|
|
165
|
|
|
|
166
|
|
|
$runner = new Creator($io, $config); |
167
|
|
|
$runner->extend(true) |
168
|
|
|
->advanced(true) |
169
|
|
|
->run(); |
170
|
|
|
|
171
|
|
|
$this->assertFileExists($configDir->url() . '/captainhook.json'); |
172
|
|
|
} |
173
|
|
|
} |
174
|
|
|
|
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