diff --git a/src/Factories/Attributes/Attribute.php b/src/Factories/Attributes/Attribute.php new file mode 100644 index 00000000..2eaf8dbf --- /dev/null +++ b/src/Factories/Attributes/Attribute.php @@ -0,0 +1,18 @@ + + * @var array */ private static array $attributes = [ Attributes\Covers::class, @@ -155,6 +155,19 @@ final class TestCaseFactory $methods )); + $classAttributes = []; + + foreach (self::$attributes as $attribute) { + if ($attribute::ABOVE_CLASS) { + /** @phpstan-ignore-next-line */ + $classAttributes = (new $attribute())->__invoke($this, $classAttributes); + } + } + + $classAttributes = implode('', array_map( + static fn ($attribute) => sprintf("\n %s", $attribute), $classAttributes, + )); + try { eval(" namespace $namespace; @@ -162,6 +175,7 @@ final class TestCaseFactory use Pest\Repositories\DatasetsRepository as __PestDatasets; use Pest\TestSuite as __PestTestSuite; + $classAttributes final class $className extends $baseClass implements $hasPrintableTestCaseClassFQN { $traitsCode diff --git a/src/Factories/TestCaseMethodFactory.php b/src/Factories/TestCaseMethodFactory.php index aac6c8dc..bb9e6721 100644 --- a/src/Factories/TestCaseMethodFactory.php +++ b/src/Factories/TestCaseMethodFactory.php @@ -129,18 +129,12 @@ final class TestCaseMethodFactory $datasetsCode = ''; $annotations = ['@test']; - $attributes = []; foreach ($annotationsToUse as $annotation) { /** @phpstan-ignore-next-line */ $annotations = (new $annotation())->__invoke($this, $annotations); } - foreach ($attributesToUse as $attribute) { - /** @phpstan-ignore-next-line */ - $attributes = (new $attribute())->__invoke($this, $attributes); - } - if (count($this->datasets) > 0) { $dataProviderName = $methodName . '_dataset'; $annotations[] = "@dataProvider $dataProviderName"; @@ -151,15 +145,10 @@ final class TestCaseMethodFactory static fn ($annotation) => sprintf("\n * %s", $annotation), $annotations, )); - $attributes = implode('', array_map( - static fn ($attribute) => sprintf("\n %s", $attribute), $attributes, - )); - return <<__runTest(