Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between `willReturn()` and `will($this->returnValue())` in PHPUnit?

Tags:

phpunit

In PHPUnit, is there any difference between

$mockFoo->method('methodName')->will($this->returnValue($mockBar));

and

$mockFoo->method('methodName')->willReturn($mockBar);

like image 383
eyecatchUp Avatar asked Nov 23 '15 10:11

eyecatchUp


1 Answers

No, willReturn() is just a shortcut. Before it was introduced, the other variation was the only one. Now you don't need it for this simple case.

To quote 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.

like image 182
Fabian Schmengler Avatar answered Sep 30 '22 16:09

Fabian Schmengler