1 | <?php |
||
12 | class ContentContext extends RawDrupalContext implements SnippetAcceptingContext { |
||
13 | |||
14 | /** |
||
15 | * Assert viewing content given its type and title. |
||
16 | * |
||
17 | * @param string $type |
||
18 | * Content type machine name. |
||
19 | * @param string $title |
||
20 | * Content title. |
||
21 | * |
||
22 | * @Given I am visiting the :type content :title |
||
23 | * @Given I visit the :type content :title |
||
24 | */ |
||
25 | public function iAmViewingTheContent($type, $title) { |
||
28 | |||
29 | /** |
||
30 | * Assert editing content given its type and title. |
||
31 | * |
||
32 | * @param string $type |
||
33 | * Content type machine name. |
||
34 | * @param string $title |
||
35 | * Content title. |
||
36 | * |
||
37 | * @Given I am editing the :type content :title |
||
38 | * @Given I edit the :type content :title |
||
39 | */ |
||
40 | public function iAmEditingTheContent($type, $title) { |
||
43 | |||
44 | /** |
||
45 | * Assert deleting content given its type and title. |
||
46 | * |
||
47 | * @param string $type |
||
48 | * Content type machine name. |
||
49 | * @param string $title |
||
50 | * Content title. |
||
51 | * |
||
52 | * @Given I am deleting the :type content :title |
||
53 | * @Given I delete the :type content :title |
||
54 | */ |
||
55 | public function iAmDeletingTheContent($type, $title) { |
||
58 | |||
59 | /** |
||
60 | * Provides a common step definition callback for node pages. |
||
61 | * |
||
62 | * @param string $op |
||
63 | * The operation being performed: 'view', 'edit', 'delete'. |
||
64 | * @param string $type |
||
65 | * The node type either as id or as label. |
||
66 | * @param string $title |
||
67 | * The node title. |
||
68 | */ |
||
69 | protected function visitContentPage($op, $type, $title) { |
||
78 | |||
79 | } |
||
80 |
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: