1 | <?php |
||
23 | class MailerTest extends TestCaseAbstract |
||
24 | { |
||
25 | /** |
||
26 | * setUp |
||
27 | * |
||
28 | * @since 3.1.0 |
||
29 | */ |
||
30 | |||
31 | public function setUp() : void |
||
43 | |||
44 | /** |
||
45 | * tearDown |
||
46 | * |
||
47 | * @since 3.1.0 |
||
48 | */ |
||
49 | |||
50 | public function tearDown() : void |
||
54 | |||
55 | /** |
||
56 | * testSend |
||
57 | * |
||
58 | * @since 2.2.0 |
||
59 | * |
||
60 | * @param array $toArray |
||
61 | * @param array $fromArray |
||
62 | * @param string $subject |
||
63 | * @param string|array $body |
||
64 | * |
||
65 | * @dataProvider providerAutoloader |
||
66 | */ |
||
67 | |||
68 | public function testSend(array $toArray = [], array $fromArray = [], string $subject = null, $body = null) : void |
||
83 | |||
84 | /** |
||
85 | * testSendAttachment |
||
86 | * |
||
87 | * @since 3.1.0 |
||
88 | * |
||
89 | * @param array $toArray |
||
90 | * @param array $fromArray |
||
91 | * @param string $subject |
||
92 | * @param string|array $body |
||
93 | * |
||
94 | * @requires OS Linux |
||
95 | * |
||
96 | * @dataProvider providerAutoloader |
||
97 | */ |
||
98 | |||
99 | public function testSendAttachment(array $toArray = [], array $fromArray = [], string $subject = null, $body = null) : void |
||
118 | } |
||
119 |
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 implementation 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 interface: