1 | <?php |
||
12 | class FixtureContext extends BaseFixtureContext |
||
13 | { |
||
14 | |||
15 | /** |
||
16 | * Select a gallery item by type and name |
||
17 | * |
||
18 | * @Given /^I (?:(?:click on)|(?:select)) the "([^"]+)" named "([^"]+)" in the gallery$/ |
||
19 | * @param string $type |
||
20 | * @param string $name |
||
21 | */ |
||
22 | public function stepISelectGalleryItem($type, $name) |
||
28 | |||
29 | /** |
||
30 | * Check the checkbox for a given gallery item |
||
31 | * @Given /^I check the "([^"]+)" named "([^"]+)" in the gallery$/ |
||
32 | * @param string $type |
||
33 | * @param string $name |
||
34 | */ |
||
35 | public function stepICheckTheGalleryItem($type, $name) |
||
43 | |||
44 | /** |
||
45 | * @Then /^I should see the "([^"]+)" named "([^"]+)" in the gallery$/ |
||
46 | * @param $type |
||
47 | * @param $name |
||
48 | */ |
||
49 | public function iShouldSeeTheGalleryItem($type, $name) |
||
54 | |||
55 | /** |
||
56 | * @Then /^I should not see the "([^"]+)" named "([^"]+)" in the gallery$/ |
||
57 | * @param $type |
||
58 | * @param $name |
||
59 | */ |
||
60 | public function iShouldNotSeeTheGalleryItem($type, $name) |
||
65 | |||
66 | /** |
||
67 | * @Then /^I should see the "([^"]*)" form$/ |
||
68 | * @param string $id HTML ID of form |
||
69 | */ |
||
70 | public function iShouldSeeTheForm($id) |
||
80 | |||
81 | /** |
||
82 | * @Given /^I click on the latest history item$/ |
||
83 | */ |
||
84 | public function iClickOnTheLatestHistoryItem() |
||
101 | |||
102 | /** |
||
103 | * @Given /^I attach the file "([^"]*)" to dropzone$/ |
||
104 | * @see MinkContext::attachFileToField() |
||
105 | */ |
||
106 | public function iAttachTheFileToDropzone($path) |
||
144 | |||
145 | /** |
||
146 | * Helper for finding items in the visible gallery view |
||
147 | * |
||
148 | * @param string $type type. E.g. 'folder', 'image' |
||
149 | * @param string $name Title of item |
||
150 | * @param int $timeout |
||
151 | * @return NodeElement |
||
152 | */ |
||
153 | protected function getGalleryItem($type, $name, $timeout = 3) |
||
164 | |||
165 | /** |
||
166 | * Invoke $try callback for a non-empty result with a given timeout |
||
167 | * |
||
168 | * @param callable $try |
||
169 | * @param int $timeout Number of seconds to retry for |
||
170 | * @return mixed Result of invoking $try, or null if timed out |
||
171 | */ |
||
172 | protected function retry($try, $timeout = 3) |
||
183 | } |
||
184 |
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: