| 1 | <?php |
||
| 13 | trait ErrorHandler |
||
| 14 | { |
||
| 15 | /** |
||
| 16 | * @var mixed[] |
||
| 17 | */ |
||
| 18 | private $errors; |
||
| 19 | |||
| 20 | /** |
||
| 21 | * Assert that the requested error was generated. |
||
| 22 | * |
||
| 23 | * @param string $errstr |
||
| 24 | * @param int $errno |
||
| 25 | */ |
||
| 26 | 8 | public function assertError(string $errstr, int $errno) |
|
| 37 | |||
| 38 | /** |
||
| 39 | * Assert that no errors were generated. |
||
| 40 | */ |
||
| 41 | 2 | public function assertNoErrors() |
|
| 52 | |||
| 53 | /** |
||
| 54 | * Activate PHPUnit error handler. |
||
| 55 | * |
||
| 56 | * @before |
||
| 57 | */ |
||
| 58 | 10 | protected function setUpErrorHandler() |
|
| 74 | } |
||
| 75 |
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.