From 742d3358b562b2e801638ed5c64f37d00abd3477 Mon Sep 17 00:00:00 2001 From: Bartosz Pietrzak Date: Wed, 9 Jan 2019 16:09:20 +0100 Subject: [PATCH] Injected parameter test POC --- .../injecting_parameters_into_context.feature | 44 +++++++++++++++++++ tests/Behat/Context/TestContext.php | 42 ++++++++++++++++++ 2 files changed, 86 insertions(+) create mode 100644 features/injecting_parameters_into_context.feature diff --git a/features/injecting_parameters_into_context.feature b/features/injecting_parameters_into_context.feature new file mode 100644 index 0000000..a1d1086 --- /dev/null +++ b/features/injecting_parameters_into_context.feature @@ -0,0 +1,44 @@ +Feature: Injecting parameters into context + + Background: + Given a context file "features/bootstrap/FeatureContext.php" containing: + """ + parameter = $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 injecting a parameter into the FeatureContext class + And a Behat configuration with the minimal working configuration for SymfonyExtension + And a Behat configuration with the minimal working configuration for MinkExtension + + + Scenario: Injecting parameters into context with SymfonyExtension + Given a feature file "features/injecting_parameter_into_context.feature" containing: + """ + Feature: Injecting parameter into the context + Scenario: + Then the parameter should be injected into the context + """ + When I run Behat + Then it should pass diff --git a/tests/Behat/Context/TestContext.php b/tests/Behat/Context/TestContext.php index 8dae841..4e72daf 100644 --- a/tests/Behat/Context/TestContext.php +++ b/tests/Behat/Context/TestContext.php @@ -157,6 +157,48 @@ CON ); } + /** + * @Given /^an application kernel injecting a parameter into the FeatureContext class$/ + */ + public function thereIsKernelInjectingParameterIntoFeatureContextClass(): void + { + $this->thereIsFile('app/AppKernel.php', <<<'CON' +load(function (ContainerBuilder $container): void { + $container->loadFromExtension('framework', [ + 'test' => $this->getEnvironment() === 'test', + 'secret' => 'Pigeon', + ]); + + $contextDefinition = new Definition(FeatureContext::class, [new Parameter('kernel.environment')]); + $contextDefinition->setAutoconfigured(true); + $container->setDefinition(FeatureContext::class, $contextDefinition); + }); + } +} +CON + ); + } + /** * @Given /^a feature file containing(?: "([^"]+)"|:)$/ */