Skip to content

Commit d5b06dd

Browse files
committed
test: use CoversTrait in PHPUnit 11.2+
1 parent 6139eb3 commit d5b06dd

File tree

1 file changed

+21
-3
lines changed

1 file changed

+21
-3
lines changed

test/unit/ExceptionDetailsTraitTest.php

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,18 @@
44

55
namespace Qameta\Allure\PHPUnit\Test\Unit;
66

7+
// phpcs:disable PSR1.Classes.ClassDeclaration.MultipleClasses
8+
79
use Exception;
810
use PHPUnit\Framework\TestCase;
11+
use PHPUnit\Framework\Attributes\CoversClass;
12+
use PHPUnit\Framework\Attributes\CoversTrait;
913
use Qameta\Allure\PHPUnit\ExceptionDetailsTrait;
1014
use Qameta\Allure\PHPUnit\AllureAdapter;
1115
use Qameta\Allure\PHPUnit\AllureAdapterInterface;
1216
use Throwable;
1317

14-
// #[CoversTrait(ExceptionDetailsTrait::class)] <--- needed by phpunit 12
15-
// #[CoversClass(ExceptionDetailsTrait::class)] <--- needed by phpunit 10 + 11
16-
final class ExceptionDetailsTraitTest extends TestCase
18+
abstract class ExceptionDetailsTraitTestBase extends TestCase
1719
{
1820
public function testOnNotSuccessfulTest_GivenException_ThrowsSameException(): void
1921
{
@@ -49,3 +51,19 @@ public function testOnNotSuccessfulTest_GivenException_SetsSameExceptionAsLast()
4951
}
5052
}
5153
}
54+
55+
if (class_exists(CoversTrait::class)) {
56+
// Since PHPUnit 11.2.0 (deprecation has been reverted in 11.5.4)
57+
#[CoversTrait(ExceptionDetailsTrait::class)]
58+
final class ExceptionDetailsTraitTest extends ExceptionDetailsTraitTestBase
59+
{
60+
}
61+
62+
} else {
63+
// For PHPUnit <11.2.0
64+
#[CoversClass(ExceptionDetailsTrait::class)]
65+
final class ExceptionDetailsTraitTest extends ExceptionDetailsTraitTestBase
66+
{
67+
}
68+
69+
}

0 commit comments

Comments
 (0)