{"record":{"id":"50724d5a32335a5e","repo":"sebastianbergmann/phpunit","slug":"s-is-not-a-valid-version-compare-operator","errorCode":null,"errorMessage":"\"%s\" is not a valid version_compare() operator","messagePattern":"\"(.+?)\" is not a valid version_compare\\(\\) operator","errorType":"exception","errorClass":"PHPUnit\\Util\\InvalidVersionOperatorException","httpStatus":null,"severity":"error","filePath":"src/Util/VersionComparisonOperator.php","lineNumber":54,"sourceCode":"    }\n\n    /**\n     * @return '!='|'<'|'<='|'<>'|'='|'=='|'>'|'>='|'eq'|'ge'|'gt'|'le'|'lt'|'ne'\n     */\n    public function asString(): string\n    {\n        return $this->operator;\n    }\n\n    /**\n     * @param '!='|'<'|'<='|'<>'|'='|'=='|'>'|'>='|'eq'|'ge'|'gt'|'le'|'lt'|'ne' $operator\n     *\n     * @throws InvalidVersionOperatorException\n     */\n    private function ensureOperatorIsValid(string $operator): void\n    {\n        if (!in_array($operator, ['<', 'lt', '<=', 'le', '>', 'gt', '>=', 'ge', '==', '=', 'eq', '!=', '<>', 'ne'], true)) {\n            throw new InvalidVersionOperatorException($operator);\n        }\n    }\n}\n","sourceCodeStart":36,"sourceCodeEnd":58,"githubUrl":"https://github.com/sebastianbergmann/phpunit/blob/f123cdb2a2d49f15025794166cfed8bda8627dd2/src/Util/VersionComparisonOperator.php#L36-L58","documentation":"VersionComparisonOperator is the value object PHPUnit uses for version constraints (for example the phpVersionOperator attribute on <directory>/<file> nodes in phpunit.xml testsuites, or operators parsed from metadata requirements like #[RequiresPhp('>= 8.1')]). ensureOperatorIsValid() only accepts operators version_compare() understands: <, lt, <=, le, >, gt, >=, ge, ==, =, eq, !=, <>, ne. Anything else throws InvalidVersionOperatorException.","triggerScenarios":"Setting phpVersionOperator to an unsupported string on a <directory> or <file> node in phpunit.xml (e.g. '=>', '~', '===', 'gte'), or constructing VersionComparisonOperator directly with such a value.","commonSituations":"Assuming composer-style constraint syntax (^, ~) works in phpunit.xml; typos like '=<'; copying version logic from another tool's config into the testsuite attributes.","solutions":["Use one of the supported operators: '<', 'lt', '<=', 'le', '>', 'gt', '>=', 'ge', '==', '=', 'eq', '!=', '<>', 'ne'","For '>= 8.1' style requirements you can usually omit the operator entirely — PHPUnit defaults to '>=' when none is given","Remove composer-only operators such as ^ or ~; express them with explicit comparisons instead","If validating user-supplied constraints, check against the allowed list before passing them in"],"exampleFix":"<!-- before -->\n<testsuites>\n  <directory suffix=\"Test.php\" phpVersion=\"8.1\" phpVersionOperator=\"=>\">tests</directory>\n</testsuites>\n\n<!-- after -->\n<testsuites>\n  <directory suffix=\"Test.php\" phpVersion=\"8.1\" phpVersionOperator=\"&gt;=\">tests</directory>\n</testsuites>","handlingStrategy":"type-guard","validationCode":"$operator = $node->getAttribute('phpVersionOperator');\n$allowed = ['<','lt','<=','le','>','gt','>=','ge','==','=','eq','!=','<>','ne'];\nif (!in_array($operator, $allowed, true)) {\n    throw new InvalidArgumentException(\"Unsupported operator '{$operator}'\");\n}","typeGuard":"/** @param string $operator @phpstan-assert-if-true ='<'|'lt'|'<='|'le'|'>'|'gt'|'>='|'ge'|'=='|'='|'eq'|'!='|'<>'|'ne' */\nstatic function isValidVersionOperator(string $operator): bool\n{\n    return in_array($operator, ['<','lt','<=','le','>','gt','>=','ge','==','=','eq','!=','<>','ne'], true);\n}","tryCatchPattern":"use PHPUnit\\Util\\InvalidVersionOperatorException;\n\ntry {\n    $op = new VersionComparisonOperator($candidate);\n} catch (InvalidVersionOperatorException $e) {\n    // fall back to the default operator instead of failing the run\n    $op = new VersionComparisonOperator('>=');\n}","preventionTips":["Remember phpVersionOperator accepts only version_compare() operators — no composer ^ or ~ syntax","Omit the operator attribute entirely when '>=' is meant; it is the default","Validate operator strings in config linters/CI before PHPUnit loads the file"],"tags":["phpunit","xml-config","version-constraint","validation"],"backgroundTag":"invalid-version-constraint","analyzedSha":"f123cdb2a2d49f15025794166cfed8bda8627dd2","analyzedAt":"2026-08-23T01:20:58.058Z","schemaVersion":2},"datasetVersion":"2026-08-23T08:06:27.607Z"}