drupalextension
drupalextension copied to clipboard
Always bootstrap the API driver
I was writing a subcontext, and got containerNotInitializedException when I wanted to call \Drupal::logger().
Because I know the extension well, it wasn't that hard for me to to track the jungle and figure out that I need to call $this->getDriver() to bootstrap Drupal. But for an innocent developer just wanting to write their own context, that's not easy to discern.
Can we bootstrap Drupal always if a feature is tagged @api?
Lightning use this in their subcontexts and add it to every step function that needs it:
/**
* Ensures the Drupal driver is bootstrapped.
*
* @throws \RuntimeException
* If the Drupal driver is not bootstrapped.
*/
protected function ensureBootstrap() {
if ($this->getDriver()->isBootstrapped() == FALSE) {
throw new \RuntimeException('Drupal is not bootstrapped.');
}
}
Note that #487 is related to early bootstrapping. I've opened #518 for discussion.