Active
Project:
Drupal Behat Testing
Version:
7.x-1.x-dev
Component:
Code
Priority:
Normal
Category:
Feature request
Assigned:
Reporter:
Created:
24 Feb 2013 at 13:05 UTC
Updated:
24 Feb 2013 at 13:05 UTC
I wonder if the fake traits in behat could be further extended? at the moment, if you want to access a method on another FeaturesContext you have to do something a little gnarly, for example, to run getSession() on the DrupalContext from your own FeaturesContext would look like this ...
$this->getMainContext()->getSession();
If we made the main context DrupalBootstrapContext, then made an abstract context class called DrupalContext which all additional FeaturesContexts added to Drupal extended we could add the following magic methods which would make all functions in the DrupalBootstrapContext become available via a simple call to $this->getSession();
abstract class DrupalContext extends BehatContext {
/**
* Magic method to call functions on DrupalContext.
*/
public function __call($name, $arguments) {
$main = $this->getMainContext();
if (method_exists($main, $name)) {
return call_user_func_array(array($main, $name), $arguments);
}
}
/**
* Magic method to get variables set on the main context.
*/
public function __get($name) {
$main = $this->getMainContext();
if (isset($main->$name)) {
return $main->$name;
}
}
}
Thoughts?