Skip to content

Extension doesn't work with phpstan 1.10 #170

Open
@garak

Description

@garak

After upgrading from phpstan 1.9 to 1.10, I started getting many errors like this:

Trying to mock an undefined method X on class Y".

Downgrading to 1.9 solves the problems, but I'd like to use the latest version.

The installed version of phpstan-phpunit is the current latest one (1.3.10)

Activity

ondrejmirtes

ondrejmirtes commented on Mar 5, 2023

@ondrejmirtes
Member

Does class Y have method X? Can you show more about the problem, the code?

garak

garak commented on Mar 5, 2023

@garak
Author

Does class Y have method X? Can you show more about the problem, the code?

Of course it does. As told above, everything runs fine with phpstan 1.9
This is the commit in which my build started failing, you can see some code there: dustin10/VichUploaderBundle@7ead900

ondrejmirtes

ondrejmirtes commented on Mar 6, 2023

@ondrejmirtes
Member

This is dg/bypass-finals problem again. Normally you can't mock final classes. PHPStan mostly doesn't play well with dg/bypass-finals.

garak

garak commented on Mar 6, 2023

@garak
Author

So I'm forced to stay on phpstan 1.9? :-(

ondrejmirtes

ondrejmirtes commented on Mar 6, 2023

@ondrejmirtes
Member

No. You have many options:

  1. Ignore this error with: https://phpstan.org/user-guide/ignoring-errors
  2. Stop mocking final classes (it's a bad hack), either by introducing an interface, or by making the class non-final.

Of course 1) is easier.

garak

garak commented on Mar 6, 2023

@garak
Author

I see.
So, probably this should be clarified in the docs. I can propose a PR, if you agree.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Extension doesn't work with phpstan 1.10 · Issue #170 · phpstan/phpstan-phpunit