Skip to content

Commit

Permalink
Closes #1033
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastianbergmann committed Mar 12, 2024
1 parent c0fe94b commit 316534a
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 0 deletions.
7 changes: 7 additions & 0 deletions ChangeLog-10.1.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

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

## [10.1.14] - 2024-MM-DD

### Fixed

* [#1033](https://github.com/sebastianbergmann/php-code-coverage/issues/1033): `@codeCoverageIgnore` annotation does not work on `enum`

## [10.1.13] - 2024-03-09

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

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

[10.1.13]: https://github.com/sebastianbergmann/php-code-coverage/compare/10.1.13...10.1
[10.1.13]: https://github.com/sebastianbergmann/php-code-coverage/compare/10.1.12...10.1.13
[10.1.12]: https://github.com/sebastianbergmann/php-code-coverage/compare/10.1.11...10.1.12
[10.1.11]: https://github.com/sebastianbergmann/php-code-coverage/compare/10.1.10...10.1.11
Expand Down
2 changes: 2 additions & 0 deletions src/StaticAnalysis/IgnoredLinesFindingVisitor.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use PhpParser\Node\Attribute;
use PhpParser\Node\Stmt\Class_;
use PhpParser\Node\Stmt\ClassMethod;
use PhpParser\Node\Stmt\Enum_;
use PhpParser\Node\Stmt\Function_;
use PhpParser\Node\Stmt\Interface_;
use PhpParser\Node\Stmt\Trait_;
Expand Down Expand Up @@ -43,6 +44,7 @@ public function enterNode(Node $node): void
if (!$node instanceof Class_ &&
!$node instanceof Trait_ &&
!$node instanceof Interface_ &&
!$node instanceof Enum_ &&
!$node instanceof ClassMethod &&
!$node instanceof Function_ &&
!$node instanceof Attribute) {
Expand Down
13 changes: 13 additions & 0 deletions tests/_files/source_with_enum_and_enum_level_ignore_annotation.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php declare(strict_types=1);
/**
* @codeCoverageIgnore
*/
enum TestEnumeration
{
case SomeCase;

public function isSomeCase(): bool
{
return $this === self::SomeCase;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php declare(strict_types=1);
enum TestEnumeration
{
case SomeCase;

/**
* @codeCoverageIgnore
*/
public function isSomeCase(): bool
{
return $this === self::SomeCase;
}
}
24 changes: 24 additions & 0 deletions tests/tests/StaticAnalysis/ParsingFileAnalyserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
*/
namespace SebastianBergmann\CodeCoverage\StaticAnalysis;

use function range;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\Ticket;
use PHPUnit\Framework\TestCase;

#[CoversClass(CodeUnitFindingVisitor::class)]
Expand Down Expand Up @@ -165,4 +167,26 @@ public function testLinesCanBeIgnoredUsingAttribute(): void
),
);
}

#[Ticket('https://github.com/sebastianbergmann/php-code-coverage/issues/1033')]
public function testEnumWithEnumLevelIgnore(): void
{
$this->assertSame(
range(5, 13),
(new ParsingFileAnalyser(true, true))->ignoredLinesFor(
TEST_FILES_PATH . 'source_with_enum_and_enum_level_ignore_annotation.php',
),
);
}

#[Ticket('https://github.com/sebastianbergmann/php-code-coverage/issues/1033')]
public function testEnumWithMethodLevelIgnore(): void
{
$this->assertSame(
range(9, 12),
(new ParsingFileAnalyser(true, true))->ignoredLinesFor(
TEST_FILES_PATH . 'source_with_enum_and_method_level_ignore_annotation.php',
),
);
}
}

0 comments on commit 316534a

Please sign in to comment.