{"record":{"id":"10529312fc2afd9f","repo":"sebastianbergmann/phpunit","slug":"options-s-and-s-cannot-be-used-together","errorCode":null,"errorMessage":"Options %s and %s cannot be used together","messagePattern":"Options (.+?) and (.+?) cannot be used together","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"src/TextUI/Configuration/Cli/Builder.php","lineNumber":1666,"sourceCode":"                    sprintf(\n                        'Options %s and %s cannot be used together',\n                        $conflictingOptions[0],\n                        $conflictingOptions[1],\n                    ),\n                );\n            }\n        }\n\n        $usedCommandOptions = [];\n\n        foreach (self::COMMAND_OPTIONS as $commandOption) {\n            if (isset($this->processed[$commandOption])) {\n                $usedCommandOptions[] = $commandOption;\n            }\n        }\n\n        if (count($usedCommandOptions) > 1) {\n            throw new Exception(\n                sprintf(\n                    'Options %s and %s cannot be used together',\n                    $usedCommandOptions[0],\n                    $usedCommandOptions[1],\n                ),\n            );\n        }\n    }\n\n    /**\n     * @return positive-int\n     */\n    private function parseStopOnValue(?string $value): int\n    {\n        if (is_numeric($value)) {\n            return max(1, (int) $value);\n        }\n","sourceCodeStart":1648,"sourceCodeEnd":1684,"githubUrl":"https://github.com/sebastianbergmann/phpunit/blob/f123cdb2a2d49f15025794166cfed8bda8627dd2/src/TextUI/Configuration/Cli/Builder.php#L1648-L1684","documentation":"Thrown by the CLI Builder when more than one of PHPUnit's mutually exclusive command options is used. COMMAND_OPTIONS (src/TextUI/Configuration/Cli/Builder.php:239) is: --atleast-version, --check-php-configuration, --check-version, --generate-configuration, --help, --list-groups, --list-suites, --list-test-files, --list-test-ids, --list-tests, --list-tests-xml, --migrate-configuration, --validate-configuration, --version, --warm-coverage-cache. Each makes PHPUnit execute a single command and exit instead of running tests, so at most one can be honored. Note the separate CONFLICTING_OPTIONS pairs (e.g. --repeat with --retry, --no-output with --testdox) only emit a warning; the hard exception is reserved for combining two COMMAND_OPTIONS.","triggerScenarios":"`vendor/bin/phpunit --migrate-configuration --validate-configuration`; `--list-tests --version`; `--generate-configuration --warm-coverage-cache`; wrapper scripts that concatenate flags (e.g. `phpunit $EXTRA_FLAGS $CMD`) where both variables expand to command options.","commonSituations":"CI pipelines that merge several maintenance invocations into one line; task-runner/IDE integrations that append their own flags to user-supplied ones; copy-pasted command lines that accumulate options over time.","solutions":["Split into separate PHPUnit invocations: `vendor/bin/phpunit --migrate-configuration && vendor/bin/phpunit --validate-configuration`","Echo or `bash -x` the expanded command to find which two command options are being combined","In wrappers, forward only the first command option and warn about any others"],"exampleFix":"# before\nvendor/bin/phpunit --migrate-configuration --validate-configuration\n\n# after\nvendor/bin/phpunit --migrate-configuration\nvendor/bin/phpunit --validate-configuration","handlingStrategy":"validation","validationCode":"const COMMAND_OPTIONS = [\n    '--atleast-version', '--check-php-configuration', '--check-version',\n    '--generate-configuration', '--help', '--list-groups', '--list-suites',\n    '--list-test-files', '--list-test-ids', '--list-tests', '--list-tests-xml',\n    '--migrate-configuration', '--validate-configuration', '--version',\n    '--warm-coverage-cache',\n];\n\n$used = array_values(array_intersect($argv, COMMAND_OPTIONS));\n\nif (count($used) > 1) {\n    fwrite(STDERR, 'Refusing to run: ' . implode(' and ', array_slice($used, 0, 2)) . ' cannot be combined' . PHP_EOL);\n    exit(2);\n}","typeGuard":null,"tryCatchPattern":"try {\n    (new \\PHPUnit\\TextUI\\CliArguments\\Builder)->fromParameters($argv);\n} catch (\\PHPUnit\\TextUI\\CliArguments\\Exception $e) {\n    if (str_contains($e->getMessage(), 'cannot be used together')) {\n        // split the run or drop one command option, then retry manually\n    }\n}","preventionTips":["Keep one command option per invocation in scripts; chain separate commands with && instead of merging flags","Audit CI wrappers that interpolate multiple flag variables into a single phpunit call","Remember pairs like --repeat/--retry only warn, but two COMMAND_OPTIONS hard-fail"],"tags":["phpunit","cli","mutually-exclusive-options","argument-parsing"],"backgroundTag":"mutually-exclusive-cli-options","analyzedSha":"f123cdb2a2d49f15025794166cfed8bda8627dd2","analyzedAt":"2026-08-23T01:20:58.058Z","schemaVersion":2},"datasetVersion":"2026-08-23T08:06:27.607Z"}