nikic / PHP-Parser

A PHP parser written in PHP
BSD 3-Clause "New" or "Revised" License
17.02k stars 1.1k forks source link

Fatal error when trying to run a code coverage report #1031

Open GiantCoder opened 1 week ago

GiantCoder commented 1 week ago

I'm running: root@b00c3eb5d255:/app# XDEBUG_MODE=coverage php bin/phpunit --coverage-html .

The error is: Testing PHP Fatal error: Declaration of PhpParser\ParserAbstract::parse(string $code, ?PhpParser\ErrorHandler $errorHandler = null) must be compatible with PhpParser\Parser::parse(string $code, ?PhpParser\ErrorHandler $errorHandler = null): ?array in /app/vendor/nikic/php-parser/lib/PhpParser/ParserAbstract.php on line 158

Relevant part of my composer.json: { "name": "phpstan/phpdoc-parser", "version": "1.32.0", "source": { "type": "git", "url": "https://github.com/phpstan/phpdoc-parser.git", "reference": "6ca22b154efdd9e3c68c56f5d94670920a1c19a4" }, "dist": { "type": "zip", "url": "https://api.github.com/repos/phpstan/phpdoc-parser/zipball/6ca22b154efdd9e3c68c56f5d94670920a1c19a4", "reference": "6ca22b154efdd9e3c68c56f5d94670920a1c19a4", "shasum": "" }, "require": { "php": "^7.2 || ^8.0" }, "require-dev": { "doctrine/annotations": "^2.0", "nikic/php-parser": "^4.15",

nikic commented 6 days ago

It looks like you end up mixing version 4.x and 5.x of PHP-Parser somehow. You have 4.x in your project and phpunit comes with it's own version -- how did you install phpunit? If it's a composer dependency things should be correctly resolved. If it's a phar, I'd expect it to be prefixed, but I'm not sure.