Tim*_*rst 11 php phpunit mocking symfony mockery
我试图模拟一个对象,该对象获得两个相同函数但具有不同参数的调用.为多个调用返回不同的返回值非常简单但我无法在任何地方找到如何使用参数验证来执行此操作.
我试过了:
$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');
Run Code Online (Sandbox Code Playgroud)
和
$this->eventDispatcher
->shouldReceive('dispatch')
->twice()
->with(
[Events::SELECT,\Mockery::type('\Not\Really\A\Namespace\Event')],
[Events::ACTIVITY,\Mockery::type('\Not\Really\A\Namespace\Event')]
);
Run Code Online (Sandbox Code Playgroud)
但他们不工作.
从输出PHPUnit给我看起来我似乎得到一个数组?
Tim*_*rst 16
嗯,这很快; 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');
Run Code Online (Sandbox Code Playgroud)