Passed
Push — master ( f6d3c0...f5019c )
by Sebastian
01:52
created

PHPTest::testExecuteConstraintApplicable()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

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