gpt4 book ai didi

php - 为多个调用指定预期参数的 mock

转载 作者:可可西里 更新时间:2023-10-31 22:44:30 27 4
gpt4 key购买 nike

我正在尝试模拟一个对象,该对象对同一个函数进行两次调用,但参数不同。为多次调用返回不同的返回值非常简单,但我无法在任何地方找到如何通过参数验证来做到这一点。

我试过:

$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');

关于php - 为多个调用指定预期参数的 mock ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26510007/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com