You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: README.md
+44-1
Original file line number
Diff line number
Diff line change
@@ -9,7 +9,7 @@
9
9
10
10
This extension provides following features:
11
11
12
-
*`createMock()`, `getMockForAbstractClass()` and `getMockFromWsdl()` methods return an intersection type of the mock object and the mocked class so that both methods from the mock object (like `expects`) and from the mocked class are available on the object.
12
+
*`createMock()`, `getMockForAbstractClass()` and `getMockFromWsdl()` methods return an intersection type (see the [detailed explanation of intersection types](https://medium.com/@ondrejmirtes/union-types-vs-intersection-types-fd44a8eacbb)) of the mock object and the mocked class so that both methods from the mock object (like `expects`) and from the mocked class are available on the object.
13
13
*`getMock()` called on `MockBuilder` is also supported.
14
14
* Interprets `Foo|PHPUnit_Framework_MockObject_MockObject` in phpDoc so that it results in an intersection type instead of a union type.
15
15
* Defines early terminating method calls for the `PHPUnit\Framework\TestCase` class to prevent undefined variable errors.
@@ -18,6 +18,49 @@ It also contains this framework-specific rule (can be enabled separately):
18
18
19
19
* Check that both values passed to `assertSame()` method are of the same type.
20
20
21
+
## How to document mock objects in phpDocs?
22
+
23
+
If you need to configure the mock even after you assign it to a property or return it from a method, you should add `PHPUnit_Framework_MockObject_MockObject` to the phpDoc:
Please note that the correct syntax for intersection types is `Foo&PHPUnit_Framework_MockObject_MockObject`. `Foo|PHPUnit_Framework_MockObject_MockObject` is also supported, but only for ecosystem and legacy reasons.
43
+
44
+
If the mock is fully configured and only the methods of the mocked class are supposed to be called on the value, it's fine to typehint only the mocked class:
0 commit comments