mirror of
https://github.com/pestphp/pest.git
synced 2026-03-06 07:47:22 +01:00
Fixes covers tests
This commit is contained in:
@ -41,6 +41,7 @@
|
|||||||
},
|
},
|
||||||
"autoload-dev": {
|
"autoload-dev": {
|
||||||
"psr-4": {
|
"psr-4": {
|
||||||
|
"Tests\\Fixtures\\Covers\\": "tests/Fixtures/Covers",
|
||||||
"Tests\\": "tests/PHPUnit/"
|
"Tests\\": "tests/PHPUnit/"
|
||||||
},
|
},
|
||||||
"files": [
|
"files": [
|
||||||
|
|||||||
@ -3,20 +3,14 @@
|
|||||||
use Pest\Factories\Attributes\Covers;
|
use Pest\Factories\Attributes\Covers;
|
||||||
use Pest\PendingCalls\TestCall;
|
use Pest\PendingCalls\TestCall;
|
||||||
use Pest\TestSuite;
|
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;
|
$runCounter = 0;
|
||||||
|
|
||||||
class TestCoversClass1
|
|
||||||
{
|
|
||||||
}
|
|
||||||
class TestCoversClass2
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
class TestCoversClass3
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
function testCoversFunction()
|
function testCoversFunction()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
@ -25,39 +19,31 @@ it('uses the correct PHPUnit attribute for class', function () {
|
|||||||
$attributes = (new ReflectionClass($this))->getAttributes();
|
$attributes = (new ReflectionClass($this))->getAttributes();
|
||||||
|
|
||||||
expect($attributes[0]->getName())->toBe('PHPUnit\Framework\Attributes\CoversClass');
|
expect($attributes[0]->getName())->toBe('PHPUnit\Framework\Attributes\CoversClass');
|
||||||
expect($attributes[0]->getArguments()[0])->toBe('P\Tests\Features\TestCoversClass1');
|
expect($attributes[0]->getArguments()[0])->toBe('Tests\Fixtures\Covers\CoversClass1');
|
||||||
})->coversClass(TestCoversClass1::class);
|
})->coversClass(CoversClass1::class);
|
||||||
|
|
||||||
it('uses the correct PHPUnit attribute for function', function () {
|
it('uses the correct PHPUnit attribute for function', function () {
|
||||||
$attributes = (new ReflectionClass($this))->getAttributes();
|
$attributes = (new ReflectionClass($this))->getAttributes();
|
||||||
|
|
||||||
expect($attributes[1]->getName())->toBe('PHPUnit\Framework\Attributes\CoversFunction');
|
expect($attributes[1]->getName())->toBe('PHPUnit\Framework\Attributes\CoversFunction');
|
||||||
expect($attributes[1]->getArguments()[0])->toBe('foo');
|
expect($attributes[1]->getArguments()[0])->toBe('testCoversFunction');
|
||||||
})->coversFunction('foo');
|
})->coversFunction('testCoversFunction');
|
||||||
|
|
||||||
it('removes duplicated attributes', function () {
|
it('removes duplicated attributes', function () {
|
||||||
$attributes = (new ReflectionClass($this))->getAttributes();
|
$attributes = (new ReflectionClass($this))->getAttributes();
|
||||||
|
|
||||||
expect($attributes[2]->getName())->toBe('PHPUnit\Framework\Attributes\CoversClass');
|
expect($attributes[2]->getName())->toBe(CoversClass::class);
|
||||||
expect($attributes[2]->getArguments()[0])->toBe('P\Tests\Features\TestCoversClass2');
|
expect($attributes[2]->getArguments()[0])->toBe(CoversClass2::class);
|
||||||
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');
|
|
||||||
})
|
})
|
||||||
->coversClass(TestCoversClass2::class, TestCoversClass1::class, Covers::class)
|
->coversClass(CoversClass2::class, CoversClass1::class)
|
||||||
->coversFunction('bar', 'foo', 'baz');
|
->coversFunction('testCoversFunction');
|
||||||
|
|
||||||
it('guesses if the given argument is a class or function', function () {
|
it('guesses if the given argument is a class or function', function () {
|
||||||
$attributes = (new ReflectionClass($this))->getAttributes();
|
$attributes = (new ReflectionClass($this))->getAttributes();
|
||||||
|
|
||||||
expect($attributes[6]->getName())->toBe('PHPUnit\Framework\Attributes\CoversClass');
|
expect($attributes[3]->getName())->toBe(CoversClass::class);
|
||||||
expect($attributes[6]->getArguments()[0])->toBe('P\Tests\Features\TestCoversClass3');
|
expect($attributes[3]->getArguments()[0])->toBe(CoversClass3::class);
|
||||||
expect($attributes[7]->getName())->toBe('PHPUnit\Framework\Attributes\CoversFunction');
|
})->covers(CoversClass3::class, 'testCoversFunction');
|
||||||
expect($attributes[7]->getArguments()[0])->toBe('testCoversFunction');
|
|
||||||
})->covers(TestCoversClass3::class, 'testCoversFunction');
|
|
||||||
|
|
||||||
it('appends CoversNothing to method attributes', function () {
|
it('appends CoversNothing to method attributes', function () {
|
||||||
$phpDoc = (new ReflectionClass($this))->getMethod($this->name());
|
$phpDoc = (new ReflectionClass($this))->getMethod($this->name());
|
||||||
|
|||||||
9
tests/Fixtures/Covers/CoversClass1.php
Normal file
9
tests/Fixtures/Covers/CoversClass1.php
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Tests\Fixtures\Covers;
|
||||||
|
|
||||||
|
class CoversClass1 {
|
||||||
|
public function foo() {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
5
tests/Fixtures/Covers/CoversClass2.php
Normal file
5
tests/Fixtures/Covers/CoversClass2.php
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Tests\Fixtures\Covers;
|
||||||
|
|
||||||
|
class CoversClass2 {}
|
||||||
5
tests/Fixtures/Covers/CoversClass3.php
Normal file
5
tests/Fixtures/Covers/CoversClass3.php
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Tests\Fixtures\Covers;
|
||||||
|
|
||||||
|
class CoversClass3 {}
|
||||||
Reference in New Issue
Block a user