从PHPUnit中的提供程序传递数组作为参数,可以使用以下方法:
withConsecutive
方法:$mock = $this->createMock(MyClass::class);
$mock->expects($this->once())
->method('myMethod')
->withConsecutive(
[['param1', 'param2']]
);
with
方法和willReturn
方法:$mock = $this->createMock(MyClass::class);
$mock->method('myMethod')
->with(['param1', 'param2'])
->willReturn('result');
with
方法和will
方法:$mock = $this->createMock(MyClass::class);
$mock->method('myMethod')
->with($this->equalTo(['param1', 'param2']))
->will($this->returnValue('result'));
在这些示例中,myMethod
是一个接受数组参数的方法,param1
和param2
是数组中的元素。您可以根据需要替换这些参数和方法名称。
推荐的腾讯云相关产品:
这些产品都可以帮助您更好地满足您的业务需求,并且可以与PHPUnit和其他云计算平台无缝集成。
领取专属 10元无门槛券
手把手带您无忧上云