Php 为多个调用指定预期参数的模拟
我试图模拟一个对象,该对象对同一个函数进行两次调用,但参数不同。为多个调用返回不同的返回值非常简单,但我找不到任何地方如何使用参数验证 我试过:Php 为多个调用指定预期参数的模拟,php,symfony,mocking,phpunit,mockery,Php,Symfony,Mocking,Phpunit,Mockery,我试图模拟一个对象,该对象对同一个函数进行两次调用,但参数不同。为多个调用返回不同的返回值非常简单,但我找不到任何地方如何使用参数验证 我试过: $this->eventDispatcher ->shouldReceive('dispatch') ->twice() ->with(Events::SELECT,\Mockery::type('\Not\Really\A\Namespace\Event')) ->with(Events:
$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');
及
但是它们不起作用
从PHPUnit给我的输出来看,好像我得到了一个数组?好吧,这很快;P显然你可以这样做,而且效果很好:
$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');
$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');