Passed
Push — master ( 7b0bcd...6035dc )
by Jakub
02:12
created

TestCaseTest::testGetJobs()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 123
Code Lines 104

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 104
c 1
b 0
f 1
nc 1
nop 0
dl 0
loc 123
rs 8

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
declare(strict_types=1);
4
5
namespace MyTester;
6
7
use MyTester\Attributes\DataProvider as DataProviderAttribute;
8
use MyTester\Attributes\Skip;
9
use MyTester\Attributes\Test;
10
use MyTester\Attributes\TestSuite;
11
12
/**
13
 * Test suite for class TestCase
14
 *
15
 * @author Jakub Konečný
16
 */
17
#[TestSuite("TestCase")]
18
final class TestCaseTest extends TestCase
19
{
20
    /** @var bool|int */
21
    private $one = false;
22
23
    public function setUp(): void
24
    {
25
        $this->one = 1;
26
    }
27
28
    public function tearDown(): void
29
    {
30
        $this->one = false;
31
    }
32
33
    public function shutDown(): void
34
    {
35
        $this->assertFalsey($this->one);
36
    }
37
38
    public function testState(): void
39
    {
40
        $this->assertFalse(false);
41
        $this->assertSame(1, $this->getCounter());
42
        $this->incCounter();
43
        $this->assertSame(3, $this->getCounter());
44
        $this->resetCounter();
45
        $this->assertSame(0, $this->getCounter());
46
    }
47
48
    /**
49
     * Test parameters
50
     */
51
    #[DataProviderAttribute("dataProvider")]
52
    public function testParams(string $text): void
53
    {
54
        $this->assertType("string", $text);
55
        $this->assertContains("a", $text);
56
    }
57
58
    public function testParamsNoneProvided(string $text): void
59
    {
60
        $this->assertTrue(false);
61
    }
62
63
    public function dataProvider(): array
64
    {
65
        return ["abc", "adef", ];
66
    }
67
68
    /**
69
     * Test custom test's name
70
     */
71
    #[Test("Custom name")]
72
    public function testTestName(): void
73
    {
74
        $this->assertSame(1, $this->one);
75
    }
76
77
    /**
78
     * Test unconditional skipping
79
     */
80
    #[Test("Skip")]
81
    #[Skip()]
82
    public function testSkip(): void
83
    {
84
        $this->assertTrue(false);
85
    }
86
87
    /**
88
     * Test skipping based on boolean
89
     */
90
    #[Test("Boolean")]
91
    #[Skip(true)]
92
    public function testSkipBoolean(): void
93
    {
94
        $this->assertTrue(false);
95
    }
96
97
    /**
98
     * Test skipping based on integer
99
     */
100
    #[Test("Integer")]
101
    #[Skip(1)]
102
    public function testSkipInteger(): void
103
    {
104
        $this->assertTrue(false);
105
    }
106
107
    /**
108
     * Test skipping based on float
109
     */
110
    #[Test("Float")]
111
    #[Skip(1.5)]
112
    public function testSkipFloat(): void
113
    {
114
        $this->assertTrue(false);
115
    }
116
117
    /**
118
     * Test skipping based on string
119
     */
120
    #[Test("String")]
121
    #[Skip("abc")]
122
    public function testSkipString(): void
123
    {
124
        $this->assertTrue(false);
125
    }
126
127
    /**
128
     * Test skipping based on PHP version
129
     */
130
    #[Test("PHP version")]
131
    #[Skip(["php" => 666])]
132
    public function testSkipPhpVersion(): void
133
    {
134
        $this->assertTrue(false);
135
    }
136
137
    /**
138
     * Test skipping based on sapi
139
     */
140
    #[Test("CGI sapi")]
141
    #[Skip(["sapi" => "abc"])]
142
    public function testCgiSapi(): void
143
    {
144
        $this->assertNotSame(PHP_SAPI, "abc");
145
    }
146
147
    /**
148
     * Test skipping based on loaded extension
149
     */
150
    #[Test("Extension")]
151
    #[Skip(["extension" => "abc"])]
152
    public function testSkipExtension(): void
153
    {
154
        $this->assertTrue(false);
155
    }
156
157
    #[Test("No assertions")]
158
    public function testNoAssertions(): void
159
    {
160
    }
161
162
    public function testGetSuiteName(): void
163
    {
164
        $this->assertSame("TestCase", $this->getSuiteName());
165
    }
166
167
    public function testGetJobName(): void
168
    {
169
        $this->assertSame("TestCase::" . __FUNCTION__, $this->getJobName(self::class, __FUNCTION__));
170
        $this->assertSame("Extension", $this->getJobName(self::class, "testSkipExtension"));
171
    }
172
173
    public function testGetJobs(): void
174
    {
175
        $jobs = $this->getJobs();
176
        $this->assertCount(17, $jobs);
177
178
        $job = $jobs[0];
179
        $this->assertSame("TestCase::testState", $job->name);
180
        $this->assertSame([$this, "testState", ], $job->callback);
181
        $this->assertSame([], $job->params);
182
        $this->assertFalse((bool) $job->skip);
183
        $this->assertCount(1, $job->onAfterExecute);
184
185
        $job = $jobs[1];
186
        $this->assertSame("TestCase::testParams", $job->name);
187
        $this->assertSame([$this, "testParams", ], $job->callback);
188
        $this->assertSame(["abc", ], $job->params);
189
        $this->assertFalse((bool) $job->skip);
190
        $this->assertCount(1, $job->onAfterExecute);
191
192
        $job = $jobs[2];
193
        $this->assertSame("TestCase::testParams", $job->name);
194
        $this->assertSame([$this, "testParams", ], $job->callback);
195
        $this->assertSame(["adef", ], $job->params);
196
        $this->assertFalse((bool) $job->skip);
197
        $this->assertCount(1, $job->onAfterExecute);
198
199
        $job = $jobs[3];
200
        $this->assertSame("TestCase::testParamsNoneProvided", $job->name);
201
        $this->assertSame([$this, "testParamsNoneProvided", ], $job->callback);
202
        $this->assertSame([], $job->params);
203
        $this->assertSame("Method requires at least 1 parameter but data provider does not provide any.", $job->skip);
204
        $this->assertCount(1, $job->onAfterExecute);
205
206
        $job = $jobs[4];
207
        $this->assertSame("Custom name", $job->name);
208
        $this->assertSame([$this, "testTestName", ], $job->callback);
209
        $this->assertSame([], $job->params);
210
        $this->assertFalse((bool) $job->skip);
211
        $this->assertCount(1, $job->onAfterExecute);
212
213
        $job = $jobs[5];
214
        $this->assertSame("Skip", $job->name);
215
        $this->assertSame([$this, "testSkip", ], $job->callback);
216
        $this->assertSame([], $job->params);
217
        $this->assertTrue((bool) $job->skip);
218
        $this->assertCount(1, $job->onAfterExecute);
219
220
        $job = $jobs[6];
221
        $this->assertSame("Boolean", $job->name);
222
        $this->assertSame([$this, "testSkipBoolean", ], $job->callback);
223
        $this->assertSame([], $job->params);
224
        $this->assertTrue((bool) $job->skip);
225
        $this->assertCount(1, $job->onAfterExecute);
226
227
        $job = $jobs[7];
228
        $this->assertSame("Integer", $job->name);
229
        $this->assertSame([$this, "testSkipInteger", ], $job->callback);
230
        $this->assertSame([], $job->params);
231
        $this->assertTrue((bool) $job->skip);
232
        $this->assertCount(1, $job->onAfterExecute);
233
234
        $job = $jobs[8];
235
        $this->assertSame("Float", $job->name);
236
        $this->assertSame([$this, "testSkipFloat", ], $job->callback);
237
        $this->assertSame([], $job->params);
238
        $this->assertTrue((bool) $job->skip);
239
        $this->assertCount(1, $job->onAfterExecute);
240
241
        $job = $jobs[9];
242
        $this->assertSame("String", $job->name);
243
        $this->assertSame([$this, "testSkipString", ], $job->callback);
244
        $this->assertSame([], $job->params);
245
        $this->assertTrue((bool) $job->skip);
246
        $this->assertCount(1, $job->onAfterExecute);
247
248
        $job = $jobs[10];
249
        $this->assertSame("PHP version", $job->name);
250
        $this->assertSame([$this, "testSkipPhpVersion", ], $job->callback);
251
        $this->assertSame([], $job->params);
252
        $this->assertTrue((bool) $job->skip);
253
        $this->assertCount(1, $job->onAfterExecute);
254
255
        $job = $jobs[11];
256
        $this->assertSame("CGI sapi", $job->name);
257
        $this->assertSame([$this, "testCgiSapi", ], $job->callback);
258
        $this->assertSame([], $job->params);
259
        $this->assertTrue((bool) $job->skip);
260
        $this->assertCount(1, $job->onAfterExecute);
261
262
        $job = $jobs[12];
263
        $this->assertSame("Extension", $job->name);
264
        $this->assertSame([$this, "testSkipExtension", ], $job->callback);
265
        $this->assertSame([], $job->params);
266
        $this->assertTrue((bool) $job->skip);
267
        $this->assertCount(1, $job->onAfterExecute);
268
269
        $job = $jobs[13];
270
        $this->assertSame("No assertions", $job->name);
271
        $this->assertSame([$this, "testNoAssertions", ], $job->callback);
272
        $this->assertSame([], $job->params);
273
        $this->assertFalse((bool) $job->skip);
274
        $this->assertCount(1, $job->onAfterExecute);
275
276
        $job = $jobs[14];
277
        $this->assertSame("TestCase::testGetSuiteName", $job->name);
278
        $this->assertSame([$this, "testGetSuiteName", ], $job->callback);
279
        $this->assertSame([], $job->params);
280
        $this->assertFalse((bool) $job->skip);
281
        $this->assertCount(1, $job->onAfterExecute);
282
283
        $job = $jobs[15];
284
        $this->assertSame("TestCase::testGetJobName", $job->name);
285
        $this->assertSame([$this, "testGetJobName", ], $job->callback);
286
        $this->assertSame([], $job->params);
287
        $this->assertFalse((bool) $job->skip);
288
        $this->assertCount(1, $job->onAfterExecute);
289
290
        $job = $jobs[16];
291
        $this->assertSame("TestCase::testGetJobs", $job->name);
292
        $this->assertSame([$this, "testGetJobs", ], $job->callback);
293
        $this->assertSame([], $job->params);
294
        $this->assertFalse((bool) $job->skip);
295
        $this->assertCount(1, $job->onAfterExecute);
296
    }
297
}
298