| 1 | <?php |
||
| 18 | trait StubTrait |
||
| 19 | { |
||
| 20 | /** |
||
| 21 | * Will create a stub with several methods and defined return values. |
||
| 22 | * definition: |
||
| 23 | * [ |
||
| 24 | * 'myMethod' => 'somevalue', |
||
| 25 | * 'myOtherMethod' => $callback, |
||
| 26 | * 'anotherMethod' => function ($x) use ($y) {}, |
||
| 27 | * ] |
||
| 28 | * |
||
| 29 | * @param string $class |
||
| 30 | * @param array $methods |
||
| 31 | * @param string $className classname for mock object |
||
| 32 | * @param bool $forceMethods |
||
| 33 | * @return \PHPUnit_Framework_MockObject_MockObject |
||
| 34 | */ |
||
| 35 | protected function stub($class, array $methods = [], $className = '', $forceMethods = false) |
||
| 59 | } |
||
| 60 |
This check looks for methods that are used by a trait but not required by it.
To illustrate, let’s look at the following code example
The trait
Idableprovides a methodequalsIdthat in turn relies on the methodgetId(). If this method does not exist on a class mixing in this trait, the method will fail.Adding the
getId()as an abstract method to the trait will make sure it is available.