| 1 | <?php |
||
| 16 | class DataValuesTestBase extends TestCase { |
||
| 17 | |||
| 18 | /** |
||
| 19 | * Creates and returns a new instance of the concrete class. |
||
| 20 | * |
||
| 21 | * @since 0.1 |
||
| 22 | * |
||
| 23 | * @return mixed |
||
| 24 | */ |
||
| 25 | public function newInstance() { |
||
| 31 | |||
| 32 | /** |
||
| 33 | * @since 0.1 |
||
| 34 | * |
||
| 35 | * @return array [instance, constructor args] |
||
| 36 | */ |
||
| 37 | public function instanceProvider() { |
||
| 50 | |||
| 51 | } |
||
| 52 |
Let’s take a look at an example:
In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different sub-classes of User which does not have a getDisplayName() method, the code will break.
Available Fixes
Change the type-hint for the parameter:
Add an additional type-check:
Add the method to the parent class: