Skip to content

Method expects() on test doubles yields error with static analyzer #6156

Closed
@smpn2

Description

@smpn2
Q A
PHPUnit version 12.0.9
PHP version 8.4.4
Installation Method Composer

Summary

ref #6154

This piece of code works, but does not pass static analysis anymore.

$mockedService
    ->expects($this->exactly(1))
    ->method('get')
    ->with(24)
    ->willReturn('24');

phpstan report

> composer analyze
------ ---------------------------------------------------------------------------------------------------- 
  Line   test\MyServiceTest.php
 ------ ----------------------------------------------------------------------------------------------------
  :16    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
 ------ ----------------------------------------------------------------------------------------------------

Current behavior

Fail static analysis

How to reproduce

https://github.com/smpn2/phpunit-6156

Expected behavior

Metadata

Metadata

Assignees

No one assigned

    Labels

    type/bugSomething is broken

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions