1 | <?php |
||
46 | class RawTqContext extends RawPageContext implements TqContextInterface |
||
47 | { |
||
48 | use Debugger; |
||
49 | use Tags; |
||
50 | |||
51 | /** |
||
52 | * Parameters of TqExtension. |
||
53 | * |
||
54 | * @var array |
||
55 | */ |
||
56 | private $parameters = []; |
||
57 | /** |
||
58 | * @var string |
||
59 | */ |
||
60 | protected static $pageUrl = ''; |
||
61 | |||
62 | /** |
||
63 | * @param string $method |
||
64 | * @param array $arguments |
||
65 | * |
||
66 | * @throws \Exception |
||
67 | * @throws ContextNotFoundException |
||
68 | * When context class cannot be loaded. |
||
69 | * |
||
70 | * @return SnippetAcceptingContext |
||
71 | */ |
||
72 | public function __call($method, array $arguments) |
||
94 | |||
95 | /** |
||
96 | * Get selector by name. |
||
97 | * |
||
98 | * @param string $name |
||
99 | * Selector name from the configuration file. |
||
100 | * |
||
101 | * @return string |
||
102 | * CSS selector. |
||
103 | * |
||
104 | * @throws \Exception |
||
105 | * If selector does not exits. |
||
106 | */ |
||
107 | public function getDrupalSelector($name) |
||
117 | |||
118 | /** |
||
119 | * {@inheritdoc} |
||
120 | */ |
||
121 | public function getDrupalText($name) |
||
126 | |||
127 | /** |
||
128 | * @param string $site |
||
129 | * Drupal site folder. |
||
130 | * |
||
131 | * @return string |
||
132 | * URL to files directory. |
||
133 | */ |
||
134 | public function getFilesUrl($site = 'default') |
||
138 | |||
139 | /** |
||
140 | * @param string $text |
||
141 | * JS code for processing. |
||
142 | * |
||
143 | * @return self |
||
144 | */ |
||
145 | protected function processJavaScript(&$text) |
||
151 | |||
152 | /** |
||
153 | * @return Environment|InitializedContextEnvironment |
||
154 | */ |
||
155 | public function getEnvironment() |
||
159 | |||
160 | /** |
||
161 | * @return SessionDriverInterface|Selenium2Driver|GoutteDriver |
||
162 | */ |
||
163 | public function getSessionDriver() |
||
167 | |||
168 | /** |
||
169 | * @return Session |
||
170 | */ |
||
171 | public function getWebDriverSession() |
||
175 | |||
176 | /** |
||
177 | * @todo Remove this when DrupalExtension will be used Mink >=1.6 and use $this->getSession->getWindowNames(); |
||
178 | * |
||
179 | * @return string[] |
||
180 | */ |
||
181 | public function getWindowNames() |
||
185 | |||
186 | /** |
||
187 | * @param NodeElement $element |
||
188 | * @param string $script |
||
189 | * |
||
190 | * @example |
||
191 | * $this->executeJsOnElement($this->element('*', 'Meta tags'), 'return jQuery({{ELEMENT}}).text();'); |
||
192 | * $this->executeJsOnElement($this->element('*', '#menu'), '{{ELEMENT}}.focus();'); |
||
193 | * |
||
194 | * @throws \Exception |
||
195 | * |
||
196 | * @return mixed |
||
197 | */ |
||
198 | public function executeJsOnElement(NodeElement $element, $script) |
||
212 | |||
213 | /** |
||
214 | * @param string $javascript |
||
215 | * JS code for execution. |
||
216 | * @param array $args |
||
217 | * Placeholder declarations. |
||
218 | * |
||
219 | * @return mixed |
||
220 | */ |
||
221 | public function executeJs($javascript, array $args = []) |
||
230 | |||
231 | /** |
||
232 | * Check JS events in step definition. |
||
233 | * |
||
234 | * @param StepScope $event |
||
235 | * |
||
236 | * @return int |
||
237 | */ |
||
238 | public static function isStepImpliesJsEvent(StepScope $event) |
||
242 | |||
243 | /** |
||
244 | * @return DrupalDriverInterface|DrushDriver |
||
245 | */ |
||
246 | public function getDrushDriver() |
||
250 | |||
251 | /** |
||
252 | * Wait for all AJAX requests and jQuery animations. |
||
253 | */ |
||
254 | public function waitAjaxAndAnimations() |
||
262 | |||
263 | /** |
||
264 | * {@inheritdoc} |
||
265 | */ |
||
266 | public function setTqParameters(array $parameters) |
||
272 | |||
273 | /** |
||
274 | * {@inheritdoc} |
||
275 | */ |
||
276 | public function getTqParameter($name) |
||
280 | |||
281 | /** |
||
282 | * {@inheritdoc} |
||
283 | */ |
||
284 | public function locatePath($path = '') |
||
288 | |||
289 | /** |
||
290 | * @return string |
||
291 | * Absolute URL. |
||
292 | */ |
||
293 | public function getCurrentUrl() |
||
297 | } |
||
298 |
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: