PHPTest::testExecuteStaticMethodNotFound()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 16
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 10
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 16
rs 9.9332
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\Action;
13
14
use CaptainHook\App\Config\Mockery as ConfigMockery;
15
use CaptainHook\App\Console\IO\Mockery as IOMockery;
16
use CaptainHook\App\Event\Dispatcher;
17
use CaptainHook\App\Mockery as CHMockery;
18
use Exception;
19
use PHPUnit\Framework\TestCase;
20
21
class PHPTest extends TestCase
22
{
23
    use ConfigMockery;
24
    use IOMockery;
25
    use CHMockery;
26
27
    public function testExecuteSuccess(): void
28
    {
29
        $config = $this->createConfigMock();
30
        $io     = $this->createIOMock();
31
        $repo   = $this->createRepositoryMock();
32
        $action = $this->createActionConfigMock();
33
        $events = new Dispatcher($io, $config, $repo);
34
        $class  = DummyPHPSuccess::class;
35
36
        $action->expects($this->once())->method('getAction')->willReturn($class);
37
38
        $php = new PHP('pre-commit', $events);
39
        $php->execute($config, $io, $repo, $action);
40
    }
41
42
    public function testExecuteEventSubscriber(): void
43
    {
44
        $config = $this->createConfigMock();
45
        $io     = $this->createIOMock();
46
        $repo   = $this->createRepositoryMock();
47
        $action = $this->createActionConfigMock();
48
        $events = new Dispatcher($io, $config, $repo);
49
        $class  = DummyPHPSubscriber::class;
50
51
        $action->expects($this->once())->method('getAction')->willReturn($class);
52
53
        $php = new PHP('pre-commit', $events);
54
        $php->execute($config, $io, $repo, $action);
55
    }
56
57
    public function testExecuteConstraintApplicable(): void
58
    {
59
        $config = $this->createConfigMock();
60
        $io     = $this->createIOMock();
61
        $repo   = $this->createRepositoryMock();
62
        $action = $this->createActionConfigMock();
63
        $events = new Dispatcher($io, $config, $repo);
64
        $class  = DummyPHPConstraint::class;
65
66
        $action->expects($this->once())->method('getAction')->willReturn($class);
67
68
        $php = new PHP('pre-commit', $events);
69
        $php->execute($config, $io, $repo, $action);
70
    }
71
72
    public function testExecuteConstraintNotApplicable(): void
73
    {
74
        $config = $this->createConfigMock();
75
        $io     = $this->createIOMock();
76
        $repo   = $this->createRepositoryMock();
77
        $action = $this->createActionConfigMock();
78
        $events = new Dispatcher($io, $config, $repo);
79
        $class  = DummyPHPConstraint::class;
80
81
        $action->expects($this->once())->method('getAction')->willReturn($class);
82
83
        $php = new PHP('pre-push', $events);
84
        $php->execute($config, $io, $repo, $action);
85
    }
86
87
    public function testExecuteFailure(): void
88
    {
89
        $this->expectException(Exception::class);
90
91
        $config = $this->createConfigMock();
92
        $io     = $this->createIOMock();
93
        $repo   = $this->createRepositoryMock();
94
        $action = $this->createActionConfigMock();
95
        $events = new Dispatcher($io, $config, $repo);
96
        $class  = DummyPHPFailure::class;
97
98
        $action->expects($this->once())->method('getAction')->willReturn($class);
99
100
        $php = new PHP('pre-commit', $events);
101
        $php->execute($config, $io, $repo, $action);
102
    }
103
104
    public function testExecuteError(): void
105
    {
106
        $this->expectException(Exception::class);
107
108
        $config = $this->createConfigMock();
109
        $io     = $this->createIOMock();
110
        $repo   = $this->createRepositoryMock();
111
        $action = $this->createActionConfigMock();
112
        $events = new Dispatcher($io, $config, $repo);
113
        $class  = DummyPHPError::class;
114
115
        $action->expects($this->once())->method('getAction')->willReturn($class);
116
117
        $php = new PHP('pre-commit', $events);
118
        $php->execute($config, $io, $repo, $action);
119
    }
120
121
    public function testExecuteByShorthand(): void
122
    {
123
        $this->expectException(Exception::class);
124
        $this->expectExceptionMessageMatches('/debugging/i');
125
126
        $config = $this->createConfigMock();
127
        $io     = $this->createIOMock();
128
        $repo   = $this->createRepositoryMock();
129
        $action = $this->createActionConfigMock();
130
        $events = new Dispatcher($io, $config, $repo);
131
        $class  = 'CaptainHook.Debug.fail';
132
133
        $action->expects($this->once())->method('getAction')->willReturn($class);
134
135
        $php = new PHP('pre-commit', $events);
136
        $php->execute($config, $io, $repo, $action);
137
    }
138
139
    public function testExecuteNoAction(): void
140
    {
141
        $this->expectException(Exception::class);
142
143
        $config = $this->createConfigMock();
144
        $io     = $this->createIOMock();
145
        $repo   = $this->createRepositoryMock();
146
        $action = $this->createActionConfigMock();
147
        $events = new Dispatcher($io, $config, $repo);
148
        $class  = DummyNoAction::class;
149
150
        $action->expects($this->once())->method('getAction')->willReturn($class);
151
152
        $php = new PHP('pre-commit', $events);
153
        $php->execute($config, $io, $repo, $action);
154
    }
155
156
    public function testExecuteStaticClassNotFound(): void
157
    {
158
        $this->expectException(Exception::class);
159
160
        $config = $this->createConfigMock();
161
        $io     = $this->createIOMock();
162
        $repo   = $this->createRepositoryMock();
163
        $action = $this->createActionConfigMock();
164
        $events = new Dispatcher($io, $config, $repo);
165
166
        $class = '\\Fiz::baz';
167
168
        $action->expects($this->once())->method('getAction')->willReturn($class);
169
170
        $php = new PHP('pre-commit', $events);
171
        $php->execute($config, $io, $repo, $action);
172
    }
173
174
    public function testExecuteStaticMethodNotFound(): void
175
    {
176
        $this->expectException(Exception::class);
177
178
        $config = $this->createConfigMock();
179
        $io     = $this->createIOMock();
180
        $repo   = $this->createRepositoryMock();
181
        $action = $this->createActionConfigMock();
182
        $events = new Dispatcher($io, $config, $repo);
183
184
        $class = '\\CaptainHook\\App\\Runner\\Action\\DummyNoAction::foo';
185
186
        $action->expects($this->once())->method('getAction')->willReturn($class);
187
188
        $php = new PHP('pre-commit', $events);
189
        $php->execute($config, $io, $repo, $action);
190
    }
191
192
    public function testExecuteStaticSuccess(): void
193
    {
194
        $config = $this->createConfigMock();
195
        $io     = $this->createIOMock();
196
        $repo   = $this->createRepositoryMock();
197
        $action = $this->createActionConfigMock();
198
        $events = new Dispatcher($io, $config, $repo);
199
200
        $class = '\\CaptainHook\\App\\Runner\\Action\\DummyPHPSuccess::executeStatic';
201
202
        $action->expects($this->once())->method('getAction')->willReturn($class);
203
204
        $php = new PHP('pre-commit', $events);
205
        $php->execute($config, $io, $repo, $action);
206
    }
207
}
208