Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compatibility issues with phpunit/php-code-coverage #10531

Closed
siganushka opened this issue Jan 8, 2024 · 4 comments
Closed

Compatibility issues with phpunit/php-code-coverage #10531

siganushka opened this issue Jan 8, 2024 · 4 comments

Comments

@siganushka
Copy link

siganushka commented Jan 8, 2024

nikic/[email protected] was released 11 hours ago, where the signature of PhpParser\Lexer\Emulative::__construct(array $options = []) was changed to PhpParser\Lexer\Emulative:__construct(?PhpVersion $phpVersion = null) and old signature used in Psalm\Internal\Provider::parseStatements method:

self::$lexer = new Emulative([
    'usedAttributes' => $attributes,
    'phpVersion' => $major_version . '.' . $minor_version,
]);

In PHP >= 8.0, since phpunit/[email protected] adds a dependency on nikic/[email protected] (such as when using phpunit/phpunit), if you depend on both nikic/php-parser and phpunit /php-code-coverage, the following error will be thrown:

Uncaught TypeError: PhpParser\Lexer\Emulative::__construct(): Argument #1 ($phpVersion) must be of type ?PhpParser\PhpVersion, array given, called in vendor/vimeo/psalm/src/Psalm/Internal/Provider/StatementsProvider.php on line 402 and defined in vendor/bin/.phpunit/phpunit-9.6-0/vendor/nikic/php-parser/lib/PhpParser/Lexer/Emulative.php:38

Please refer to:

https://github.com/vimeo/psalm/blob/b113f3ed0259fd6e212d87c3df80eec95a6abf19/src/Psalm/Internal/Provider/StatementsProvider.php#L400...L403

sebastianbergmann/php-code-coverage@e19555d

https://github.com/nikic/PHP-Parser/blob/master/UPGRADE-5.0.md#changes-to-the-lexer

https://github.com/siganushka/generic-bundle/actions/runs/7443079097/job/20247867853

Possible solutions

  1. Fix compatibility with nikic/[email protected] and add dependency on 5.0
"require": {
    "nikic/php-parser": "^4.18 || ^5.0",
}
  1. Declare in nikic/[email protected] that it conflicts with the specified version
"conflict": {
    "nikic/php-parser": ">=5.0",
}
@ireinhart
Copy link

Same her.

@orklah
Copy link
Collaborator

orklah commented Jan 9, 2024

Psalm could very well use php-parser 5.0 from now

Could you submit a PR?

@Slamdunk
Copy link
Contributor

There is currently no plan to backport this to v5: #10567 (comment)

@weirdan
Copy link
Collaborator

weirdan commented Feb 26, 2024

Yep. This will be supported in v6.

@weirdan weirdan closed this as completed Feb 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants