diff --git a/features/injecting_services_into_context.feature b/features/injecting_services_into_context.feature new file mode 100644 index 0000000..f8b60c7 --- /dev/null +++ b/features/injecting_services_into_context.feature @@ -0,0 +1,65 @@ +Feature: Injecting services into context + + Background: + Given a working Symfony application with SymfonyExtension configured + And a Behat configuration containing: + """ + default: + suites: + default: + contexts: + - App\Tests\SomeContext + """ + And a feature file containing: + """ + Feature: + Scenario: + Then the passed service should be an instance of "\Psr\Container\ContainerInterface" + """ + And a context file "tests/SomeContext.php" containing: + """ + service = $service; } + + /** @Then the passed service should be an instance of :expected */ + public function serviceShouldBe(string $expected): void + { + assert(is_object($this->service)); + assert($this->service instanceof $expected); + } + } + """ + + Scenario: Injecting a service into a context explicitly set as public + Given a YAML services file containing: + """ + services: + App\Tests\SomeContext: + public: true + arguments: + - "@service_container" + """ + When I run Behat + Then it should pass + + Scenario: Injecting a service into an autoconfigured context + Given a YAML services file containing: + """ + services: + _defaults: + autoconfigure: true + + App\Tests\SomeContext: + arguments: + - "@service_container" + """ + When I run Behat + Then it should pass