1 | <?php |
||
16 | class MenuContext extends RawDrupalContext { |
||
17 | |||
18 | |||
19 | /** |
||
20 | * Menu links created during test execution. |
||
21 | * |
||
22 | * @var \Drupal\menu_link_content\Entity\MenuLinkContent[] |
||
23 | */ |
||
24 | private $menuLinks = []; |
||
25 | |||
26 | /** |
||
27 | * Create menu structure for nodes. |
||
28 | * |
||
29 | * @param string $menu_name |
||
30 | * Menu machine name. |
||
31 | * @param \Behat\Gherkin\Node\TableNode $table |
||
32 | * Table representing the menu structure to be specified as follows: |
||
33 | * | title | parent | |
||
34 | * | Page 1 | | |
||
35 | * | Page 2 | Page 1 | |
||
36 | * | Page 3 | Page 2 |. |
||
37 | * |
||
38 | * @throws \Behat\Mink\Exception\ExpectationException |
||
39 | * Throws exception if menu not found. |
||
40 | * |
||
41 | * @Given the following :menu_name menu structure for content: |
||
42 | */ |
||
43 | public function assertMenuStructureForContent($menu_name, TableNode $table) { |
||
57 | |||
58 | /** |
||
59 | * Create menu structure my adding menu links. |
||
60 | * |
||
61 | * @param string $menu_name |
||
62 | * Menu machine name. |
||
63 | * @param \Behat\Gherkin\Node\TableNode $table |
||
64 | * Table representing the menu structure to be specified as follows: |
||
65 | * | title | uri | parent | |
||
66 | * | Link 1 | internal:/ | | |
||
67 | * | Link 2 | internal:/ | Link 1 | |
||
68 | * | Link 3 | internal:/ | Link 1 |. |
||
69 | * |
||
70 | * @throws \Behat\Mink\Exception\ExpectationException |
||
71 | * Throws exception if menu not found. |
||
72 | * |
||
73 | * @Given the following :menu_name menu structure: |
||
74 | */ |
||
75 | public function assertMenuStructure($menu_name, TableNode $table) { |
||
84 | |||
85 | /** |
||
86 | * Assert clean Watchdog after every step. |
||
87 | * |
||
88 | * @param \Behat\Behat\Hook\Scope\AfterScenarioScope $event |
||
89 | * Event object. |
||
90 | * |
||
91 | * @AfterScenario |
||
92 | */ |
||
93 | public function deleteMenuLinks(AfterScenarioScope $event) { |
||
102 | |||
103 | } |
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: