From 9cede4d612cdf7ab77faff98b5c40badc67950ca Mon Sep 17 00:00:00 2001 From: Kamil Kokot Date: Wed, 9 Jan 2019 22:40:32 +0100 Subject: [PATCH] Test injecting services --- .../injecting_services_into_context.feature | 65 +++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 features/injecting_services_into_context.feature 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