PHPUnit “Mocked method does not exist.” when using $mock->expects($this->at(…))

前端 未结 7 1468
失恋的感觉
失恋的感觉 2021-02-05 00:56

I\'ve run into a strange issue with PHPUnit mock objects. I have a method that should be called twice, so I\'m using the \"at\" matcher. This works for the first time the method

7条回答
  •  鱼传尺愫
    2021-02-05 01:15

    FYI, Not sure if its related, but I encountered the same thing, but not with the $this->at() method, for me it was the $this->never() method.

    This raised the error

    $mock->expects($this->never())
        ->method('exists')
        ->with('arg');
    

    This fixed the error

    $mock->expects($this->never())
        ->method('exists');  
    

    It did the same thing when using the $this->exactly(0) method.

    Hope this help someone.

提交回复
热议问题