diff --git a/tests/Architecture/CodingStandardsTest.php b/tests/Architecture/CodingStandardsTest.php index 9e4cd4f..7d7ceb2 100644 --- a/tests/Architecture/CodingStandardsTest.php +++ b/tests/Architecture/CodingStandardsTest.php @@ -4,6 +4,31 @@ declare(strict_types=1); namespace Tests\Architecture; +/** + * @param array $directories + * @return array + */ +function getTestFiles(array $directories): array +{ + $files = []; + foreach ($directories as $dir) { + $path = base_path($dir); + if (! is_dir($path)) { + continue; + } + $dirIterator = new \RecursiveDirectoryIterator($path, \RecursiveDirectoryIterator::SKIP_DOTS); + $iterator = new \RecursiveIteratorIterator($dirIterator); + /** @var \SplFileInfo $file */ + foreach ($iterator as $file) { + if ($file->isFile() && str_ends_with($file->getFilename(), 'Test.php')) { + $files[] = $file->getPathname(); + } + } + } + + return $files; +} + describe('Coding Standards & Project Rules', function (): void { arch()->preset()->php(); // Le helper assert natif est interdit en faveur de Webmozart\Assert @@ -66,14 +91,7 @@ describe('Coding Standards & Project Rules', function (): void { ->toUseStrictTypes(); it('ensures every test file in tests directory has a namespace', function (): void { - /** @var array $testFiles */ - $testFiles = glob(base_path('tests/{*,*/*,*/*/*,*/*/*/*}.php'), GLOB_BRACE); - - foreach ($testFiles as $file) { - if (preg_match('/Test\.php$/', basename($file)) !== 1) { - continue; - } - + foreach (getTestFiles(['tests']) as $file) { $content = (string) file_get_contents($file); expect($content)->toMatch( '/^\s*namespace\s+Tests/m', @@ -83,14 +101,7 @@ describe('Coding Standards & Project Rules', function (): void { }); it('ensures every Unit and Integration test file contains a covers() call', function (): void { - /** @var array $testFiles */ - $testFiles = glob(base_path('{tests/Unit,tests/Integration}/{*,*/*,*/*/*,*/*/*/*}.php'), GLOB_BRACE); - - foreach ($testFiles as $file) { - if (preg_match('/Test\.php$/', basename($file)) !== 1) { - continue; - } - + foreach (getTestFiles(['tests/Unit', 'tests/Integration']) as $file) { $content = (string) file_get_contents($file); expect($content)->toMatch( '/^\s*covers\s*\(/m',