php – Mockery指定多个调用的预期参数
发布时间:2020-12-13 18:15:33 所属栏目:PHP教程 来源:网络整理
导读:我试图模拟一个对象,该对象获得两个相同函数但具有不同参数的调用.为多个调用返回不同的返回值非常简单但我无法在任何地方找到如何使用参数验证来执行此操作. 我试过了: $this-eventDispatcher -shouldReceive('dispatch') -twice() -with(Events::SELECT,
我试图模拟一个对象,该对象获得两个相同函数但具有不同参数的调用.为多个调用返回不同的返回值非常简单但我无法在任何地方找到如何使用参数验证来执行此操作.
我试过了: $this->eventDispatcher ->shouldReceive('dispatch') ->twice() ->with(Events::SELECT,Mockery::type('NotReallyANamespaceEvent')) ->with(Events::ACTIVITY,Mockery::type('NotReallyANamespaceEvent'); 和 $this->eventDispatcher ->shouldReceive('dispatch') ->twice() ->with( [Events::SELECT,Mockery::type('NotReallyANamespaceEvent')],[Events::ACTIVITY,Mockery::type('NotReallyANamespaceEvent')] ); 但它们不起作用. 从输出PHPUnit给我看起来我似乎得到一个数组?
嗯,这很快; P显然你可以这样做,它工作得很好:
$this->eventDispatcher ->shouldReceive('dispatch') ->with(Events::SELECT,Mockery::type('NotReallyANamespaceEvent')); $this->eventDispatcher ->shouldReceive('dispatch') ->with(Events::ACTIVITY,Mockery::type('NotReallyANamespaceEvent'); (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |