diff --git a/features/injecting_parameters_into_context.feature b/features/injecting_parameters_into_context.feature index a18e2f6..2d7d67c 100644 --- a/features/injecting_parameters_into_context.feature +++ b/features/injecting_parameters_into_context.feature @@ -2,52 +2,60 @@ Feature: Injecting parameters into context Background: Given a working Symfony application with SymfonyExtension configured - Given a context file "features/bootstrap/FeatureContext.php" containing: - """ - parameter = $parameter; - } + final class SomeContext implements Context { + private $parameter; - /** - * @Then the parameter should be injected into the context - */ - public function behatContainerShouldBeInjectedToTheContext() - { - if (null === $this->parameter || empty($this->parameter)) { - throw new \DomainException('Required parameter was not injected!'); - } - } - } - """ - And an application kernel configured for SymfonyExtension with YAML services file containing: + public function __construct(?string $parameter = null) { $this->parameter = $parameter; } + + /** @Then the passed parameter should be :expected */ + public function parameterShouldBe(string $expected): void { assert($this->parameter === $expected); } + } + """ + + Scenario: Injecting a parameter into a context explicitly set as public + Given a services file "config/services.yaml" containing: """ services: - FeatureContext: - class: FeatureContext + App\Tests\SomeContext: public: true arguments: - "%kernel.environment%" """ - And a Behat configuration with the minimal working configuration for SymfonyExtension - And a Behat configuration with the minimal working configuration for MinkExtension + When I run Behat + Then it should pass - - Scenario: Injecting parameters into context with SymfonyExtension - Given a feature file "features/injecting_parameter_into_context.feature" containing: + Scenario: Injecting a parameter into an autoconfigured context + Given a services file "config/services.yaml" containing: """ - Feature: Injecting parameter into the context - Scenario: - Then the parameter should be injected into the context + services: + _defaults: + autoconfigure: true + + App\Tests\SomeContext: + arguments: + - "%kernel.environment%" """ When I run Behat Then it should pass