Skip to content

Commit 316534a

Browse files
Closes #1033
1 parent c0fe94b commit 316534a

5 files changed

+59
-0
lines changed

ChangeLog-10.1.md

+7
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+
## [10.1.14] - 2024-MM-DD
6+
7+
### Fixed
8+
9+
* [#1033](https://github.com/sebastianbergmann/php-code-coverage/issues/1033): `@codeCoverageIgnore` annotation does not work on `enum`
10+
511
## [10.1.13] - 2024-03-09
612

713
### Changed
@@ -95,6 +101,7 @@ All notable changes are documented in this file using the [Keep a CHANGELOG](htt
95101

96102
* The `SebastianBergmann\CodeCoverage\Filter::includeDirectory()`, `SebastianBergmann\CodeCoverage\Filter::excludeDirectory()`, and `SebastianBergmann\CodeCoverage\Filter::excludeFile()` methods are now deprecated
97103

104+
[10.1.13]: https://github.com/sebastianbergmann/php-code-coverage/compare/10.1.13...10.1
98105
[10.1.13]: https://github.com/sebastianbergmann/php-code-coverage/compare/10.1.12...10.1.13
99106
[10.1.12]: https://github.com/sebastianbergmann/php-code-coverage/compare/10.1.11...10.1.12
100107
[10.1.11]: https://github.com/sebastianbergmann/php-code-coverage/compare/10.1.10...10.1.11

src/StaticAnalysis/IgnoredLinesFindingVisitor.php

+2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use PhpParser\Node\Attribute;
1616
use PhpParser\Node\Stmt\Class_;
1717
use PhpParser\Node\Stmt\ClassMethod;
18+
use PhpParser\Node\Stmt\Enum_;
1819
use PhpParser\Node\Stmt\Function_;
1920
use PhpParser\Node\Stmt\Interface_;
2021
use PhpParser\Node\Stmt\Trait_;
@@ -43,6 +44,7 @@ public function enterNode(Node $node): void
4344
if (!$node instanceof Class_ &&
4445
!$node instanceof Trait_ &&
4546
!$node instanceof Interface_ &&
47+
!$node instanceof Enum_ &&
4648
!$node instanceof ClassMethod &&
4749
!$node instanceof Function_ &&
4850
!$node instanceof Attribute) {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php declare(strict_types=1);
2+
/**
3+
* @codeCoverageIgnore
4+
*/
5+
enum TestEnumeration
6+
{
7+
case SomeCase;
8+
9+
public function isSomeCase(): bool
10+
{
11+
return $this === self::SomeCase;
12+
}
13+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php declare(strict_types=1);
2+
enum TestEnumeration
3+
{
4+
case SomeCase;
5+
6+
/**
7+
* @codeCoverageIgnore
8+
*/
9+
public function isSomeCase(): bool
10+
{
11+
return $this === self::SomeCase;
12+
}
13+
}

tests/tests/StaticAnalysis/ParsingFileAnalyserTest.php

+24
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@
99
*/
1010
namespace SebastianBergmann\CodeCoverage\StaticAnalysis;
1111

12+
use function range;
1213
use PHPUnit\Framework\Attributes\CoversClass;
14+
use PHPUnit\Framework\Attributes\Ticket;
1315
use PHPUnit\Framework\TestCase;
1416

1517
#[CoversClass(CodeUnitFindingVisitor::class)]
@@ -165,4 +167,26 @@ public function testLinesCanBeIgnoredUsingAttribute(): void
165167
),
166168
);
167169
}
170+
171+
#[Ticket('https://github.com/sebastianbergmann/php-code-coverage/issues/1033')]
172+
public function testEnumWithEnumLevelIgnore(): void
173+
{
174+
$this->assertSame(
175+
range(5, 13),
176+
(new ParsingFileAnalyser(true, true))->ignoredLinesFor(
177+
TEST_FILES_PATH . 'source_with_enum_and_enum_level_ignore_annotation.php',
178+
),
179+
);
180+
}
181+
182+
#[Ticket('https://github.com/sebastianbergmann/php-code-coverage/issues/1033')]
183+
public function testEnumWithMethodLevelIgnore(): void
184+
{
185+
$this->assertSame(
186+
range(9, 12),
187+
(new ParsingFileAnalyser(true, true))->ignoredLinesFor(
188+
TEST_FILES_PATH . 'source_with_enum_and_method_level_ignore_annotation.php',
189+
),
190+
);
191+
}
168192
}

0 commit comments

Comments
 (0)