-
-
Notifications
You must be signed in to change notification settings - Fork 454
Open
Description
Technical information
- php v8.4
- laravel v12.42
- pest v4.2
Now, in architectural tests, we can check suffixes in class names
Example:
test('Controllers should have Controller suffix')
->expect('App\Http\Controllers')
->classes()
->toHaveSuffix('Controller');I want to check that tests contain the suffix “Test” so that they participate in testing, because sometimes we may simply forget to add the suffix “Test” and the file does not submit during testing
I couldn't find how to do this in the documentation
Wrote a custom test that works:
test('Tests should have Test suffix', function () {
$testDirs = [
'tests',
];
$exceptions = [
'TestCase.php',
'Pest.php',
];
$invalidFiles = collect($testDirs)
->filter(fn($dir) => is_dir($dir))
->flatMap(function ($dir) use ($exceptions) {
return collect(
new RecursiveIteratorIterator(
new RecursiveDirectoryIterator($dir)
)
)->filter(fn($file) => $file->isFile())
->filter(fn($file) => $file->getExtension() === 'php')
->filter(fn($file) => ! in_array($file->getFilename(), $exceptions, true))
->filter(fn($file) => ! str_ends_with($file->getFilename(), 'Test.php'))
->map(fn($file) => $file->getPathname())
->all();
});
expect($invalidFiles)->toBeEmpty(
"Files not should have Test suffix:\n" . $invalidFiles->implode("\n")
);
});I want to know if it is possible to do the same with pest as implemented in the first example ?
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels