{"record":{"id":"c73d5d4ce83c0234","repo":"sebastianbergmann/phpunit","slug":"option-s-requires-a-non-empty-value","errorCode":null,"errorMessage":"Option %s requires a non-empty value","messagePattern":"Option (.+?) requires a non-empty value","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"src/TextUI/Configuration/Cli/Builder.php","lineNumber":1696,"sourceCode":"     */\n    private function parseStopOnValue(?string $value): int\n    {\n        if (is_numeric($value)) {\n            return max(1, (int) $value);\n        }\n\n        return 1;\n    }\n\n    /**\n     * @throws Exception\n     *\n     * @return non-empty-string\n     */\n    private function requireNonEmptyValue(?string $value, string $option): string\n    {\n        if ($value === null || $value === '') {\n            throw new Exception(\n                sprintf('Option %s requires a non-empty value', $option),\n            );\n        }\n\n        return $value;\n    }\n\n    /**\n     * @throws Exception\n     *\n     * @return positive-int\n     */\n    private function requirePositiveIntValue(?string $value, string $option): int\n    {\n        if (!is_numeric($value)) {\n            throw new Exception(\n                sprintf('Option %s requires a positive integer value', $option),\n            );","sourceCodeStart":1678,"sourceCodeEnd":1714,"githubUrl":"https://github.com/sebastianbergmann/phpunit/blob/f123cdb2a2d49f15025794166cfed8bda8627dd2/src/TextUI/Configuration/Cli/Builder.php#L1678-L1714","documentation":"requireNonEmptyValue() (src/TextUI/Configuration/Cli/Builder.php:1693) guards options whose value must be a non-empty string: --group, --exclude-group, --covers, --uses, --requires-php-extension, --test-suffix, --coverage-filter, --log-events-text, --log-events-verbose-text, and --extension. It throws when getopt hands the Builder null or '' for one of these. The message names the offending option.","triggerScenarios":"`vendor/bin/phpunit --group=` (empty string after =); `--exclude-group \"$GROUPS\"` where the shell variable is empty or unset; CI matrix variables interpolating to ''; `--test-suffix ''` from a wrapper that always passes the flag.","commonSituations":"Unbound or empty environment variables interpolated into CI commands (GitLab/GitHub Actions/GitLab YAML); Makefiles that always emit the flag; wrappers that pass optional filters unconditionally.","solutions":["Give the option a non-empty value, e.g. `--group=unit`","Guard the shell expansion so the flag disappears when the variable is empty: `${GROUP:+--group \"$GROUP\"}`","Provide a default: `--group \"${GROUP:-default}\"`"],"exampleFix":"# before\nvendor/bin/phpunit --exclude-group \"$EXCLUDED\"\n# EXCLUDED=\"\" -> Option --exclude-group requires a non-empty value\n\n# after\nvendor/bin/phpunit ${EXCLUDED:+--exclude-group \"$EXCLUDED\"} tests","handlingStrategy":"validation","validationCode":"// Wrapper-side guard for every value-taking option you forward\n$forwarded = [];\n\nforeach (['--group', '--exclude-group', '--covers', '--uses', '--test-suffix', '--coverage-filter', '--extension'] as $opt) {\n    $val = getopt('', ['group::', 'exclude-group::'])[$opt] ?? null; // or your own source\n    // simplest: validate before composing the command\n}\n\n// Shell-level guard (recommended):\n// vendor/bin/phpunit ${GROUP:+--group \"$GROUP\"} tests","typeGuard":null,"tryCatchPattern":"try {\n    $cliConfig = (new \\PHPUnit\\TextUI\\CliArguments\\Builder)->fromParameters($argv);\n} catch (\\PHPUnit\\TextUI\\CliArguments\\Exception $e) {\n    if (preg_match('/Option (.+) requires a non-empty value/', $e->getMessage(), $m)) {\n        // $m[1] names the flag: supply a value or strip the flag and rebuild argv\n    }\n}","preventionTips":["Use shell parameter expansion `${VAR:+--flag \"$VAR\"}` so empty variables drop the flag","In CI YAML, guard empty inputs with `if: ${{ env.GROUP != '' }}` or default the variable","Never interpolate unvalidated user input directly into option values"],"tags":["phpunit","cli","option-value","shell-interpolation","validation"],"backgroundTag":"empty-cli-option-value","analyzedSha":"f123cdb2a2d49f15025794166cfed8bda8627dd2","analyzedAt":"2026-08-23T01:20:58.058Z","schemaVersion":2},"datasetVersion":"2026-08-23T08:06:27.607Z"}