mirror of
https://github.com/pestphp/pest.git
synced 2026-03-12 02:37:22 +01:00
Merge pull request #804 from titantwentyone/2.x
Allow traits to be covered
This commit is contained in:
@ -227,7 +227,7 @@ final class TestCall
|
|||||||
public function covers(string ...$classesOrFunctions): self
|
public function covers(string ...$classesOrFunctions): self
|
||||||
{
|
{
|
||||||
foreach ($classesOrFunctions as $classOrFunction) {
|
foreach ($classesOrFunctions as $classOrFunction) {
|
||||||
$isClass = class_exists($classOrFunction);
|
$isClass = class_exists($classOrFunction) || trait_exists($classOrFunction);
|
||||||
$isMethod = function_exists($classOrFunction);
|
$isMethod = function_exists($classOrFunction);
|
||||||
|
|
||||||
if (! $isClass && ! $isMethod) {
|
if (! $isClass && ! $isMethod) {
|
||||||
|
|||||||
@ -6,6 +6,7 @@ use PHPUnit\Framework\Attributes\CoversClass;
|
|||||||
use Tests\Fixtures\Covers\CoversClass1;
|
use Tests\Fixtures\Covers\CoversClass1;
|
||||||
use Tests\Fixtures\Covers\CoversClass2;
|
use Tests\Fixtures\Covers\CoversClass2;
|
||||||
use Tests\Fixtures\Covers\CoversClass3;
|
use Tests\Fixtures\Covers\CoversClass3;
|
||||||
|
use Tests\Fixtures\Covers\CoversTrait;
|
||||||
|
|
||||||
$runCounter = 0;
|
$runCounter = 0;
|
||||||
|
|
||||||
@ -43,6 +44,13 @@ it('guesses if the given argument is a class or function', function () {
|
|||||||
expect($attributes[3]->getArguments()[0])->toBe(CoversClass3::class);
|
expect($attributes[3]->getArguments()[0])->toBe(CoversClass3::class);
|
||||||
})->covers(CoversClass3::class, 'testCoversFunction');
|
})->covers(CoversClass3::class, 'testCoversFunction');
|
||||||
|
|
||||||
|
it('uses the correct PHPUnit attribute for trait', function () {
|
||||||
|
$attributes = (new ReflectionClass($this))->getAttributes();
|
||||||
|
|
||||||
|
expect($attributes[4]->getName())->toBe('PHPUnit\Framework\Attributes\CoversClass');
|
||||||
|
expect($attributes[4]->getArguments()[0])->toBe('Tests\Fixtures\Covers\CoversTrait');
|
||||||
|
})->coversClass(CoversTrait::class);
|
||||||
|
|
||||||
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());
|
||||||
|
|
||||||
|
|||||||
8
tests/Fixtures/Covers/CoversTrait.php
Normal file
8
tests/Fixtures/Covers/CoversTrait.php
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Tests\Fixtures\Covers;
|
||||||
|
|
||||||
|
trait CoversTrait
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user