Skip to content

Commit 7e601e0

Browse files
wiesesebastianbergmann
authored andcommitted
test doubles: stubs: list available short hands
List the (convenience) short hands and their longer counterparts. IDEs should do a fine job suggesting those already, but having them show up on readthedocs would be great. Maybe it would make more sense to only mention the short hands after their long syntax is explained (as happens for quite a few of them in the paragraphs thereafter), but I placed the list of available short hands where it was explained for `willReturn($value)` so far. Long call syntax as seen in https://github.com/sebastianbergmann/phpunit-mock-objects/blob/0dfddc236629eb7ead4df2dfa3d79d548e011a3b/tests/MockObjectTest.php Resolves #20
1 parent 3a2bad4 commit 7e601e0

File tree

1 file changed

+26
-3
lines changed

1 file changed

+26
-3
lines changed

src/test-doubles.rst

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -182,9 +182,32 @@ the same best practice defaults used by ``createMock()``.
182182
}
183183
184184
In the examples so far we have been returning simple values using
185-
``willReturn($value)``. This short syntax is the same as
186-
``will($this->returnValue($value))``. We can use variations
187-
on this longer syntax to achieve more complex stubbing behaviour.
185+
``willReturn($value)`` – a short syntax for convenience. :numref:`test-doubles.stubs.shorthands` shows the
186+
available stubbing short hands alongside their longer counterparts.
187+
188+
.. rst-class:: table
189+
.. list-table:: Stubbing short hands
190+
:name: test-doubles.stubs.shorthands
191+
:header-rows: 1
192+
193+
* - short hand
194+
- longer syntax
195+
* - ``willReturn($value)``
196+
- ``will($this->returnValue($value))``
197+
* - ``willReturnArgument($argumentIndex)``
198+
- ``will($this->returnArgument($argumentIndex))``
199+
* - ``willReturnCallback($callback)``
200+
- ``will($this->returnCallback($callback))``
201+
* - ``willReturnMap($valueMap)``
202+
- ``will($this->returnValueMap($valueMap))``
203+
* - ``willReturnOnConsecutiveCalls($value1, $value2)``
204+
- ``will($this->onConsecutiveCalls($value1, $value2))``
205+
* - ``willReturnSelf()``
206+
- ``will($this->returnSelf())``
207+
* - ``willThrowException($exception)``
208+
- ``will($this->throwException($exception))``
209+
210+
We can use variations on this longer syntax to achieve more complex stubbing behaviour.
188211

189212
Sometimes you want to return one of the arguments of a method call
190213
(unchanged) as the result of a stubbed method call.

0 commit comments

Comments
 (0)