1 | <?php |
||
13 | class ExtensionsCommandTest extends AbstractCommandTest |
||
14 | { |
||
15 | /** |
||
16 | * {@inheritDoc} |
||
17 | */ |
||
18 | public function getTestCommand() |
||
22 | |||
23 | /** |
||
24 | * Ensure that the Injector's class resolution is returned for a given Object |
||
25 | * |
||
26 | * @covers ::execute |
||
27 | */ |
||
28 | public function testExecute() |
||
41 | |||
42 | /** |
||
43 | * Ensure that the InputArgument for the object is added |
||
44 | * |
||
45 | * @covers ::configure |
||
46 | */ |
||
47 | public function testConfigure() |
||
51 | |||
52 | /** |
||
53 | * Ensure that extra headers are added for CMS pages |
||
54 | * |
||
55 | * @covers ::getHeaders |
||
56 | * @dataProvider headerProvider |
||
57 | * |
||
58 | * @param bool $isCms |
||
59 | * @param string[] $expected |
||
60 | */ |
||
61 | public function testGetHeaders($isCms, $expected) |
||
65 | |||
66 | /** |
||
67 | * @return string[] |
||
68 | */ |
||
69 | public function headerProvider() |
||
76 | |||
77 | /** |
||
78 | * Ensure that extra headers are added for CMS pages |
||
79 | * |
||
80 | * @covers ::getRows |
||
81 | * @dataProvider rowsProvider |
||
82 | * |
||
83 | * @param bool $isCms |
||
84 | * @param array $extensions |
||
85 | * @param string[] $expected |
||
86 | */ |
||
87 | public function testGetRows($isCms, $extensions, $expected) |
||
91 | |||
92 | /** |
||
93 | * @return array[] |
||
94 | */ |
||
95 | public function rowsProvider() |
||
114 | } |
||
115 |
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: