mirror of
https://github.com/pestphp/pest.git
synced 2026-03-11 18:27:23 +01:00
add covers list and attributes mutator
This commit is contained in:
@ -4,6 +4,8 @@ declare(strict_types=1);
|
||||
|
||||
namespace Pest\Factories\Attributes;
|
||||
|
||||
use Pest\Factories\Covers\CoversClass;
|
||||
use Pest\Factories\Covers\CoversFunction;
|
||||
use Pest\Factories\TestCaseMethodFactory;
|
||||
|
||||
/**
|
||||
@ -22,11 +24,16 @@ final class Covers
|
||||
public function __invoke(TestCaseMethodFactory $method, array $attributes): array
|
||||
{
|
||||
foreach ($method->covers as $covering) {
|
||||
if (is_array($covering)) {
|
||||
$attributes[] = "#[\PHPUnit\Framework\Attributes\CoversClass({$covering[0]}]";
|
||||
$attributes[] = "#[\PHPUnit\Framework\Attributes\CoversFunction({$covering[1]}]";
|
||||
if ($covering instanceof CoversClass) {
|
||||
$attributes[] = "#[\PHPUnit\Framework\Attributes\CoversClass({$covering->class}]";
|
||||
|
||||
if (!is_null($covering->method)) {
|
||||
$attributes[] = "#[\PHPUnit\Framework\Attributes\CoversFunction({$covering->method}]";
|
||||
}
|
||||
} else if ($covering instanceof CoversFunction) {
|
||||
$attributes[] = "#[\PHPUnit\Framework\Attributes\CoversFunction({$covering->function}]";
|
||||
} else {
|
||||
$attributes[] = "#[\PHPUnit\Framework\Attributes\CoversClass($covering)]";
|
||||
$attributes[] = "#[\PHPUnit\Framework\Attributes\CoversNothing]";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
16
src/Factories/Covers/CoversClass.php
Normal file
16
src/Factories/Covers/CoversClass.php
Normal file
@ -0,0 +1,16 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Pest\Factories\Covers;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
final class CoversClass
|
||||
{
|
||||
public function __construct(public string $class, public ?string $method = null)
|
||||
{
|
||||
//
|
||||
}
|
||||
}
|
||||
16
src/Factories/Covers/CoversFunction.php
Normal file
16
src/Factories/Covers/CoversFunction.php
Normal file
@ -0,0 +1,16 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Pest\Factories\Covers;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
final class CoversFunction
|
||||
{
|
||||
public function __construct(public string $function)
|
||||
{
|
||||
//
|
||||
}
|
||||
}
|
||||
13
src/Factories/Covers/CoversNothing.php
Normal file
13
src/Factories/Covers/CoversNothing.php
Normal file
@ -0,0 +1,13 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Pest\Factories\Covers;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
final class CoversNothing
|
||||
{
|
||||
//
|
||||
}
|
||||
@ -35,6 +35,15 @@ final class TestCaseFactory
|
||||
Annotations\Groups::class,
|
||||
];
|
||||
|
||||
/**
|
||||
* The list of annotations.
|
||||
*
|
||||
* @var array<int, class-string>
|
||||
*/
|
||||
private static array $attributes = [
|
||||
Attributes\Covers::class,
|
||||
];
|
||||
|
||||
/**
|
||||
* The FQN of the Test Case class.
|
||||
*
|
||||
@ -142,7 +151,7 @@ final class TestCaseFactory
|
||||
}
|
||||
|
||||
$methodsCode = implode('', array_map(
|
||||
fn (TestCaseMethodFactory $methodFactory) => $methodFactory->buildForEvaluation($classFQN, self::$annotations),
|
||||
fn (TestCaseMethodFactory $methodFactory) => $methodFactory->buildForEvaluation($classFQN, self::$annotations, self::$attributes),
|
||||
$methods
|
||||
));
|
||||
|
||||
|
||||
@ -50,7 +50,7 @@ final class TestCaseMethodFactory
|
||||
/**
|
||||
* The covered classes and methods, if any.
|
||||
*
|
||||
* @var array<int, string>
|
||||
* @var array<int, \Pest\Factories\Covers\CoversClass|\Pest\Factories\Covers\CoversFunction|\Pest\Factories\Covers\CoversNothing>
|
||||
*/
|
||||
public array $covers = [];
|
||||
|
||||
|
||||
Reference in New Issue
Block a user