Skip to content

Commit 4a6c34a

Browse files
Merge branch '12.5'
* 12.5: Closes #1150
2 parents c875dc3 + 77ae011 commit 4a6c34a

File tree

4 files changed

+34
-0
lines changed

4 files changed

+34
-0
lines changed

ChangeLog-14.1.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+
## [14.1.2] - 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
## [14.1.1] - 2026-04-13
612

713
### Fixed
@@ -22,5 +28,6 @@ All notable changes are documented in this file using the [Keep a CHANGELOG](htt
2228

2329
* [#1147](https://github.com/sebastianbergmann/php-code-coverage/pull/1147): `CoversClass` does not transitively target traits used by enumerations
2430

31+
[14.1.2]: https://github.com/sebastianbergmann/php-code-coverage/compare/14.1.1...main
2532
[14.1.1]: https://github.com/sebastianbergmann/php-code-coverage/compare/14.1.0...14.1.1
2633
[14.1.0]: https://github.com/sebastianbergmann/php-code-coverage/compare/14.0.0...14.1.0

src/StaticAnalysis/Visitor/ExecutableLinesFindingVisitor.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,10 @@ public function enterNode(Node $node): null
144144
$node instanceof Node\Stmt\ClassMethod ||
145145
$node instanceof Node\Expr\Closure ||
146146
$node instanceof Node\Stmt\Trait_) {
147+
if ($node instanceof Node\Stmt\ClassMethod && $node->isAbstract()) {
148+
return null;
149+
}
150+
147151
if ($node instanceof Node\Stmt\Function_ || $node instanceof Node\Stmt\ClassMethod) {
148152
$unsets = [];
149153

tests/_files/source_with_abstract_method.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@ abstract class ClassWithAbstractMethod
55
{
66
abstract public function abstractMethod(): void;
77

8+
abstract protected function anotherAbstractMethod(): void;
9+
810
public function concreteMethod(): void
911
{
12+
echo 'x';
1013
}
1114
}

tests/tests/StaticAnalysis/Visitor/ExecutableLinesFindingVisitorTest.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,26 @@ public function testEmptyForLoopIsProcessedCorrectly(): void
7777
$this->assertNotEmpty($result);
7878
}
7979

80+
#[Ticket('https://github.com/sebastianbergmann/phpunit/issues/6442')]
81+
public function testAbstractMethodDeclarationsAreNotExecutable(): void
82+
{
83+
$source = file_get_contents(__DIR__ . '/../../../_files/source_with_abstract_method.php');
84+
$parser = (new ParserFactory)->createForHostVersion();
85+
$nodes = $parser->parse($source);
86+
$executableLinesFindingVisitor = new ExecutableLinesFindingVisitor($source);
87+
88+
$traverser = new NodeTraverser;
89+
$traverser->addVisitor($executableLinesFindingVisitor);
90+
$traverser->traverse($nodes);
91+
92+
$executableLines = $executableLinesFindingVisitor->executableLinesGroupedByBranch();
93+
94+
$this->assertArrayNotHasKey(6, $executableLines);
95+
$this->assertArrayNotHasKey(8, $executableLines);
96+
97+
$this->assertArrayHasKey(12, $executableLines);
98+
}
99+
80100
#[Ticket('https://github.com/sebastianbergmann/php-code-coverage/issues/967')]
81101
public function testMatchArmsAreProcessedCorrectly(): void
82102
{

0 commit comments

Comments
 (0)