{"record":{"id":"84e6a94b226e7b4a","repo":"sebastianbergmann/phpunit","slug":"s-section-is-empty","errorCode":null,"errorMessage":"--%s-- section is empty","messagePattern":"--(.+?)-- section is empty","errorType":"exception","errorClass":"InvalidPhptFileException","httpStatus":null,"severity":"error","filePath":"src/Runner/Phpt/Parser.php","lineNumber":340,"sourceCode":"    /**\n     * @param array<non-empty-string, string> $sections\n     * @param non-empty-string                $codeSection\n     *\n     * @throws InvalidPhptFileException\n     */\n    private function ensureCodeIsNotEmpty(array $sections, string $codeSection): void\n    {\n        if (isset($sections['FILE']) && $sections['FILE'] !== '') {\n            return;\n        }\n\n        if ($codeSection === 'FILE_EXTERNAL') {\n            throw new InvalidPhptFileException(\n                'File referenced by --FILE_EXTERNAL-- section is empty',\n            );\n        }\n\n        throw new InvalidPhptFileException(\n            sprintf(\n                '--%s-- section is empty',\n                $codeSection,\n            ),\n        );\n    }\n}\n","sourceCodeStart":322,"sourceCodeEnd":348,"githubUrl":"https://github.com/sebastianbergmann/phpunit/blob/f123cdb2a2d49f15025794166cfed8bda8627dd2/src/Runner/Phpt/Parser.php#L322-L348","documentation":"ensureCodeIsNotEmpty() is the last stop of parse(): when no early return applies (FILE is absent or empty) and the code section is FILE or FILEEOF, it throws InvalidPhptFileException(sprintf('--%s-- section is empty', $codeSection)). The code section exists but has no content, so there is nothing to run.","triggerScenarios":"A .phpt whose --FILE-- section contains no lines (header immediately followed by the next header), or a --FILEEOF-- section whose rtrim()ed content is empty.","commonSituations":"Creating a test from a skeleton and not filling in the code yet; editing away the body; misunderstanding FILEEOF (its content is rtrim()ed of trailing newlines and used as FILE).","solutions":["Add the PHP code to the empty --FILE-- (or --FILEEOF--) section.","If the test genuinely runs no code, reconsider whether it should be a PHPT test at all — a plain PHPUnit TestCase is a better fit."],"exampleFix":"-- before\n--FILE--\n--EXPECT--\nHello\n\n-- after\n--FILE--\necho 'Hello';\n--EXPECT--\nHello","handlingStrategy":"validation","validationCode":"// verify the --FILE-- section has a body (next line after the header is not another header)\n$body = (string) file_get_contents($phptFile);\nif (preg_match('/--FILE--\\R(--[_A-Z]+--|\\s*$)/', $body) === 1) {\n    throw new RuntimeException('--FILE-- section is empty in ' . $phptFile);\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Never save a .phpt skeleton with an empty --FILE-- section; put at least a minimal echo in it.","Prefer plain TestCase classes for tests that run no code."],"tags":["phpunit","phpt","empty-section","parser"],"backgroundTag":"empty-required-section","analyzedSha":"f123cdb2a2d49f15025794166cfed8bda8627dd2","analyzedAt":"2026-08-23T01:20:58.058Z","schemaVersion":2},"datasetVersion":"2026-08-23T08:06:27.607Z"}