Skip to content

Commit afd8bd5

Browse files
Closes #681
1 parent bf5b28e commit afd8bd5

5 files changed

+57
-0
lines changed

ChangeLog.md

+6
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22

33
All notable changes are documented in this file using the [Keep a CHANGELOG](http://keepachangelog.com/) principles.
44

5+
## [7.0.5] - 2019-MM-DD
6+
7+
### Fixed
8+
9+
* Fixed [#681](https://github.com/sebastianbergmann/php-code-coverage/pull/681): `use function` statements are not ignored
10+
511
## [7.0.4] - 2019-05-29
612

713
### Fixed

src/CodeCoverage.php

+1
Original file line numberDiff line numberDiff line change
@@ -761,6 +761,7 @@ private function getLinesToBeIgnoredInner(string $fileName): array
761761
case \PHP_Token_OPEN_TAG::class:
762762
case \PHP_Token_CLOSE_TAG::class:
763763
case \PHP_Token_USE::class:
764+
case \PHP_Token_USE_FUNCTION::class:
764765
$this->ignoredLines[$fileName][] = $token->getLine();
765766

766767
break;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
namespace SebastianBergmann\CodeCoverage\TestFixture;
3+
4+
use stdClass;
5+
use function array_filter;
6+
use const ARRAY_FILTER_USE_BOTH;
7+
8+
class C
9+
{
10+
public function m(): void
11+
{
12+
$o = new stdClass;
13+
14+
array_filter(
15+
['a' => 1, 'b' => 2, 'c' => 3, 'd' => 4],
16+
static function ($v, $k)
17+
{
18+
return $k === 'b' || $v === 4;
19+
},
20+
ARRAY_FILTER_USE_BOTH
21+
);
22+
}
23+
}

tests/tests/CodeCoverageTest.php

+26
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,32 @@ public function testGetLinesToBeIgnoredWhenIgnoreIsDisabled(): void
259259
);
260260
}
261261

262+
public function testUseStatementsAreIgnored(): void
263+
{
264+
$this->assertEquals(
265+
[
266+
1,
267+
2,
268+
3,
269+
4,
270+
5,
271+
6,
272+
7,
273+
8,
274+
9,
275+
10,
276+
13,
277+
16,
278+
23,
279+
24,
280+
],
281+
$this->getLinesToBeIgnored()->invoke(
282+
$this->coverage,
283+
TEST_FILES_PATH . 'source_with_use_statements.php'
284+
)
285+
);
286+
}
287+
262288
public function testAppendThrowsExceptionIfCoveredCodeWasNotExecuted(): void
263289
{
264290
$this->coverage->filter()->addDirectoryToWhitelist(TEST_FILES_PATH);

tests/tests/FilterTest.php

+1
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ protected function setUp(): void
6969
TEST_FILES_PATH . 'source_with_ignore.php',
7070
TEST_FILES_PATH . 'source_with_namespace.php',
7171
TEST_FILES_PATH . 'source_with_oneline_annotations.php',
72+
TEST_FILES_PATH . 'source_with_use_statements.php',
7273
TEST_FILES_PATH . 'source_without_ignore.php',
7374
TEST_FILES_PATH . 'source_without_namespace.php',
7475
];

0 commit comments

Comments
 (0)