我正在尝试模拟一个对象,该对象对同一函数进行两次调用,但参数不同。为多个调用返回不同的返回值是非常直接的,但我在任何地方都找不到如何使用参数验证。
我试过了:
$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');
和
$this->eventDispatcher
->shouldReceive('dispatch')
->twice()
->with(
[Events::SELECT,'Mockery::type(''Not'Really'A'Namespace'Event')],
[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');