Skip to content

Commit

Permalink
fix: php_unit_test_class_requires_covers Attribute detection when c…
Browse files Browse the repository at this point in the history
…lass is final (#8016)
  • Loading branch information
atomiix committed May 16, 2024
1 parent ab56bb5 commit 61caa3a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/Fixer/PhpUnit/PhpUnitTestClassRequiresCoversFixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@ protected function applyPhpUnitClassFix(Tokens $tokens, int $startIndex, int $en
return; // don't add `@covers` annotation for abstract base classes
}

if (isset($modifiers['final'])) {
$classIndex = $tokens->getPrevMeaningfulToken($classIndex);
}

$this->ensureIsDocBlockWithAnnotation(
$tokens,
$classIndex,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,14 @@ class FooTest extends \PHPUnit_Framework_TestCase {}
class FooTest extends \PHPUnit_Framework_TestCase {}
PHP,
];

yield 'with attribute on final class' => [
<<<'PHP'
<?php
#[PHPUnit\Framework\Attributes\CoversNothing]
final class FooTest extends \PHPUnit_Framework_TestCase {}
PHP,
];
}

/**
Expand Down

0 comments on commit 61caa3a

Please sign in to comment.