PHPUnit 中`willReturn()` 和`will($this->returnValue())` 的区别?
Difference between `willReturn()` and `will($this->returnValue())` in PHPUnit?
在 PHPUnit 中,
之间有什么区别吗?
$mockFoo->method('methodName')->will($this->returnValue($mockBar));
和
$mockFoo->method('methodName')->willReturn($mockBar);
不,willReturn()
只是一个捷径。在它被引入之前,另一个变体是唯一的。现在这个简单的案例不需要它。
引用the manual:
This short syntax is the same as will($this->returnValue($value))
. We can use variations on this longer syntax to achieve more complex stubbing behaviour.
在 PHPUnit 中,
之间有什么区别吗?$mockFoo->method('methodName')->will($this->returnValue($mockBar));
和
$mockFoo->method('methodName')->willReturn($mockBar);
不,willReturn()
只是一个捷径。在它被引入之前,另一个变体是唯一的。现在这个简单的案例不需要它。
引用the manual:
This short syntax is the same as
will($this->returnValue($value))
. We can use variations on this longer syntax to achieve more complex stubbing behaviour.