1 | <?php |
||
11 | trait BrowserTrait |
||
12 | { |
||
13 | use AbstractTrait; |
||
14 | |||
15 | /** |
||
16 | * @param $method |
||
17 | * @param $url |
||
18 | * @param $post |
||
19 | * |
||
20 | * @throws \Codeception\Exception\ModuleException |
||
21 | */ |
||
22 | public function loadPage($method, $url, $post) |
||
26 | |||
27 | /** |
||
28 | * @return \Codeception\Module|PhpBrowser |
||
29 | * @throws \Codeception\Exception\ModuleException |
||
30 | */ |
||
31 | protected function getBrowserModule() |
||
35 | |||
36 | |||
37 | /** |
||
38 | * @param $name |
||
39 | * |
||
40 | * @return mixed |
||
41 | * @throws \Codeception\Exception\ModuleException |
||
42 | */ |
||
43 | public function getCurrentUriParam($name) |
||
51 | |||
52 | /** |
||
53 | * @return mixed |
||
54 | * @throws \Codeception\Exception\ModuleException |
||
55 | */ |
||
56 | public function getCurrentUri() |
||
60 | |||
61 | |||
62 | /** |
||
63 | * @return mixed |
||
64 | * @throws \Codeception\Exception\ModuleException |
||
65 | */ |
||
66 | public function getCurrentUrl() |
||
70 | |||
71 | |||
72 | /** |
||
73 | * @param $expected |
||
74 | * |
||
75 | * @throws \Codeception\Exception\ModuleException |
||
76 | */ |
||
77 | public function seeFullUrlEquals($expected) |
||
83 | } |
||
84 |
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: