1 | <?php |
||
14 | class BaseMenu implements ConfigurableNavigatorInterface |
||
15 | { |
||
16 | const NAVIGATOR = 'BaseMenu'; |
||
17 | protected $webdriver; |
||
18 | protected $themeConfiguration; |
||
19 | protected $loaded; |
||
20 | protected $logger; |
||
21 | |||
22 | public function __construct( |
||
34 | |||
35 | protected function pathAction($path, &$xpath) |
||
36 | { |
||
37 | |||
38 | usleep(500000); // Give the UI some time to update |
||
39 | $xpath .= '/descendant::' . $this->themeConfiguration->getNavigationChildXPathSelector($path); |
||
40 | |||
41 | $element = $this->webdriver->byXpath($xpath . '/a'); |
||
42 | |||
43 | $this->execute($element); |
||
44 | |||
45 | return $element; |
||
46 | } |
||
47 | |||
48 | protected function execute(WebDriverElement $element) |
||
49 | { |
||
50 | $this->webdriver->getMouse()->mouseMove($element->getCoordinates()); |
||
|
|||
51 | if ($this->themeConfiguration->getUseClicksToNavigate()) { |
||
52 | $this->webdriver->getMouse()->click(); |
||
53 | } |
||
54 | } |
||
55 | |||
56 | public function navigateTo($path) |
||
76 | |||
77 | } |
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: