{"record":{"id":"43e81e23b1419d90","repo":"pestphp/pest","slug":"unable-to-create-test-case-for-test-file-at-s","errorCode":null,"errorMessage":"Unable to create test case for test file at [%s]. \n %s","messagePattern":"Unable to create test case for test file at \\[(.+?)\\]\\. \n (.+?)","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"critical","filePath":"src/Factories/TestCaseFactory.php","lineNumber":172,"sourceCode":"\n            use Pest\\Exceptions\\DatasetProviderError as __PestDatasetProviderError;\n            use Pest\\Repositories\\DatasetsRepository as __PestDatasets;\n            use Pest\\TestSuite as __PestTestSuite;\n\n            $attributesCode\n            #[\\AllowDynamicProperties]\n            final class $className extends $baseClass implements $hasPrintableTestCaseClassFQN {\n                $traitsCode\n\n                public static \\$__filename = $filenameLiteral;\n\n                $methodsCode\n            }\n            PHP;\n\n            eval($classCode);\n        } catch (ParseError $caught) {\n            throw new RuntimeException(sprintf(\n                \"Unable to create test case for test file at [%s]. \\n %s\",\n                $filename,\n                $classCode\n            ), 1, $caught);\n        }\n    }\n\n    public function addMethod(TestCaseMethodFactory $method): void\n    {\n        if ($method->description === null) {\n            throw new TestDescriptionMissing($method->filename);\n        }\n\n        if (array_key_exists($method->description, $this->methods)) {\n            throw new TestAlreadyExist($method->filename, $method->description);\n        }\n\n        if (","sourceCodeStart":154,"sourceCodeEnd":190,"githubUrl":"https://github.com/pestphp/pest/blob/1af74a215c3a89bc7a44fc6f9322e369eaad2423/src/Factories/TestCaseFactory.php#L154-L190","documentation":"For every test file, TestCaseFactory generates a PHP test-case class (filename constant, trait code, method code) and evals it. If the generated source fails to parse, the ParseError is caught and rethrown as a RuntimeException containing the test file path and the full generated class code — so the exception message doubles as a debugging dump of what Pest built. It is rare and usually signals either an exotic test file or a Pest code-generation bug.","triggerScenarios":"A test file whose name or test descriptions produce class/method code the generator cannot quote safely; trait composition (uses()) injecting code that breaks the generated class; version mismatches after upgrading Pest or PHP where codegen assumptions changed; eval() disabled is not the cause here (that raises a different error) — a genuine parse failure is.","commonSituations":"Upgrading Pest across major versions with stale caches or mixed old/new vendor files; unusual filenames (spaces, unicode) for test files; projects generating Pest files programmatically with unescaped content; PHP version changes altering acceptable syntax in eval'd code.","solutions":["Read the generated class code embedded in the exception message and locate the malformed fragment — usually the method name or trait list derived from your test file.","Simplify/rename the offending pieces: ASCII filenames, plain test descriptions, standard uses() usage; then re-run.","Reinstall a clean dependency tree (rm -rf vendor composer.lock && composer install) to rule out half-upgraded codegen.","If the generated code looks wrong for a normal test file, report it to pestphp/pest including the message — it is likely a codegen bug."],"exampleFix":"// before: test file with an exotic name \"2024‑07 ✔.php\" -> generated class fails to parse\n// after: rename the file to plain ASCII\ngit mv \"tests/2024-07 ✔.php\" tests/ReleaseSmokeTest.php","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n    $factory->buildTestCaseFor($filename);\n} catch (RuntimeException $e) {\n    // message embeds the generated class code — dump it for the bug report\n    file_put_contents(__DIR__.'/pest-generated-dump.php', $e->getMessage());\n    throw $e;\n}","preventionTips":["Keep test filenames and descriptions plain ASCII identifiers.","After major Pest/PHP upgrades, run a clean vendor reinstall before debugging codegen errors.","If you generate Pest test files programmatically, run them through php -l in CI to catch unparseable output early.","Report reproducible codegen ParseErrors upstream with the embedded generated class."],"tags":["pest","code-generation","eval","parse-error","testcase-factory"],"backgroundTag":"generated-code-parse-error","analyzedSha":"1af74a215c3a89bc7a44fc6f9322e369eaad2423","analyzedAt":"2026-08-21T02:16:38.132Z","schemaVersion":2},"datasetVersion":"2026-08-21T03:17:12.404Z"}