diff --git a/src/Test/KernelTestCase.php b/src/Test/KernelTestCase.php index cdb241a..06a458c 100644 --- a/src/Test/KernelTestCase.php +++ b/src/Test/KernelTestCase.php @@ -19,6 +19,9 @@ use Psl\Json; use Psl\Str; use Psl\Type; +use Psl\Vec; +use ReflectionAttribute; +use ReflectionClass; use ReflectionObject; use RuntimeException; use Speicher210\FunctionalTestBundle\Attribute\WithFixture; @@ -265,6 +268,7 @@ private function getFixturesFromTestAttributes(): iterable $testName = $this->name(); $classAttributes = [ + ...$this->getFixturesFromTraits($reflection), ...$reflection->getAttributes(WithFixture::class), ...$reflection->getAttributes(WithFixtureForTest::class), ]; @@ -295,6 +299,22 @@ private function getFixturesFromTestAttributes(): iterable } } + /** + * @param ReflectionObject|ReflectionClass $reflection + * + * @return list> + */ + private function getFixturesFromTraits(ReflectionObject|ReflectionClass $reflection): array + { + return Vec\flat_map( + $reflection->getTraits(), + fn (ReflectionClass $class) => [ + ...$class->getAttributes(WithFixture::class), + ...$this->getFixturesFromTraits($class), + ], + ); + } + /** * @return non-empty-string */