1 | <?php |
||
15 | class GenericFeatureContext extends MinkContext |
||
16 | { |
||
17 | /** @var int UI generic delay duration in milliseconds */ |
||
18 | const DELAY = 1000; |
||
19 | /** @var 0.1 sec spin delay */ |
||
20 | const SPIN_DELAY = 100000; |
||
21 | /** @var int UI javascript generic delay duration in milliseconds */ |
||
22 | const JS_DELAY = self::DELAY / 5; |
||
23 | /** @var int UI spin function timeout for ex 30*0.1s = 15 sec timeout */ |
||
24 | const SPIN_TIMEOUT = 150; |
||
25 | |||
26 | /** @var mixed */ |
||
27 | protected $session; |
||
28 | |||
29 | /** |
||
30 | * Initializes context. |
||
31 | * |
||
32 | * Every scenario gets its own context instance. |
||
33 | * You can also pass arbitrary arguments to the |
||
34 | * context constructor through behat.yml. |
||
35 | * |
||
36 | * @param mixed $session |
||
37 | */ |
||
38 | public function __construct($session = null) |
||
44 | |||
45 | /** |
||
46 | * Get Symfony service instance. |
||
47 | * |
||
48 | * @param string $serviceName Service identifier |
||
49 | * @param string $session Behat Symfony session name |
||
50 | * |
||
51 | * @return object Symfony service instance |
||
52 | */ |
||
53 | public function getSymfonyService(string $serviceName, string $session = 'symfony2') |
||
61 | |||
62 | /** |
||
63 | * Spin function to avoid Selenium fails. |
||
64 | * |
||
65 | * @param callable $lambda |
||
66 | * @param null $data |
||
67 | * @param int $delay |
||
68 | * @param int $timeout |
||
69 | * |
||
70 | * @throws \Exception |
||
71 | * |
||
72 | * @return bool |
||
73 | */ |
||
74 | public function spin(callable $lambda, $data = null, $delay = self::SPIN_DELAY, $timeout = self::SPIN_TIMEOUT) |
||
97 | |||
98 | /** |
||
99 | * @AfterStep |
||
100 | * |
||
101 | * @param AfterStepScope $scope |
||
102 | */ |
||
103 | public function takeScreenShotAfterFailedStep(AfterStepScope $scope) |
||
117 | |||
118 | /** |
||
119 | * Find all elements by CSS selector. |
||
120 | * |
||
121 | * @param string $selector CSS selector |
||
122 | * |
||
123 | * @throws \InvalidArgumentException If element not found |
||
124 | * |
||
125 | * @return \Behat\Mink\Element\NodeElement[] |
||
126 | */ |
||
127 | protected function findAllByCssSelector(string $selector) |
||
147 | |||
148 | /** |
||
149 | * Find element by CSS selector. |
||
150 | * |
||
151 | * @param string $selector CSS selector |
||
152 | * |
||
153 | * @throws \InvalidArgumentException If element not found |
||
154 | * |
||
155 | * @return \Behat\Mink\Element\NodeElement |
||
156 | */ |
||
157 | public function findByCssSelector(string $selector) : NodeElement |
||
161 | |||
162 | /** |
||
163 | * @Given /^I set browser window size to "([^"]*)" x "([^"]*)"$/ |
||
164 | * |
||
165 | * @param int $width Browser window width |
||
166 | * @param int $height Browser window height |
||
167 | */ |
||
168 | public function iSetBrowserWindowSizeToX($width, $height) |
||
172 | |||
173 | /** |
||
174 | * @Given /^I wait "([^"]*)" milliseconds for response$/ |
||
175 | * |
||
176 | * @param int $delay Amount of milliseconds to wait |
||
177 | */ |
||
178 | public function iWaitMillisecondsForResponse($delay = self::DELAY) |
||
182 | |||
183 | /** |
||
184 | * Click on the element with the provided xpath query. |
||
185 | * |
||
186 | * @When I click on the element :arg1 |
||
187 | * |
||
188 | * @param string $selector CSS element selector |
||
189 | * |
||
190 | * @throws \InvalidArgumentException |
||
191 | */ |
||
192 | public function iClickOnTheElement(string $selector) |
||
197 | |||
198 | /** |
||
199 | * Checks, that current page PATH is equal to specified |
||
200 | * Example: Then I should be on "/" |
||
201 | * Example: And I should be on "/bats" |
||
202 | * Example: And I should be on "http://google.com" |
||
203 | * |
||
204 | * @param string $page Page for assertion |
||
205 | */ |
||
206 | public function assertPageAddress($page) { |
||
212 | |||
213 | /** |
||
214 | * @When /^I hover over the element "([^"]*)"$/ |
||
215 | * |
||
216 | * @param string $selector CSS element selector |
||
217 | * |
||
218 | * @throws \InvalidArgumentException |
||
219 | */ |
||
220 | public function iHoverOverTheElement(string $selector) |
||
224 | |||
225 | /** |
||
226 | * Fill in input with the provided info. |
||
227 | * |
||
228 | * @When I fill in the input :arg1 with :arg2 |
||
229 | * |
||
230 | * @param string $selector CSS element selector |
||
231 | * @param string $value Element value for filling in |
||
232 | * |
||
233 | * @throws \InvalidArgumentException |
||
234 | */ |
||
235 | public function iFillInTheElement(string $selector, string $value) |
||
239 | |||
240 | /** |
||
241 | * @When I scroll vertically to :arg1 px |
||
242 | * |
||
243 | * @param mixed $yPos Vertical scrolling position in pixels |
||
244 | */ |
||
245 | public function iScrollVerticallyToPx($yPos) |
||
249 | |||
250 | /** |
||
251 | * @When I scroll horizontally to :arg1 px |
||
252 | * |
||
253 | * @param mixed $xPos Horizontal scrolling position in pixels |
||
254 | */ |
||
255 | public function iScrollHorizontallyToPx($xPos) |
||
259 | |||
260 | /** |
||
261 | * @Given /^I fill hidden field "([^"]*)" with "([^"]*)"$/ |
||
262 | * |
||
263 | * @param string $field Field name |
||
264 | * @param string $value Field value |
||
265 | */ |
||
266 | public function iFillHiddenFieldWith(string $field, string $value) |
||
273 | |||
274 | /** |
||
275 | * @Then I check custom checkbox with :id |
||
276 | * |
||
277 | * @param string $id Checkbox identifier |
||
278 | * |
||
279 | * @throws \InvalidArgumentException If checkbox with provided identifier does not exists |
||
280 | */ |
||
281 | public function iCheckCustomCheckboxWith(string $id) |
||
294 | |||
295 | /** |
||
296 | * @Then I drag element :selector to :target |
||
297 | * |
||
298 | * @param string $selector Source element for dragging |
||
299 | * @param string $target Target element to drag to |
||
300 | * |
||
301 | * @throws \InvalidArgumentException |
||
302 | */ |
||
303 | public function dragElementTo(string $selector, string $target) |
||
309 | |||
310 | /** |
||
311 | * Fill in input with the provided info. |
||
312 | * |
||
313 | * @When I fill in the element :arg1 with value :arg2 using js |
||
314 | * |
||
315 | * @param string $selector CSS element selector |
||
316 | * @param string $value Element value for filling in |
||
317 | */ |
||
318 | public function iFillInTheElementUsingJs(string $selector, string $value) |
||
322 | } |
||
323 |
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: