pestphp/pest · error · TestCaseClassOrTraitNotFound
The class or trait [%s] could not be found. Please check the
Error message
The class or trait [%s] could not be found. Please check the name, and make sure it is autoloadable.
What it means
Error "The class or trait [%s] could not be found. Please check the name, and make sure it is autoloadable." thrown in pestphp/pest.
Source
Thrown at src/Repositories/TestRepository.php:72
return array_values(array_map(static fn (TestCaseFactory $factory): string => $factory->filename, $this->testCases));
}
/**
* @param array<int, string> $classOrTraits
* @param array<int, string> $groups
* @param array<int, string> $paths
* @param array<int, Closure> $hooks
*/
public function use(array $classOrTraits, array $groups, array $paths, array $hooks): void
{
foreach ($classOrTraits as $classOrTrait) {
if (class_exists($classOrTrait)) {
continue;
}
if (trait_exists($classOrTrait)) {
continue;
}
throw new TestCaseClassOrTraitNotFound($classOrTrait);
}
$hooks = array_map(fn (Closure $hook): array => [$hook], $hooks);
foreach ($paths as $path) {
if (array_key_exists($path, $this->uses)) {
$this->uses[$path] = [
[...$this->uses[$path][0], ...$classOrTraits],
[...$this->uses[$path][1], ...$groups],
array_map(
fn (int $index): array => [...$this->uses[$path][2][$index] ?? [], ...($hooks[$index] ?? [])],
range(0, 3),
),
];
} else {
$this->uses[$path] = [$classOrTraits, $groups, $hooks];
}
}View on GitHub (pinned to 1af74a215c)
When it happens
Trigger: Thrown at src/Repositories/TestRepository.php:72 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of pestphp/pest@1af74a215c (2026-08-21).
Data as JSON: /api/errors/65ddf9824339639f.
Report an issue: GitHub.