【发布时间】:2014-05-05 13:43:52
【问题描述】:
有没有办法为多个匹配断言模拟类方法字符串参数?
$this->getMock()
->expects($this->any())
->method('setString')
->with($this->stringContains('word3'))
->will($this->returnSelf());
这个例子将通过 ->setString('word1 word2 word3 word4')
我需要做的是匹配是否使用包含“word1”和“word3”的参数调用 setString()
但是
$this->getMock()
->expects($this->any())
->method('setString')
->with(
$this->stringContains('word1'),
$this->stringContains('word3')
)
->will($this->returnSelf());
这个实现正在检查 setString() 的 2 个参数,这不是我想要检查的。
想法?使用 $this->callback() ?有没有更适合的 PHPUnit 断言?
【问题讨论】:
标签: php unit-testing phpunit