Last active
October 27, 2024 14:22
-
-
Save dillingham/3f71297e3264681897b960e11b63e127 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
test('All controllers must have corresponding test files with correct paths', function () { | |
$controllerPath = base_path('app/Http/Controllers'); | |
$testPath = base_path('tests/Feature'); | |
$controllerFiles = collect(File::allFiles($controllerPath)) | |
->filter(fn($file) => $file->getExtension() === 'php') | |
->map(function ($file) use ($controllerPath) { | |
return str_replace([$controllerPath . '/', '.php'], '', $file->getPathname()); | |
}); | |
$testFiles = collect(File::allFiles($testPath)) | |
->filter(fn($file) => $file->getExtension() === 'php') | |
->map(function ($file) use ($testPath) { | |
return str_replace([$testPath . '/', 'Test.php'], '', $file->getPathname()); | |
}); | |
$missingTests = $controllerFiles->diff($testFiles); | |
if ($missingTests->isNotEmpty()) { | |
echo 'Missing or incorrectly placed tests for controllers:' . PHP_EOL; | |
foreach ($missingTests as $missingTest) { | |
echo "- $missingTest" . PHP_EOL; | |
} | |
} | |
expect($missingTests->isEmpty())->toBeTrue( | |
'There are controllers without corresponding test files, see list above.' | |
); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment