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