1 | <?php |
||
47 | class RawTqContext extends RawPageContext implements TqContextInterface |
||
48 | { |
||
49 | use JavaScript; |
||
50 | use Debugger; |
||
51 | use Tags; |
||
52 | |||
53 | /** |
||
54 | * Parameters of TqExtension. |
||
55 | * |
||
56 | * @var array |
||
57 | */ |
||
58 | private $parameters = []; |
||
59 | /** |
||
60 | * @var string |
||
61 | */ |
||
62 | protected static $pageUrl = ''; |
||
63 | |||
64 | /** |
||
65 | * @param string $method |
||
66 | * @param array $arguments |
||
67 | * |
||
68 | * @throws \Exception |
||
69 | * @throws ContextNotFoundException |
||
70 | * When context class cannot be loaded. |
||
71 | * |
||
72 | * @return SnippetAcceptingContext |
||
73 | */ |
||
74 | public function __call($method, array $arguments) |
||
96 | |||
97 | /** |
||
98 | * Get selector by name. |
||
99 | * |
||
100 | * @param string $name |
||
101 | * Selector name from the configuration file. |
||
102 | * |
||
103 | * @return string |
||
104 | * CSS selector. |
||
105 | * |
||
106 | * @throws \Exception |
||
107 | * If selector does not exits. |
||
108 | */ |
||
109 | public function getDrupalSelector($name) |
||
119 | |||
120 | /** |
||
121 | * {@inheritdoc} |
||
122 | */ |
||
123 | public function getDrupalText($name) |
||
128 | |||
129 | /** |
||
130 | * @param string $site |
||
131 | * Drupal site folder. |
||
132 | * |
||
133 | * @return string |
||
134 | * URL to files directory. |
||
135 | */ |
||
136 | public function getFilesUrl($site = 'default') |
||
140 | |||
141 | /** |
||
142 | * @return Environment|InitializedContextEnvironment |
||
143 | */ |
||
144 | public function getEnvironment() |
||
148 | |||
149 | /** |
||
150 | * @return SessionDriverInterface|Selenium2Driver|GoutteDriver |
||
151 | */ |
||
152 | public function getSessionDriver() |
||
156 | |||
157 | /** |
||
158 | * @return Session |
||
159 | */ |
||
160 | public function getWebDriverSession() |
||
164 | |||
165 | /** |
||
166 | * @todo Remove this when DrupalExtension will be used Mink >=1.6 and use $this->getSession->getWindowNames(); |
||
167 | * |
||
168 | * @return string[] |
||
169 | */ |
||
170 | public function getWindowNames() |
||
174 | |||
175 | /** |
||
176 | * @param NodeElement $element |
||
177 | * @param string $script |
||
178 | * |
||
179 | * @example |
||
180 | * $this->executeJsOnElement($this->element('*', 'Meta tags'), 'return jQuery({{ELEMENT}}).text();'); |
||
181 | * $this->executeJsOnElement($this->element('*', '#menu'), '{{ELEMENT}}.focus();'); |
||
182 | * |
||
183 | * @throws \Exception |
||
184 | * |
||
185 | * @return mixed |
||
186 | */ |
||
187 | public function executeJsOnElement(NodeElement $element, $script) |
||
200 | |||
201 | /** |
||
202 | * @param string $javascript |
||
203 | * JS code for execution. |
||
204 | * @param array $args |
||
205 | * Placeholder declarations. |
||
206 | * |
||
207 | * @return mixed |
||
208 | */ |
||
209 | public function executeJs($javascript, array $args = []) |
||
217 | |||
218 | /** |
||
219 | * Check JS events in step definition. |
||
220 | * |
||
221 | * @param StepScope $event |
||
222 | * |
||
223 | * @return int |
||
224 | */ |
||
225 | public static function isStepImpliesJsEvent(StepScope $event) |
||
229 | |||
230 | /** |
||
231 | * @return DrupalDriverInterface|DrushDriver |
||
232 | */ |
||
233 | public function getDrushDriver() |
||
237 | |||
238 | /** |
||
239 | * Wait for all AJAX requests and jQuery animations. |
||
240 | */ |
||
241 | public function waitAjaxAndAnimations() |
||
249 | |||
250 | /** |
||
251 | * {@inheritdoc} |
||
252 | */ |
||
253 | public function setTqParameters(array $parameters) |
||
259 | |||
260 | /** |
||
261 | * {@inheritdoc} |
||
262 | */ |
||
263 | public function getTqParameter($name) |
||
267 | |||
268 | /** |
||
269 | * {@inheritdoc} |
||
270 | */ |
||
271 | public function locatePath($path = '') |
||
275 | |||
276 | /** |
||
277 | * @return string |
||
278 | * Absolute URL. |
||
279 | */ |
||
280 | public function getCurrentUrl() |
||
284 | } |
||
285 |
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: