{"record":{"id":"08296cc538d6bf6f","repo":"sebastianbergmann/phpunit","slug":"file-referenced-by-file-external-section-is-em","errorCode":null,"errorMessage":"File referenced by --FILE_EXTERNAL-- section is empty","messagePattern":"File referenced by --FILE_EXTERNAL-- section is empty","errorType":"exception","errorClass":"InvalidPhptFileException","httpStatus":null,"severity":"error","filePath":"src/Runner/Phpt/Parser.php","lineNumber":335,"sourceCode":"        }\n\n        return $found[0];\n    }\n\n    /**\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":317,"sourceCodeEnd":348,"githubUrl":"https://github.com/sebastianbergmann/phpunit/blob/f123cdb2a2d49f15025794166cfed8bda8627dd2/src/Runner/Phpt/Parser.php#L317-L348","documentation":"ensureCodeIsNotEmpty() returns early when a non-empty FILE section exists; parseExternal() has already loaded the --FILE_EXTERNAL-- target's contents into sections['FILE']. When the resolved code section is FILE_EXTERNAL and that content is empty, InvalidPhptFileException('File referenced by --FILE_EXTERNAL-- section is empty') is thrown: the external file exists and is readable, but contributes no code.","triggerScenarios":"--FILE_EXTERNAL-- points at a zero-byte file, or a file containing only whitespace/newlines, so after loading there is no code to execute.","commonSituations":"Placeholder fixtures committed empty; a fixture script truncated during a bad merge; a generation step that failed silently before the test run.","solutions":["Put the intended PHP code into the file referenced by --FILE_EXTERNAL--.","If fixtures are generated at build time, make the generator fail the build on empty output instead of writing an empty file."],"exampleFix":"# before: hello.php is empty (0 bytes)\n--FILE_EXTERNAL--\nhello.php\n\n# after: hello.php contains\n<?php echo 'Hello';","handlingStrategy":"validation","validationCode":"// before running PHPT tests, verify FILE_EXTERNAL targets are non-empty\nforeach (glob('tests/*.phpt') as $phpt) {\n    $body = (string) file_get_contents($phpt);\n    if (preg_match('/--FILE_EXTERNAL--\\R\\s*(\\S+)/', $body, $m) === 1) {\n        $target = dirname($phpt) . DIRECTORY_SEPARATOR . $m[1];\n        if (trim((string) file_get_contents($target)) === '') {\n            throw new RuntimeException(\"Empty FILE_EXTERNAL fixture: {$target}\");\n        }\n    }\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Make fixture generators fail on empty output instead of writing zero-byte files.","Reject empty fixture files in review and in pre-commit hooks."],"tags":["phpunit","phpt","empty-file","fixtures","file-external"],"backgroundTag":"empty-required-section","analyzedSha":"f123cdb2a2d49f15025794166cfed8bda8627dd2","analyzedAt":"2026-08-23T01:20:58.058Z","schemaVersion":2},"datasetVersion":"2026-08-23T08:06:27.607Z"}