PHPUnit:期望方法含义
当我创建一个新的模拟时,我需要调用expects方法。它到底有什么作用?它的论据又如何呢?
$todoListMock = $this->getMock('\Model\Todo_List');
$todoListMock->expects($this->any())
->method('getItems')
->will($this->returnValue(array($itemMock)));
我在任何地方都找不到原因(我已经尝试过文档)。我已经阅读了来源,但我无法理解。
When I create a new mock I need to call the expects method. What exactly it does? What about its arguments?
$todoListMock = $this->getMock('\Model\Todo_List');
$todoListMock->expects($this->any())
->method('getItems')
->will($this->returnValue(array($itemMock)));
I can't find the reason anywhere (I've tried docs). I've read the sources but I can't understand it.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
参见:
具有多个 Expects() 调用的 PHPUnit 模拟
https://phpunit.de/manual/current/en/test-doubles.html#test-doubles.stubs
http://www.slideshare.net/mjlivelyjr/advanced-phpunit-testing
see:
PHPUnit mock with multiple expects() calls
https://phpunit.de/manual/current/en/test-doubles.html#test-doubles.stubs
http://www.slideshare.net/mjlivelyjr/advanced-phpunit-testing
查看源代码会告诉您:
PHPUnit 手册在
A look into the source code will tell you:
And the PHPUnit Manual lists the available Matchers at