{"record":{"id":"7c599024c0d321f9","repo":"sebastianbergmann/phpunit","slug":"phpunit-does-not-support-phpt-s-sections","errorCode":null,"errorMessage":"PHPUnit does not support PHPT --%s-- sections","messagePattern":"PHPUnit does not support PHPT --(.+?)-- sections","errorType":"exception","errorClass":"UnsupportedPhptSectionException","httpStatus":null,"severity":"error","filePath":"src/Runner/Phpt/Parser.php","lineNumber":170,"sourceCode":"\n            $sections[$section] .= $line;\n        }\n\n        $codeSection = $this->ensureExactlyOneSectionOf($sections, self::FILE_SECTIONS);\n\n        $this->ensureExactlyOneSectionOf($sections, self::EXPECTATION_SECTIONS);\n\n        if (isset($sections['FILEEOF'])) {\n            $sections['FILE'] = rtrim($sections['FILEEOF'], \"\\r\\n\");\n\n            unset($sections['FILEEOF']);\n        }\n\n        $this->parseExternal($phptFile, $sections);\n\n        foreach (self::UNSUPPORTED_SECTIONS as $unsupportedSection) {\n            if (isset($sections[$unsupportedSection])) {\n                throw new UnsupportedPhptSectionException($unsupportedSection);\n            }\n        }\n\n        $this->ensureCodeIsNotEmpty($sections, $codeSection);\n\n        return $sections;\n    }\n\n    /**\n     * @return array<non-empty-string, string>\n     */\n    public function parseEnvSection(string $content): array\n    {\n        $env = [];\n\n        foreach (explode(\"\\n\", trim($content)) as $e) {\n            $e = explode('=', trim($e), 2);\n","sourceCodeStart":152,"sourceCodeEnd":188,"githubUrl":"https://github.com/sebastianbergmann/phpunit/blob/f123cdb2a2d49f15025794166cfed8bda8627dd2/src/Runner/Phpt/Parser.php#L152-L188","documentation":"After section parsing, parse() loops over the UNSUPPORTED_SECTIONS constant (CGI, COOKIE, DEFLATE_POST, EXPECTHEADERS, EXTENSIONS, GET, GZIP_POST, HEADERS, PHPDBG, POST, POST_RAW, PUT, REDIRECTTEST, REQUEST) and throws UnsupportedPhptSectionException('PHPUnit does not support PHPT --%s-- sections') when one is present. These are real php run-tests.php sections that PHPUnit deliberately rejects, mostly because they require a CGI/web harness PHPUnit does not provide.","triggerScenarios":"Running a .phpt written for php run-tests.php that uses --POST--, --GET--, --COOKIE--, --EXPECTHEADERS--, --POST_RAW-- etc.; copying php-src or extension PHPT suites verbatim into a PHPUnit-driven test run.","commonSituations":"Porting php-src/PECL tests that exercise the CGI SAPI; reusing upstream PHPT corpora in CI based on PHPUnit; grabbing a run-tests test without checking PHPUnit's support matrix.","solutions":["Remove the unsupported section when the test still makes sense without it (for example drop --EXPECTHEADERS-- and keep --EXPECT--).","Rewrite the test as a normal PHPUnit TestCase (e.g. using an HTTP client against a running server) when it genuinely depends on request data.","Leave such tests to php run-tests.php or a harness that supports CGI sections."],"exampleFix":"-- before\n--POST--\na=1\n--FILE--\n<?php echo $_POST['a'];\n--EXPECT--\n1\n\n-- after (plain PHPUnit test)\npublic function testPostA(): void\n{\n    $response = $this->client->post('/', ['a' => '1']);\n    self::assertSame('1', (string) $response->getBody());\n}","handlingStrategy":"validation","validationCode":"function assertNoUnsupportedPhptSections(string $phptFile): void\n{\n    $unsupported = ['CGI','COOKIE','DEFLATE_POST','EXPECTHEADERS','EXTENSIONS','GET',\n        'GZIP_POST','HEADERS','PHPDBG','POST','POST_RAW','PUT','REDIRECTTEST','REQUEST'];\n\n    foreach (file($phptFile) as $line) {\n        if (preg_match('/^--([_A-Z]+)--/', $line, $m) === 1 && in_array($m[1], $unsupported, true)) {\n            throw new RuntimeException('PHPUnit cannot run --' . $m[1] . '--; port the test to a TestCase');\n        }\n    }\n}","typeGuard":null,"tryCatchPattern":"try {\n    $sections = (new \\PHPUnit\\Runner\\Phpt\\Parser())->parse($phptFile);\n} catch (\\PHPUnit\\Runner\\Phpt\\UnsupportedPhptSectionException $e) {\n    // route this file to php run-tests.php or port it; do not retry as-is\n}","preventionTips":["Before importing run-tests.php suites, filter out tests whose headers intersect the CGI/request section list.","Keep web-request PHPT tests in a separate CI job driven by a harness that supports them."],"tags":["phpunit","phpt","cgi","unsupported-section","porting"],"backgroundTag":"unsupported-file-section","analyzedSha":"f123cdb2a2d49f15025794166cfed8bda8627dd2","analyzedAt":"2026-08-23T01:20:58.058Z","schemaVersion":2},"datasetVersion":"2026-08-23T08:06:27.607Z"}