From 04d2fa5ce8ba57f6a0dada48652fd691e763aa8b Mon Sep 17 00:00:00 2001 From: Nuno Maduro Date: Fri, 5 Jan 2024 14:37:33 +0000 Subject: [PATCH] feat: moves covers nothing to attribute --- src/Factories/Annotations/CoversNothing.php | 27 --------------------- src/Factories/Attributes/Covers.php | 2 ++ src/Factories/TestCaseFactory.php | 1 - tests/Features/Covers.php | 21 +++------------- 4 files changed, 6 insertions(+), 45 deletions(-) delete mode 100644 src/Factories/Annotations/CoversNothing.php diff --git a/src/Factories/Annotations/CoversNothing.php b/src/Factories/Annotations/CoversNothing.php deleted file mode 100644 index 76f03368..00000000 --- a/src/Factories/Annotations/CoversNothing.php +++ /dev/null @@ -1,27 +0,0 @@ -covers[0] ?? null) instanceof CoversNothingFactory) { - $annotations[] = '@coversNothing'; - } - - return $annotations; - } -} diff --git a/src/Factories/Attributes/Covers.php b/src/Factories/Attributes/Covers.php index a798e4b5..ad22ff8a 100644 --- a/src/Factories/Attributes/Covers.php +++ b/src/Factories/Attributes/Covers.php @@ -36,6 +36,8 @@ final class Covers extends Attribute $attributes[] = "#[\PHPUnit\Framework\Attributes\CoversClass({$covering->class}::class)]"; } elseif ($covering instanceof CoversFunction) { $attributes[] = "#[\PHPUnit\Framework\Attributes\CoversFunction('{$covering->function}')]"; + } else { + $attributes[] = "#[\PHPUnit\Framework\Attributes\CoversNothing()]"; } } diff --git a/src/Factories/TestCaseFactory.php b/src/Factories/TestCaseFactory.php index c7fd35f5..a2f3feb3 100644 --- a/src/Factories/TestCaseFactory.php +++ b/src/Factories/TestCaseFactory.php @@ -34,7 +34,6 @@ final class TestCaseFactory private const ANNOTATIONS = [ Annotations\Depends::class, Annotations\Groups::class, - Annotations\CoversNothing::class, Annotations\TestDox::class, ]; diff --git a/tests/Features/Covers.php b/tests/Features/Covers.php index 31074e09..dd4701c4 100644 --- a/tests/Features/Covers.php +++ b/tests/Features/Covers.php @@ -51,28 +51,15 @@ it('uses the correct PHPUnit attribute for trait', function () { expect($attributes[4]->getArguments()[0])->toBe('Tests\Fixtures\Covers\CoversTrait'); })->coversClass(CoversTrait::class); -it('appends CoversNothing to method attributes', function () { - $phpDoc = (new ReflectionClass($this))->getMethod($this->name()); +it('uses the correct PHPUnit attribute for covers nothing', function () { + $attributes = (new ReflectionClass($this))->getAttributes(); - expect(str_contains($phpDoc->getDocComment(), '* @coversNothing'))->toBeTrue(); + expect($attributes[5]->getName())->toBe('PHPUnit\Framework\Attributes\CoversNothing'); + expect($attributes[5]->getArguments())->toHaveCount(0); })->coversNothing(); -it('does not append CoversNothing to other methods', function () { - $phpDoc = (new ReflectionClass($this))->getMethod($this->name()); - - expect(str_contains($phpDoc->getDocComment(), '* @coversNothing'))->toBeFalse(); -}); - it('throws exception if no class nor method has been found', function () { $testCall = new TestCall(TestSuite::getInstance(), 'filename', 'description', fn () => 'closure'); $testCall->covers('fakeName'); })->throws(InvalidArgumentException::class, 'No class or method named "fakeName" has been found.'); - -describe('a "describe" group of tests', function () { - it('does not append CoversNothing to method attributes', function () { - $phpDoc = (new ReflectionClass($this))->getMethod($this->name()); - - expect(str_contains($phpDoc->getDocComment(), '* @coversNothing'))->toBeTrue(); - }); -})->coversNothing();