Skip to content

Latest commit

 

History

History
50 lines (34 loc) · 1.06 KB

File metadata and controls

50 lines (34 loc) · 1.06 KB

Dependency Injection

Setup

NoExtension

Argument resolver is required for DI autowiring to work.

    # Allows DI in contexts (uses autowiring).
    Zalas\Behat\NoExtension:
      argument_resolver: true
      imports:
        - "./config/services.yml"

Services file

Set up your service like a regular symfony one. If you want to use Interfaces, you need to do some alias magic.

services:
  Brainsum\DrupalBehatTesting\DrupalExtension\Service\ExampleService: ~
  Brainsum\DrupalBehatTesting\DrupalExtension\Service\ExampleServiceInterface: '@Brainsum\DrupalBehatTesting\DrupalExtension\Service\ExampleService'

Context

Simply add the argument. Symfony DI autowiring takes care of the rest.

class ExampleContext {

  private $example;
  
  public function __construct(
    ExampleServiceInterface $example
  ) {
    $this->example = $example;
  }
  
}

Roadmap

  • It would be better if contexts could be set up as services, too.