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

PHPStan reports error in a bunch of places with PHPUnit 12.0.9 #6157

Closed
acelaya opened this issue Mar 20, 2025 · 2 comments
Closed

PHPStan reports error in a bunch of places with PHPUnit 12.0.9 #6157

acelaya opened this issue Mar 20, 2025 · 2 comments
Labels
type/bug Something is broken

Comments

@acelaya
Copy link

acelaya commented Mar 20, 2025

Q A
PHPUnit version 12.0.9
PHP version 8.4.3
Installation Method Composer

Summary

I just updated to PHPUnit 12.0.9 and PHPStan is reporting the same error hundreds of times, in every instance of $mockObject->expects(...)->method(...):

  37     Call to method method() on an unknown class PHPUnit\Framework\MockObject\Builder\InvocationMocker.  
         🪪  class.notFound                                                                                  
         💡 Learn more at https://phpstan.org/user-guide/discovering-symbols    

I see the PHPUnit\Framework\MockObject\Builder\InvocationMocker has been in fact removed in this version (I had a direct reference in one test that I had to change with PHPUnit\Framework\MockObject\InvocationStubber), so it seems there's still some reference to it somewhere.

Running the tests work though. It's just a static analysis issue.

Current behavior

Running PHPStan over the test code reports Call to method method() on an unknown class PHPUnit\Framework\MockObject\Builder\InvocationMocker in every place where a mock has been created with ->createMock() and then ->method() is called.

How to reproduce

Create a test where a mock is created and then some expectations are configured on it:

use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\Reorderable;

class MyTest extends TestCase
{
    public function testSomething(): void
    {
        // I randomly picked Reorderable because it's part of PHPUnit. Anything produces the same result
        $mock = $this->createMock(Reorderable::class); 
        $mock->expects($this->never())->method('sortId');
    }
}

Then run phpstan against this file:

vendor/bin/phpstan MyTest.php

 ------ ---------------------------------------------------------------------------------------------------- 
  Line   MyTest.php                                                           
 ------ ---------------------------------------------------------------------------------------------------- 
  10     Call to method method() on an unknown class PHPUnit\Framework\MockObject\Builder\InvocationMocker.  
         🪪  class.notFound                                                                                  
         💡 Learn more at https://phpstan.org/user-guide/discovering-symbols    
 ------ ---------------------------------------------------------------------------------------------------- 

Expected behavior

PHPStan should not report any error

@staabm
Copy link
Contributor

staabm commented Mar 20, 2025

I guess this is a duplicate of #6156

@acelaya
Copy link
Author

acelaya commented Mar 20, 2025

I guess this is a duplicate of #6156

Ugh, I saw that error and somehow thought it was a different thing without even opening it, but yes, it's the same. Sorry for the noise.

@acelaya acelaya closed this as completed Mar 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type/bug Something is broken
Projects
None yet
Development

No branches or pull requests

2 participants