diff --git a/tests/Scoper/Spec/SpecParser.php b/tests/Scoper/Spec/SpecParser.php index e0019fbf..92d4a605 100644 --- a/tests/Scoper/Spec/SpecParser.php +++ b/tests/Scoper/Spec/SpecParser.php @@ -20,6 +20,7 @@ use Humbug\PhpScoper\Configuration\SymbolsConfigurationFactory; use Humbug\PhpScoper\NotInstantiable; use InvalidArgumentException; +use PHPUnit\Framework\Assert; use PHPUnit\Framework\Attributes\Group; use PHPUnit\Framework\TestCase; use Symfony\Component\Finder\SplFileInfo; @@ -81,15 +82,19 @@ class SpecParser extends TestCase /** * @throws UnparsableFile */ - public static function parseSpecFile(string $sourceDir, SplFileInfo $file): iterable - { + public static function parseSpecFile( + string $sourceDir, + SplFileInfo $file, + ): iterable { try { - $fixtures = include $file; + $specs = include $file; + + self::checkSpecFileSchema($specs); - $meta = $fixtures['meta']; - unset($fixtures['meta']); + $meta = $specs['meta']; + unset($specs['meta']); - foreach ($fixtures as $fixtureTitle => $fixtureSet) { + foreach ($specs as $fixtureTitle => $fixtureSet) { yield from self::parseSpec( basename($sourceDir).'/'.$file->getRelativePathname(), $meta, @@ -102,6 +107,21 @@ public static function parseSpecFile(string $sourceDir, SplFileInfo $file): iter } } + /** + * @phpstan-assert array{'meta': array, array-key: string|array} $specs + */ + private static function checkSpecFileSchema(mixed $specs): void + { + Assert::assertIsArray($specs); + + Assert::assertArrayHasKey('meta', $specs); + Assert::assertIsArray($specs['meta']); + + foreach ($specs as $title => $spec) { + Assert::assertTrue(is_string($spec) || is_array($spec)); + } + } + private static function parseSpec( string $file, array $meta,