Skip to content

Commit e979531

Browse files
committed
Fix coverage for uncovered files with arrays
1 parent 8b23f3a commit e979531

File tree

3 files changed

+24
-26
lines changed

3 files changed

+24
-26
lines changed

src/StaticAnalysis/ExecutableLinesFindingVisitor.php

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,7 @@
1010
namespace SebastianBergmann\CodeCoverage\StaticAnalysis;
1111

1212
use PhpParser\Node;
13-
use PhpParser\Node\Expr\Array_;
1413
use PhpParser\Node\Expr\ArrayDimFetch;
15-
use PhpParser\Node\Expr\ArrayItem;
1614
use PhpParser\Node\Expr\Assign;
1715
use PhpParser\Node\Expr\BinaryOp;
1816
use PhpParser\Node\Expr\CallLike;
@@ -150,22 +148,6 @@ private function getLines(Node $node): array
150148
return [$node->dim->getStartLine()];
151149
}
152150

153-
if ($node instanceof Array_) {
154-
$startLine = $node->getStartLine();
155-
156-
if (isset($this->executableLines[$startLine])) {
157-
return [];
158-
}
159-
160-
if ([] === $node->items) {
161-
return [$node->getEndLine()];
162-
}
163-
164-
if ($node->items[0] instanceof ArrayItem) {
165-
return [$node->items[0]->getStartLine()];
166-
}
167-
}
168-
169151
if ($node instanceof ClassMethod) {
170152
if ($node->name->name !== '__construct') {
171153
return [];
@@ -235,7 +217,6 @@ private function isExecutable(Node $node): bool
235217
{
236218
return $node instanceof Assign ||
237219
$node instanceof ArrayDimFetch ||
238-
$node instanceof Array_ ||
239220
$node instanceof BinaryOp ||
240221
$node instanceof Break_ ||
241222
$node instanceof CallLike ||

tests/_files/source_with_return_and_array_with_scalars.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,4 +62,24 @@ public function eigth(): void
6262
return
6363
;
6464
}
65+
66+
/**
67+
* Array expression must not add executable line to make uncovered
68+
* output consistent with output from real coverage driver like Xdebug.
69+
*
70+
* @see https://github.com/sebastianbergmann/php-code-coverage/pull/938
71+
*/
72+
public function nineNestedArray(): array
73+
{
74+
return [
75+
[],
76+
[[]],
77+
[[
78+
'test',
79+
'test' => [
80+
[[[false]]]
81+
]
82+
]],
83+
];
84+
}
6585
}

tests/tests/Data/RawCodeCoverageDataTest.php

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,6 @@ public function testUseStatementsAreUncovered(): void
272272
[
273273
12,
274274
14,
275-
15,
276275
16,
277276
18,
278277
],
@@ -300,7 +299,6 @@ public function testInterfacesAreUncovered(): void
300299
[
301300
7,
302301
9,
303-
10,
304302
11,
305303
13,
306304
],
@@ -342,7 +340,6 @@ public function testHeavyIndentationIsHandledCorrectly(): void
342340
25,
343341
28,
344342
31,
345-
36,
346343
40,
347344
46,
348345
48,
@@ -364,7 +361,6 @@ public function testHeavyIndentationIsHandledCorrectly(): void
364361
117,
365362
120,
366363
123,
367-
125, // This shouldn't be marked as LoC, but it's high unlikely to happen IRL to have $var = []; on multiple lines
368364
132,
369365
135,
370366
139,
@@ -415,14 +411,15 @@ public function testReturnStatementWithOnlyAnArrayWithScalarReturnsTheFirstEleme
415411

416412
$this->assertEquals(
417413
[
418-
8,
414+
7,
419415
15,
420-
24,
416+
22,
421417
30,
422-
40,
418+
39,
423419
47,
424420
54,
425421
63,
422+
74,
426423
],
427424
array_keys(RawCodeCoverageData::fromUncoveredFile($file, new ParsingFileAnalyser(true, true))->lineCoverage()[$file])
428425
);

0 commit comments

Comments
 (0)