From 7a41a540f2d94a85b13bd3aff387e4e007215863 Mon Sep 17 00:00:00 2001 From: Nuno Maduro Date: Fri, 16 Sep 2022 12:34:20 +0100 Subject: [PATCH] Fixes covers tests --- composer.json | 1 + tests/Features/Covers.php | 46 +++++++++----------------- tests/Fixtures/Covers/CoversClass1.php | 9 +++++ tests/Fixtures/Covers/CoversClass2.php | 5 +++ tests/Fixtures/Covers/CoversClass3.php | 5 +++ 5 files changed, 36 insertions(+), 30 deletions(-) create mode 100644 tests/Fixtures/Covers/CoversClass1.php create mode 100644 tests/Fixtures/Covers/CoversClass2.php create mode 100644 tests/Fixtures/Covers/CoversClass3.php diff --git a/composer.json b/composer.json index 35879005..433f4f0a 100644 --- a/composer.json +++ b/composer.json @@ -41,6 +41,7 @@ }, "autoload-dev": { "psr-4": { + "Tests\\Fixtures\\Covers\\": "tests/Fixtures/Covers", "Tests\\": "tests/PHPUnit/" }, "files": [ diff --git a/tests/Features/Covers.php b/tests/Features/Covers.php index fa8b50b8..834dfcd6 100644 --- a/tests/Features/Covers.php +++ b/tests/Features/Covers.php @@ -3,20 +3,14 @@ use Pest\Factories\Attributes\Covers; use Pest\PendingCalls\TestCall; use Pest\TestSuite; +use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\CoversFunction; +use Tests\Fixtures\Covers\CoversClass1; +use Tests\Fixtures\Covers\CoversClass2; +use Tests\Fixtures\Covers\CoversClass3; $runCounter = 0; -class TestCoversClass1 -{ -} -class TestCoversClass2 -{ -} - -class TestCoversClass3 -{ -} - function testCoversFunction() { } @@ -25,39 +19,31 @@ it('uses the correct PHPUnit attribute for class', function () { $attributes = (new ReflectionClass($this))->getAttributes(); expect($attributes[0]->getName())->toBe('PHPUnit\Framework\Attributes\CoversClass'); - expect($attributes[0]->getArguments()[0])->toBe('P\Tests\Features\TestCoversClass1'); -})->coversClass(TestCoversClass1::class); + expect($attributes[0]->getArguments()[0])->toBe('Tests\Fixtures\Covers\CoversClass1'); +})->coversClass(CoversClass1::class); it('uses the correct PHPUnit attribute for function', function () { $attributes = (new ReflectionClass($this))->getAttributes(); expect($attributes[1]->getName())->toBe('PHPUnit\Framework\Attributes\CoversFunction'); - expect($attributes[1]->getArguments()[0])->toBe('foo'); -})->coversFunction('foo'); + expect($attributes[1]->getArguments()[0])->toBe('testCoversFunction'); +})->coversFunction('testCoversFunction'); it('removes duplicated attributes', function () { $attributes = (new ReflectionClass($this))->getAttributes(); - expect($attributes[2]->getName())->toBe('PHPUnit\Framework\Attributes\CoversClass'); - expect($attributes[2]->getArguments()[0])->toBe('P\Tests\Features\TestCoversClass2'); - expect($attributes[3]->getName())->toBe('PHPUnit\Framework\Attributes\CoversClass'); - expect($attributes[3]->getArguments()[0])->toBe('Pest\Factories\Attributes\Covers'); - expect($attributes[4]->getName())->toBe('PHPUnit\Framework\Attributes\CoversFunction'); - expect($attributes[4]->getArguments()[0])->toBe('bar'); - expect($attributes[5]->getName())->toBe('PHPUnit\Framework\Attributes\CoversFunction'); - expect($attributes[5]->getArguments()[0])->toBe('baz'); + expect($attributes[2]->getName())->toBe(CoversClass::class); + expect($attributes[2]->getArguments()[0])->toBe(CoversClass2::class); }) - ->coversClass(TestCoversClass2::class, TestCoversClass1::class, Covers::class) - ->coversFunction('bar', 'foo', 'baz'); + ->coversClass(CoversClass2::class, CoversClass1::class) + ->coversFunction('testCoversFunction'); it('guesses if the given argument is a class or function', function () { $attributes = (new ReflectionClass($this))->getAttributes(); - expect($attributes[6]->getName())->toBe('PHPUnit\Framework\Attributes\CoversClass'); - expect($attributes[6]->getArguments()[0])->toBe('P\Tests\Features\TestCoversClass3'); - expect($attributes[7]->getName())->toBe('PHPUnit\Framework\Attributes\CoversFunction'); - expect($attributes[7]->getArguments()[0])->toBe('testCoversFunction'); -})->covers(TestCoversClass3::class, 'testCoversFunction'); + expect($attributes[3]->getName())->toBe(CoversClass::class); + expect($attributes[3]->getArguments()[0])->toBe(CoversClass3::class); +})->covers(CoversClass3::class, 'testCoversFunction'); it('appends CoversNothing to method attributes', function () { $phpDoc = (new ReflectionClass($this))->getMethod($this->name()); diff --git a/tests/Fixtures/Covers/CoversClass1.php b/tests/Fixtures/Covers/CoversClass1.php new file mode 100644 index 00000000..378c237f --- /dev/null +++ b/tests/Fixtures/Covers/CoversClass1.php @@ -0,0 +1,9 @@ +