fix fqn on coversClass attribute and array evaluation

This commit is contained in:
danilopolani
2022-03-07 16:18:55 +01:00
parent 1dc33070fe
commit 32dbac87c8
2 changed files with 7 additions and 5 deletions

View File

@ -32,9 +32,9 @@ final class Covers extends Attribute
{ {
foreach ($method->covers as $covering) { foreach ($method->covers as $covering) {
if ($covering instanceof CoversClass) { if ($covering instanceof CoversClass) {
$attributes[] = "#[\PHPUnit\Framework\Attributes\CoversClass({$covering->class}]"; $attributes[] = "#[\PHPUnit\Framework\Attributes\CoversClass({$covering->class}::class)]";
} else if ($covering instanceof CoversFunction) { } else if ($covering instanceof CoversFunction) {
$attributes[] = "#[\PHPUnit\Framework\Attributes\CoversFunction('{$covering->function}']"; $attributes[] = "#[\PHPUnit\Framework\Attributes\CoversFunction('{$covering->function}')]";
} else { } else {
$attributes[] = "#[\PHPUnit\Framework\Attributes\CoversNothing]"; $attributes[] = "#[\PHPUnit\Framework\Attributes\CoversNothing]";
} }

View File

@ -159,13 +159,15 @@ final class TestCaseFactory
foreach (self::$attributes as $attribute) { foreach (self::$attributes as $attribute) {
if ($attribute::ABOVE_CLASS) { if ($attribute::ABOVE_CLASS) {
/** @phpstan-ignore-next-line */ foreach ($methods as $methodFactory) {
$classAttributes = (new $attribute())->__invoke($this, $classAttributes); $classAttributes = (new $attribute())->__invoke($methodFactory, $classAttributes);
}
} }
} }
$classAttributes = implode('', array_map( $classAttributes = implode('', array_map(
static fn ($attribute) => sprintf("\n %s", $attribute), $classAttributes, static fn ($attribute) => sprintf("\n %s", $attribute),
array_unique($classAttributes),
)); ));
try { try {