Mockery specifying expected arguments for multiple calls

淺唱寂寞╮ 提交于 2019-12-18 19:40:26

问题


I am trying to mock an object that gets two calls to the same function but with different arguments. It's pretty straight forward to give back different return values for multiple calls but I can't find anywhere how to do it with the argument validation.

I tried:

$this->eventDispatcher
    ->shouldReceive('dispatch')
    ->twice()
    ->with(Events::SELECT,\Mockery::type('\Not\Really\A\Namespace\Event'))
    ->with(Events::ACTIVITY,\Mockery::type('\Not\Really\A\Namespace\Event');

And

$this->eventDispatcher
        ->shouldReceive('dispatch')
        ->twice()
        ->with(
            [Events::SELECT,\Mockery::type('\Not\Really\A\Namespace\Event')],
            [Events::ACTIVITY,\Mockery::type('\Not\Really\A\Namespace\Event')]
        );

But they don't work.

From the output PHPUnit gives me it seems like I'm getting an array?


回答1:


Well that was fast ;P Apparently you can do this and it works just fine:

$this->eventDispatcher
    ->shouldReceive('dispatch')
    ->with(Events::SELECT,\Mockery::type('\Not\Really\A\Namespace\Event'));

$this->eventDispatcher
    ->shouldReceive('dispatch')
    ->with(Events::ACTIVITY,\Mockery::type('\Not\Really\A\Namespace\Event'); 


来源:https://stackoverflow.com/questions/26510007/mockery-specifying-expected-arguments-for-multiple-calls

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!