Skip to content

Commit 77ae011

Browse files
Closes #1150
1 parent a25bde1 commit 77ae011

File tree

4 files changed

+45
-0
lines changed

4 files changed

+45
-0
lines changed

ChangeLog-12.5.md

Lines changed: 7 additions & 0 deletions
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+
## [12.5.6] - 2026-MM-DD
6+
7+
### Fixed
8+
9+
* [#1150](https://github.com/sebastianbergmann/php-code-coverage/issues/1150): Abstract method declarations are incorrectly counted as executable lines
10+
511
## [12.5.5] - 2026-04-13
612

713
### Fixed
@@ -47,6 +53,7 @@ All notable changes are documented in this file using the [Keep a CHANGELOG](htt
4753
* [#1126](https://github.com/sebastianbergmann/php-code-coverage/issues/1126): Add test execution time to `<test>` elements under `projects/tests` in the XML reports index file
4854
* [#1127](https://github.com/sebastianbergmann/php-code-coverage/issues/1127): Add SHA-1 hash of content of SUT source file to XML report
4955

56+
[12.5.6]: https://github.com/sebastianbergmann/php-code-coverage/compare/12.5.5...12.5
5057
[12.5.5]: https://github.com/sebastianbergmann/php-code-coverage/compare/12.5.4...12.5.5
5158
[12.5.4]: https://github.com/sebastianbergmann/php-code-coverage/compare/12.5.3...12.5.4
5259
[12.5.3]: https://github.com/sebastianbergmann/php-code-coverage/compare/12.5.2...12.5.3

src/StaticAnalysis/Visitor/ExecutableLinesFindingVisitor.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,10 @@ public function enterNode(Node $node): null
142142
$node instanceof Node\Stmt\ClassMethod ||
143143
$node instanceof Node\Expr\Closure ||
144144
$node instanceof Node\Stmt\Trait_) {
145+
if ($node instanceof Node\Stmt\ClassMethod && $node->isAbstract()) {
146+
return null;
147+
}
148+
145149
if ($node instanceof Node\Stmt\Function_ || $node instanceof Node\Stmt\ClassMethod) {
146150
$unsets = [];
147151

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?php declare(strict_types=1);
2+
namespace SebastianBergmann\CodeCoverage\TestFixture;
3+
4+
abstract class AbstractClassWithAbstractMethod
5+
{
6+
abstract public function abstractMethod(): string;
7+
8+
abstract protected function anotherAbstractMethod(int $value): int;
9+
10+
public function concreteMethod(): string
11+
{
12+
return 'concrete';
13+
}
14+
}

tests/tests/StaticAnalysis/Visitor/ExecutableLinesFindingVisitorTest.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,26 @@ public function testExecutableLinesAreGroupedByBranchPhp82(): void
4040
$this->doTestSelfDescribingAssert(TEST_FILES_PATH . 'source_for_branched_exec_lines_php82.php');
4141
}
4242

43+
#[Ticket('https://github.com/sebastianbergmann/phpunit/issues/6442')]
44+
public function testAbstractMethodDeclarationsAreNotExecutable(): void
45+
{
46+
$source = file_get_contents(__DIR__ . '/../../../_files/source_with_abstract_method.php');
47+
$parser = (new ParserFactory)->createForHostVersion();
48+
$nodes = $parser->parse($source);
49+
$executableLinesFindingVisitor = new ExecutableLinesFindingVisitor($source);
50+
51+
$traverser = new NodeTraverser;
52+
$traverser->addVisitor($executableLinesFindingVisitor);
53+
$traverser->traverse($nodes);
54+
55+
$executableLines = $executableLinesFindingVisitor->executableLinesGroupedByBranch();
56+
57+
$this->assertArrayNotHasKey(6, $executableLines);
58+
$this->assertArrayNotHasKey(8, $executableLines);
59+
60+
$this->assertArrayHasKey(12, $executableLines);
61+
}
62+
4363
#[Ticket('https://github.com/sebastianbergmann/php-code-coverage/issues/967')]
4464
public function testMatchArmsAreProcessedCorrectly(): void
4565
{

0 commit comments

Comments
 (0)