From 443f8483864c59526d4655805754004e8469258b Mon Sep 17 00:00:00 2001 From: danilopolani Date: Mon, 7 Mar 2022 17:40:29 +0100 Subject: [PATCH] fix fqn for coversClass --- src/Factories/Attributes/Covers.php | 5 +++++ src/Factories/TestCaseFactory.php | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/Factories/Attributes/Covers.php b/src/Factories/Attributes/Covers.php index 67cf44ad..1d0e6991 100644 --- a/src/Factories/Attributes/Covers.php +++ b/src/Factories/Attributes/Covers.php @@ -32,6 +32,11 @@ final class Covers extends Attribute { foreach ($method->covers as $covering) { if ($covering instanceof CoversClass) { + // Prepend a backslash for FQN classes + if (str_contains($covering->class, '\\')) { + $covering->class = '\\' . $covering->class; + } + $attributes[] = "#[\PHPUnit\Framework\Attributes\CoversClass({$covering->class}::class)]"; } else if ($covering instanceof CoversFunction) { $attributes[] = "#[\PHPUnit\Framework\Attributes\CoversFunction('{$covering->function}')]"; diff --git a/src/Factories/TestCaseFactory.php b/src/Factories/TestCaseFactory.php index d568ee3e..2fb6d429 100644 --- a/src/Factories/TestCaseFactory.php +++ b/src/Factories/TestCaseFactory.php @@ -166,7 +166,7 @@ final class TestCaseFactory } $classAttributes = implode('', array_map( - static fn ($attribute) => sprintf("\n %s", $attribute), + static fn (string $attribute) => sprintf("\n %s", $attribute), array_unique($classAttributes), ));