test(CodingStandards): refactor test file retrieval logic

Updated test file retrieval to use a dedicated function for improved clarity and maintainability.
This commit is contained in:
Jérémy Munsch 2026-08-13 12:58:29 +02:00
parent 39d394b7fb
commit ab031e8d76
Signed by: forge-joniko
GPG key ID: D7EFE2F5CB6CC0E4

View file

@ -4,6 +4,31 @@ declare(strict_types=1);
namespace Tests\Architecture;
/**
* @param array<int, string> $directories
* @return array<int, string>
*/
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<int, string> $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<int, string> $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',