Total Complexity | 40 |
Total Lines | 735 |
Duplicated Lines | 0 % |
Changes | 0 |
Complex classes like DropdownTest often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use DropdownTest, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
16 | class DropdownTest extends ComponentTest |
||
17 | { |
||
18 | public function testDefaultToString() |
||
19 | { |
||
20 | $sut = $this->createNode(); |
||
21 | |||
22 | $this->assertSame('<div><ul></ul></div>', (string)$sut); |
||
23 | } |
||
24 | |||
25 | public function testToStringWithoutWrapper() |
||
26 | { |
||
27 | $sut = $this->createNode(); |
||
28 | |||
29 | $sut->setWrapper(null); |
||
30 | |||
31 | $this->assertSame('<ul></ul>', (string)$sut); |
||
32 | } |
||
33 | |||
34 | /** |
||
35 | * @return array |
||
36 | */ |
||
37 | public function toStringWithTranslationProvider(): array |
||
38 | { |
||
39 | return [ |
||
40 | ['AAA', ['AAA' => 'BBB'], '<div><ul><li>BBB</li></ul></div>'], |
||
41 | ]; |
||
42 | } |
||
43 | |||
44 | /** |
||
45 | * @return array |
||
46 | */ |
||
47 | public function toStringReturnsRawContentByDefaultProvider(): array |
||
48 | { |
||
49 | return [ |
||
50 | 'IItem' => [new Item('foo'), '<li>foo</li>'], |
||
51 | 'IItem[]' => [[new Item('foo')], '<li>foo</li>'], |
||
52 | ]; |
||
53 | } |
||
54 | |||
55 | /** |
||
56 | * @return array |
||
57 | */ |
||
58 | public function toStringCanReturnTranslatedContentProvider(): array |
||
59 | { |
||
60 | $translations = ['foo' => 'bar']; |
||
61 | |||
62 | return [ |
||
63 | 'IItem' => [new Item('foo'), $translations, '<li>bar</li>'], |
||
64 | 'IItem[]' => [[new Item('foo')], $translations, '<li>bar</li>'], |
||
65 | ]; |
||
66 | } |
||
67 | |||
68 | /** |
||
69 | * @return array |
||
70 | */ |
||
71 | public function findProvider(): array |
||
72 | { |
||
73 | $node1 = new Item('1'); |
||
74 | $node2 = new Item('2'); |
||
75 | |||
76 | return [ |
||
77 | [[], $node1, null], |
||
78 | [[$node2], $node1, null], |
||
79 | [[$node1, $node2], $node1, 0], |
||
80 | [[$node1, $node2], $node2, 1], |
||
81 | ]; |
||
82 | } |
||
83 | |||
84 | /** |
||
85 | * @return array |
||
86 | */ |
||
87 | public function findFirstChildProvider(): array |
||
88 | { |
||
89 | $item0 = new Item('0'); |
||
90 | $item1 = (new Item('1'))->setIntent('foo'); |
||
91 | $item2 = (new Item('2'))->setIntent('bar'); |
||
92 | $item3 = (new Item('3'))->setIntent('foo', 'bar'); |
||
93 | $content = [$item0, $item1, $item2, $item3]; |
||
94 | |||
95 | return [ |
||
96 | 'INode-no-intent' => [$content, INode::class, [], $item0], |
||
97 | 'INode-foo-intent' => [$content, INode::class, ['foo'], $item1], |
||
98 | 'INode-bar-intent' => [$content, INode::class, ['bar'], $item2], |
||
99 | 'INode-foo-and-bar-intent' => [$content, INode::class, ['foo', 'bar'], $item3], |
||
100 | 'IComponent-foo-intent' => [$content, IComponent::class, ['foo'], $item1], |
||
101 | 'Component-foo-intent' => [$content, Component::class, ['foo'], $item1], |
||
102 | 'fail-INode-baz-intent' => [$content, INode::class, ['baz'], null], |
||
103 | 'fail-INode-foo-and-baz-intent' => [$content, INode::class, ['foo', 'baz'], null], |
||
104 | 'fail-Node-foo-intent' => [$content, Node::class, ['foo'], null], |
||
105 | 'Item-foo-intent' => [$content, Item::class, ['foo'], $item1], |
||
106 | ]; |
||
107 | } |
||
108 | |||
109 | /** |
||
110 | * @return array |
||
111 | */ |
||
112 | public function collectProvider(): array |
||
113 | { |
||
114 | $node0 = new Node('0'); |
||
115 | $item0 = new Item($node0); |
||
116 | $node1 = new Node('1', ['foo']); |
||
117 | $node2 = new Node('2', ['bar']); |
||
118 | $node3 = new Node('3', ['foo', 'bar']); |
||
119 | $collection4 = new Collection([$node3, $node1, $node2]); |
||
120 | $item5 = new Item([$collection4]); |
||
121 | $content = [$item0, $item5]; |
||
122 | |||
123 | $level0Expected = [$item0, $item5]; |
||
124 | $level1Expected = [$item0, $node0, $item5, $collection4]; |
||
125 | $defaultExpected = [$item0, $node0, $item5, $collection4, $node3, $node1, $node2]; |
||
126 | $fooOnlyExpected = [$node3, $node1]; |
||
127 | $fooBarOnlyExpected = [$node3]; |
||
128 | |||
129 | return [ |
||
130 | '0-depth' => [$content, null, 0, [], $level0Expected], |
||
131 | '1-depth' => [$content, null, 1, [], $level1Expected], |
||
132 | 'default' => [$content, null, -1, [], $defaultExpected], |
||
133 | 'inode-only' => [$content, INode::class, -1, [], $defaultExpected], |
||
134 | 'stdclass-only' => [$content, \stdClass::class, -1, [], []], |
||
135 | 'foo-only' => [$content, null, -1, ['foo'], $fooOnlyExpected], |
||
136 | 'foo-bar-only' => [$content, null, -1, ['foo', 'bar'], $fooBarOnlyExpected], |
||
137 | ]; |
||
138 | } |
||
139 | |||
140 | public function testCountWithExplicitOffset() |
||
141 | { |
||
142 | $expectedResult = 2; |
||
143 | |||
144 | $item1 = new Item('1'); |
||
145 | $item2 = new Item('2'); |
||
146 | |||
147 | $sut = $this->createNode(); |
||
148 | |||
149 | $sut[0] = $item1; |
||
150 | $sut[1] = $item2; |
||
151 | |||
152 | $this->assertSame($expectedResult, count($sut)); |
||
153 | } |
||
154 | |||
155 | public function testCountWithMixedOffset() |
||
156 | { |
||
157 | $item1 = new Item('1'); |
||
158 | $item2 = new Item('2'); |
||
159 | |||
160 | $expectedCount = 5; |
||
161 | |||
162 | $sut = $this->createNode(); |
||
163 | |||
164 | $sut[] = $item1; |
||
165 | $sut[] = $item1; |
||
166 | $sut[1] = $item2; |
||
167 | $sut[2] = $item1; |
||
168 | $sut[3] = $item1; |
||
169 | $sut[] = $item1; |
||
170 | |||
171 | $this->assertSame($expectedCount, count($sut)); |
||
172 | } |
||
173 | |||
174 | public function testArrayAccessWithoutOffset() |
||
175 | { |
||
176 | $item1 = new Item('1'); |
||
177 | $item2 = new Item('2'); |
||
178 | |||
179 | $sut = $this->createNode(); |
||
180 | |||
181 | $sut[] = $item1; |
||
182 | $sut[] = $item2; |
||
183 | |||
184 | $this->assertSame($item1, $sut[0]); |
||
185 | $this->assertSame($item2, $sut[1]); |
||
186 | } |
||
187 | |||
188 | public function testArrayAccessWithExplicitOffset() |
||
189 | { |
||
190 | $item1 = new Item('1'); |
||
191 | $item2 = new Item('2'); |
||
192 | |||
193 | $sut = $this->createNode(); |
||
194 | |||
195 | $sut[0] = $item1; |
||
196 | $sut[1] = $item2; |
||
197 | |||
198 | $this->assertSame($item1, $sut[0]); |
||
199 | $this->assertSame($item2, $sut[1]); |
||
200 | } |
||
201 | |||
202 | public function testArrayAccessThrowExceptionWhenMadeDirty() |
||
203 | { |
||
204 | $this->expectException(\InvalidArgumentException::class); |
||
205 | |||
206 | $item1 = new Item('1'); |
||
207 | |||
208 | $sut = $this->createNode(); |
||
209 | |||
210 | $sut[1] = $item1; |
||
211 | } |
||
212 | |||
213 | public function testArrayAccessWithMixedOffset() |
||
214 | { |
||
215 | $item1 = new Item('1'); |
||
216 | $item2 = new Item('2'); |
||
217 | |||
218 | $sut = $this->createNode(); |
||
219 | |||
220 | $sut[] = $item1; |
||
221 | $sut[] = $item1; |
||
222 | $sut[1] = $item2; |
||
223 | $sut[2] = $item1; |
||
224 | $sut[3] = $item1; |
||
225 | $sut[] = $item1; |
||
226 | |||
227 | $expectedNodes = [0 => $item1, 1 => $item2, 2 => $item1, 3 => $item1, 4 => $item1]; |
||
228 | foreach ($expectedNodes as $idx => $item) { |
||
229 | $this->assertEquals($item, $sut[$idx]); |
||
230 | } |
||
231 | } |
||
232 | |||
233 | /** |
||
234 | * @return array |
||
235 | */ |
||
236 | public function contentFailureProvider(): array |
||
237 | { |
||
238 | return [ |
||
239 | 'bool' => [true], |
||
240 | 'non-node object' => [new \StdClass()], |
||
241 | 'string wrapped' => [['']], |
||
242 | 'non-node object wrapped' => [[new \StdClass()]], |
||
243 | 'node double wrapped' => [[[new Node()]]], |
||
244 | ]; |
||
245 | } |
||
246 | |||
247 | public function testCountWithoutOffset() |
||
248 | { |
||
249 | $expectedResult = 2; |
||
250 | |||
251 | $item1 = new Item('1'); |
||
252 | $item2 = new Item('2'); |
||
253 | |||
254 | $sut = $this->createNode(); |
||
255 | |||
256 | $sut[] = $item1; |
||
257 | $sut[] = $item2; |
||
258 | |||
259 | $this->assertSame($expectedResult, count($sut)); |
||
260 | } |
||
261 | |||
262 | public function testSetContent() |
||
263 | { |
||
264 | $item1 = new Item('1'); |
||
265 | $item2 = new Item('2'); |
||
266 | |||
267 | $expectedNodes = [new Item('3')]; |
||
268 | |||
269 | $sut = $this->createNode(); |
||
270 | |||
271 | $sut[] = $item1; |
||
272 | $sut[] = $item1; |
||
273 | $sut[1] = $item2; |
||
274 | $sut[2] = $item1; |
||
275 | $sut[3] = $item1; |
||
276 | $sut[] = $item1; |
||
277 | |||
278 | $sut->setContent('3'); |
||
279 | |||
280 | $actualResult = $sut->getNodes(); |
||
281 | |||
282 | $this->assertEquals($expectedNodes, $actualResult); |
||
283 | } |
||
284 | |||
285 | public function testGetNodes() |
||
286 | { |
||
287 | $item1 = new Item('1'); |
||
288 | $item2 = new Item('2'); |
||
289 | |||
290 | $expectedNodes = [$item1, $item2, $item1, $item1, $item1]; |
||
291 | |||
292 | $sut = $this->createNode(); |
||
293 | |||
294 | $sut[] = $item1; |
||
295 | $sut[] = $item1; |
||
296 | $sut[1] = $item2; |
||
297 | $sut[2] = $item1; |
||
298 | $sut[3] = $item1; |
||
299 | $sut[] = $item1; |
||
300 | |||
301 | $actualResult = $sut->getNodes(); |
||
302 | |||
303 | $this->assertEquals($expectedNodes, $actualResult); |
||
304 | } |
||
305 | |||
306 | public function testGetExtendedNodes() |
||
307 | { |
||
308 | $item1 = new Item('1'); |
||
309 | $item2 = new Item('2'); |
||
310 | |||
311 | $expectedNodes = [$item1, $item2, $item1, $item1, $item1]; |
||
312 | |||
313 | $sut = $this->createNode(); |
||
314 | |||
315 | $sut[] = $item1; |
||
316 | $sut[] = $item1; |
||
317 | $sut[1] = $item2; |
||
318 | $sut[2] = $item1; |
||
319 | $sut[3] = $item1; |
||
320 | $sut[] = $item1; |
||
321 | |||
322 | $actualResult = $sut->getExtendedNodes(); |
||
323 | |||
324 | $this->assertCount(8, $actualResult); |
||
325 | $this->assertInstanceOf(Collection::class, $actualResult[0]); |
||
326 | $this->assertInstanceOf(Collection::class, $actualResult[1]); |
||
327 | $this->assertInstanceOf(Component::class, $actualResult[2]); |
||
328 | $this->assertSame($expectedNodes, array_slice($actualResult, 3)); |
||
329 | } |
||
330 | |||
331 | public function testGetDescendantNodes() |
||
332 | { |
||
333 | $itemContent1 = new Node('1'); |
||
334 | $itemContent2 = new Node('2'); |
||
335 | |||
336 | $item1 = new Item($itemContent1); |
||
337 | $item2 = new Item($itemContent2); |
||
338 | |||
339 | $expectedNodes = [ |
||
340 | $item1, $itemContent1, |
||
341 | $item2, $itemContent2, |
||
342 | $item1, $itemContent1, |
||
343 | $item1, $itemContent1, |
||
344 | $item1, $itemContent1 |
||
345 | ]; |
||
346 | |||
347 | $sut = $this->createNode(); |
||
348 | |||
349 | $sut[] = $item1; |
||
350 | $sut[] = $item1; |
||
351 | $sut[1] = $item2; |
||
352 | $sut[2] = $item1; |
||
353 | $sut[3] = $item1; |
||
354 | $sut[] = $item1; |
||
355 | |||
356 | $actualResult = $sut->getDescendantNodes(); |
||
357 | |||
358 | $this->assertEquals($expectedNodes, $actualResult); |
||
359 | } |
||
360 | |||
361 | public function testGetExtendedDescendantNodes() |
||
362 | { |
||
363 | $itemContent1 = new Node('1'); |
||
364 | $itemContent2 = new Node('2'); |
||
365 | |||
366 | $item1 = new Item($itemContent1); |
||
367 | $item2 = new Item($itemContent2); |
||
368 | |||
369 | $expectedNodes = [ |
||
370 | $item1, $itemContent1, |
||
371 | $item2, $itemContent2, |
||
372 | $item1, $itemContent1, |
||
373 | $item1, $itemContent1, |
||
374 | $item1, $itemContent1 |
||
375 | ]; |
||
376 | |||
377 | $sut = $this->createNode(); |
||
378 | |||
379 | $sut[] = $item1; |
||
380 | $sut[] = $item1; |
||
381 | $sut[1] = $item2; |
||
382 | $sut[2] = $item1; |
||
383 | $sut[3] = $item1; |
||
384 | $sut[] = $item1; |
||
385 | |||
386 | $actualResult = $sut->getExtendedDescendantNodes(); |
||
387 | |||
388 | $this->assertCount(13, $actualResult); |
||
389 | $this->assertInstanceOf(Collection::class, $actualResult[0]); |
||
390 | $this->assertInstanceOf(Collection::class, $actualResult[1]); |
||
391 | $this->assertInstanceOf(Component::class, $actualResult[2]); |
||
392 | $this->assertSame($expectedNodes, array_slice($actualResult, 3)); |
||
393 | } |
||
394 | |||
395 | public function testIterator() |
||
396 | { |
||
397 | $item1 = new Item('1'); |
||
398 | $item2 = new Item('2'); |
||
399 | |||
400 | $expectedKeys = [0, 1, 2, 3, 4]; |
||
401 | $expectedNodes = [$item1, $item2, $item1, $item1, $item1]; |
||
402 | |||
403 | $sut = $this->createNode(); |
||
404 | |||
405 | $sut[] = $item1; |
||
406 | $sut[] = $item1; |
||
407 | $sut[1] = $item2; |
||
408 | $sut[2] = $item1; |
||
409 | $sut[3] = $item1; |
||
410 | $sut[] = $item1; |
||
411 | |||
412 | $pos = 0; |
||
413 | foreach ($sut as $key => $node) { |
||
414 | $this->assertSame($expectedKeys[$pos], $key); |
||
415 | $this->assertSame($expectedNodes[$pos], $node); |
||
416 | $pos++; |
||
417 | } |
||
418 | } |
||
419 | |||
420 | /** |
||
421 | * @return array |
||
422 | */ |
||
423 | public function insertBeforeProvider(): array |
||
424 | { |
||
425 | $needle = new Item('1'); |
||
426 | $item2 = new Item('2'); |
||
427 | $item3 = new Item('3'); |
||
428 | |||
429 | return [ |
||
430 | 'empty-content' => [ |
||
431 | [], |
||
432 | $needle, |
||
433 | [$item2], |
||
434 | false, |
||
435 | [], |
||
436 | ], |
||
437 | 'only-non-matching-content' => [ |
||
438 | [$item2, $item3], |
||
439 | $needle, |
||
440 | [$needle, $item3], |
||
441 | false, |
||
442 | [$item2, $item3], |
||
443 | ], |
||
444 | 'only-matching-content' => [ |
||
445 | [$needle], |
||
446 | $needle, |
||
447 | [$item2, $item3], |
||
448 | true, |
||
449 | [$item2, $item3, $needle], |
||
450 | ], |
||
451 | 'non-first-matching-content' => [ |
||
452 | [$item2, $needle], |
||
453 | $needle, |
||
454 | [$item3, $item3], |
||
455 | true, |
||
456 | [$item2, $item3, $item3, $needle], |
||
457 | ], |
||
458 | ]; |
||
459 | } |
||
460 | |||
461 | /** |
||
462 | * @return array |
||
463 | */ |
||
464 | public function insertAfterProvider(): array |
||
498 | ], |
||
499 | ]; |
||
500 | } |
||
501 | |||
502 | /** |
||
503 | * @return array |
||
504 | */ |
||
505 | public function replaceProvider(): array |
||
506 | { |
||
507 | $needle = new Item('1'); |
||
508 | $item2 = new Item('2'); |
||
509 | $item3 = new Item('3'); |
||
510 | |||
511 | return [ |
||
512 | 'empty-content' => [ |
||
513 | [], |
||
514 | $needle, |
||
515 | [$item2], |
||
516 | false, |
||
517 | [], |
||
518 | ], |
||
519 | 'only-non-matching-content' => [ |
||
520 | [$item2, $item3], |
||
521 | $needle, |
||
522 | [$needle, $item3], |
||
523 | false, |
||
524 | [$item2, $item3], |
||
525 | ], |
||
526 | 'only-matching-content' => [ |
||
527 | [$needle], |
||
528 | $needle, |
||
529 | [$item2, $item3], |
||
530 | true, |
||
531 | [$item2, $item3], |
||
532 | ], |
||
533 | 'non-first-matching-content' => [ |
||
534 | [$item2, $needle], |
||
535 | $needle, |
||
536 | [$item3, $item3], |
||
537 | true, |
||
538 | [$item2, $item3, $item3], |
||
539 | ], |
||
540 | 'non-last-matching-content' => [ |
||
541 | [$needle, $item2], |
||
542 | $needle, |
||
543 | [$item3, $item3], |
||
544 | true, |
||
545 | [$item3, $item3, $item2], |
||
546 | ], |
||
547 | ]; |
||
548 | } |
||
549 | |||
550 | /** |
||
551 | * @return array |
||
552 | */ |
||
553 | public function removeProvider(): array |
||
554 | { |
||
555 | $needle = new Item('1'); |
||
556 | $item2 = new Item('2'); |
||
557 | $item3 = new Item('3'); |
||
558 | |||
559 | return [ |
||
560 | 'empty-content' => [ |
||
561 | [], |
||
562 | $needle, |
||
563 | false, |
||
564 | [], |
||
565 | ], |
||
566 | 'only-non-matching-content' => [ |
||
567 | [$item2, $item3], |
||
568 | $needle, |
||
569 | false, |
||
570 | [$item2, $item3], |
||
571 | ], |
||
572 | 'only-matching-content' => [ |
||
573 | [$needle], |
||
574 | $needle, |
||
575 | true, |
||
576 | [], |
||
577 | ], |
||
578 | 'non-first-matching-content' => [ |
||
579 | [$item2, $needle], |
||
580 | $needle, |
||
581 | true, |
||
582 | [$item2], |
||
583 | ], |
||
584 | 'non-last-matching-content' => [ |
||
585 | [$needle, $item2], |
||
586 | $needle, |
||
587 | true, |
||
588 | [$item2], |
||
589 | ], |
||
590 | ]; |
||
591 | } |
||
592 | |||
593 | /** |
||
594 | * @return array |
||
595 | */ |
||
596 | public function isMatchProvider(): array |
||
597 | { |
||
598 | return [ |
||
599 | 'INode-no-intent' => [INode::class, [], true], |
||
600 | 'INode-foo-intent' => [INode::class, ['foo'], true], |
||
601 | 'INode-bar-intent' => [INode::class, ['bar'], true], |
||
602 | 'INode-foo-and-bar-intent' => [INode::class, ['foo', 'bar'], true], |
||
603 | 'IComponent-foo-intent' => [IComponent::class, ['foo'], true], |
||
604 | 'Component-foo-intent' => [Component::class, ['foo'], true], |
||
605 | 'fail-INode-baz-intent' => [INode::class, ['baz'], false], |
||
606 | 'fail-INode-foo-and-baz-intent' => [INode::class, ['foo', 'baz'], false], |
||
607 | 'fail-Node-foo-intent' => [Node::class, ['foo'], false], |
||
608 | 'Dropdown-foo-intent' => [Dropdown::class, ['foo'], true], |
||
609 | ]; |
||
610 | } |
||
611 | |||
612 | public function testArrayAccessUnset() |
||
613 | { |
||
614 | $node1 = new Item('1'); |
||
615 | |||
616 | $sut = $this->createNode(); |
||
617 | |||
618 | $sut[] = $node1; |
||
619 | |||
620 | $this->assertTrue($sut->offsetExists(0)); |
||
621 | |||
622 | unset($sut[0]); |
||
623 | |||
624 | $this->assertfalse($sut->offsetExists(0)); |
||
625 | } |
||
626 | |||
627 | /** |
||
628 | * @dataProvider toStringWithTranslationProvider |
||
629 | * |
||
630 | * @param $content |
||
631 | * @param array $translations |
||
632 | * @param string $expectedResult |
||
633 | */ |
||
634 | public function testToStringWithTranslation($content, array $translations, string $expectedResult) |
||
635 | { |
||
636 | $translator = MockTranslatorFactory::createSimpleTranslator($this, $translations); |
||
637 | |||
638 | $sut = $this->createNode($content); |
||
639 | $sut->setTranslator($translator); |
||
640 | |||
641 | $this->assertSame($expectedResult, (string)$sut); |
||
642 | } |
||
643 | |||
644 | /** |
||
645 | * @dataProvider isMatchProvider |
||
646 | * |
||
647 | * @param string|null $className |
||
648 | * @param string[] $intents |
||
649 | * @param int|null $expectedResult |
||
650 | */ |
||
651 | public function testIsMatch(?string $className, array $intents, bool $expectedResult) |
||
652 | { |
||
653 | $sut = $this->createNode(); |
||
654 | $sut->setIntent('foo', 'bar'); |
||
655 | |||
656 | $actualResult = $sut->isMatch($className, ...$intents); |
||
657 | |||
658 | $this->assertSame($expectedResult, $actualResult); |
||
659 | } |
||
660 | |||
661 | public function testGetPrefixGetsEmptyCollectionByDefault() |
||
662 | { |
||
663 | $sut = $this->createNode(); |
||
664 | |||
665 | $actualResult = $sut->getPrefix(); |
||
666 | |||
667 | $this->assertInstanceOf(ICollection::class, $actualResult); |
||
668 | $this->assertCount(0, $actualResult); |
||
669 | } |
||
670 | |||
671 | public function testGetPrefixGetsLastPrefixSet() |
||
672 | { |
||
673 | $sut = $this->createNode(); |
||
674 | |||
675 | /** @var ICollection $collectionStub */ |
||
676 | $collectionStub = $this->createMock(ICollection::class); |
||
677 | |||
678 | $sut->setPrefix($collectionStub); |
||
679 | |||
680 | $actualResult = $sut->getPrefix(); |
||
681 | |||
682 | $this->assertSame($collectionStub, $actualResult); |
||
683 | } |
||
684 | |||
685 | public function testGetPostfixGetsEmptyCollectionByDefault() |
||
686 | { |
||
687 | $sut = $this->createNode(); |
||
688 | |||
689 | $actualResult = $sut->getPostfix(); |
||
690 | |||
691 | $this->assertInstanceOf(ICollection::class, $actualResult); |
||
692 | $this->assertCount(0, $actualResult); |
||
693 | } |
||
694 | |||
695 | public function testGetPostfixGetsLastPrefixSet() |
||
696 | { |
||
697 | $sut = $this->createNode(); |
||
698 | |||
699 | /** @var ICollection $collectionStub */ |
||
700 | $collectionStub = $this->createMock(ICollection::class); |
||
701 | |||
702 | $sut->setPostfix($collectionStub); |
||
703 | |||
704 | $actualResult = $sut->getPostfix(); |
||
705 | |||
706 | $this->assertSame($collectionStub, $actualResult); |
||
707 | } |
||
708 | |||
709 | public function testGetWrapperCanReturnNull() |
||
710 | { |
||
711 | $sut = $this->createNode(); |
||
712 | |||
713 | $sut->setWrapper(null); |
||
714 | |||
715 | $actualResult = $sut->getWrapper(); |
||
1 ignored issue
–
show
|
|||
716 | |||
717 | $this->assertNull($actualResult); |
||
718 | } |
||
719 | |||
720 | public function testGetWrapperReturnsComponentByDefault() |
||
727 | } |
||
728 | |||
729 | public function testGetWrapperReturnsLastSetWrapper() |
||
730 | { |
||
731 | $sut = $this->createNode(); |
||
732 | |||
733 | /** @var IComponent $componentStub */ |
||
734 | $componentStub = $this->createMock(IComponent::class); |
||
735 | |||
736 | $sut->setWrapper($componentStub); |
||
737 | |||
738 | $actualResult = $sut->getWrapper(); |
||
739 | |||
740 | $this->assertSame($componentStub, $actualResult); |
||
741 | } |
||
742 | |||
743 | /** |
||
744 | * @param INode[]|INode|string|null $content |
||
745 | * |
||
746 | * @return Dropdown |
||
747 | */ |
||
748 | protected function createNode($content = null): INode |
||
751 | } |
||
752 | } |
||
753 |
This check looks for function or method calls that always return null and whose return value is assigned to a variable.
The method
getObject()
can return nothing but null, so it makes no sense to assign that value to a variable.The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.