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

Add support for PHPUnit 12.0.9 #222

Open
VincentLanglet opened this issue Mar 19, 2025 · 4 comments
Open

Add support for PHPUnit 12.0.9 #222

VincentLanglet opened this issue Mar 19, 2025 · 4 comments

Comments

@VincentLanglet
Copy link
Contributor

VincentLanglet commented Mar 19, 2025

See sebastianbergmann/phpunit#6156 (comment)

In 12.0.9 PHPUnit removed the InvocationMocker classes, the PR is sebastianbergmann/phpunit@fb4df53

Current references are

I feel like PHPUnit\Framework\MockObject\Builder\InvocationMocker was basically replaced by PHPUnit\Framework\MockObject\InvocationStubberImplementation

Currently don't know if it will require a StubFilesExtensionLoader like this one
https://github.com/phpstan/phpstan-doctrine/blob/2.0.x/src/Stubs/Doctrine/StubFilesExtensionLoader.php
or if a there is a better strategy.

One first step would be to test this lib with phpunit 10/11 (and 12) but it's currently forbidden by the hardcoded php config

"phpunit/phpunit": "^9.6"
},
"config": {
"platform": {
"php": "7.4.6"
},

@sebastianbergmann
Copy link

I also remember talking to Ondrej and/or Markus last year about whether the stubs in phpstan-phpunit are still needed. Ideally, this part of this extension can just be removed.

@VincentLanglet
Copy link
Contributor Author

I also remember talking to Ondrej and/or Markus last year about whether the stubs in phpstan-phpunit are still needed. Ideally, this part of this extension can just be removed.

I assume that some of this code might be conditionally removed for recent version of phpunit but not all of them.

For instance the MockMethodCallRule is made to report code like

$this->createMock(Bar::class)->method('nonExistingMethod');

Those file were introduced in #72,

  • MockMethodCallRule for the rule
  • InvocationMocker.stub in order to add @template TMockedClass in order to keep trace of the original class mocked
  • MockObjectDynamicReturnTypeExtension to tell phpstan that MockObject&Foo::expects will returns InvocationMocker<Foo>.
  • InvocationMockerDynamicReturnTypeExtension to tell phpstan that InvocationMocker methods are returning the same object with the same generic. => Maybe not needed anymore since most of method are annotated with @return $this ?

@sebastianbergmann
Copy link

Maybe not needed anymore since most of method are annotated with @return $this?

I just found one more method (see sebastianbergmann/phpunit@4b7f2a8) that is part of the public API for configuring test doubles which was missing @return $this. So hopefully with the next release, PHPUnit 12.0.10, all relevant methods will have this.

@SamMousa
Copy link

I can confirm that without the extension PHPStan works fine for the mocks.

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

3 participants