3 namespace Drupal\DrupalExtension\Context\Initializer;
5 use Behat\Behat\Context\Initializer\ContextInitializer;
6 use Behat\Behat\Context\Context;
7 use Behat\Testwork\Hook\HookDispatcher;
9 use Drupal\DrupalDriverManager;
10 use Drupal\DrupalExtension\Context\DrupalContext;
11 use Drupal\DrupalExtension\Context\DrupalAwareInterface;
13 class DrupalAwareInitializer implements ContextInitializer {
14 private $drupal, $parameters, $dispatcher;
16 public function __construct(DrupalDriverManager $drupal, array $parameters, HookDispatcher $dispatcher) {
17 $this->drupal = $drupal;
18 $this->parameters = $parameters;
19 $this->dispatcher = $dispatcher;
25 public function initializeContext(Context $context) {
27 // All contexts are passed here, only DrupalAwareInterface is allowed.
28 if (!$context instanceof DrupalAwareInterface) {
32 // Set Drupal driver manager.
33 $context->setDrupal($this->drupal);
35 // Set event dispatcher.
36 $context->setDispatcher($this->dispatcher);
38 // Add all parameters to the context.
39 $context->setDrupalParameters($this->parameters);