From 13d64ca7cba6cf8f3d5daa770b599925f1fcae5a Mon Sep 17 00:00:00 2001 From: Kamil Kokot Date: Mon, 4 Mar 2019 13:32:09 +0100 Subject: [PATCH 1/2] Allow accessing a context in another context --- ...ssing_a_context_in_another_context.feature | 70 +++++++++++++++++++ ...InitializedSymfonyExtensionEnvironment.php | 4 +- 2 files changed, 73 insertions(+), 1 deletion(-) create mode 100644 features/sanity_checks/accessing_a_context_in_another_context.feature diff --git a/features/sanity_checks/accessing_a_context_in_another_context.feature b/features/sanity_checks/accessing_a_context_in_another_context.feature new file mode 100644 index 0000000..59cf842 --- /dev/null +++ b/features/sanity_checks/accessing_a_context_in_another_context.feature @@ -0,0 +1,70 @@ +Feature: Accessing a context in another context + + Scenario: Accessing a context in another context + Given a working Symfony application with SymfonyExtension configured + And a Behat configuration containing: + """ + default: + suites: + default: + contexts: + - App\Tests\SomeContext + - App\Tests\AnotherContext + """ + And a feature file containing: + """ + Feature: + Scenario: + Then it should pass + """ + And a context file "tests/SomeContext.php" containing: + """ + getEnvironment(); + + $this->someContext = $environment->getContext('App\Tests\SomeContext'); + } + + /** @Then it should pass */ + public function itShouldPass(): void + { + $this->someContext->someMethod(); + } + } + """ + And a YAML services file containing: + """ + services: + App\Tests\SomeContext: + public: true + + App\Tests\AnotherContext: + public: true + """ + When I run Behat + Then it should pass diff --git a/src/Context/Environment/InitializedSymfonyExtensionEnvironment.php b/src/Context/Environment/InitializedSymfonyExtensionEnvironment.php index b07da6e..6527899 100644 --- a/src/Context/Environment/InitializedSymfonyExtensionEnvironment.php +++ b/src/Context/Environment/InitializedSymfonyExtensionEnvironment.php @@ -72,9 +72,11 @@ final class InitializedSymfonyExtensionEnvironment implements SymfonyExtensionEn } /** + * @see http://behat.org/en/latest/cookbooks/accessing_contexts_from_each_other.html + * * @throws ContextNotFoundException */ - private function getContext(string $class): Context + public function getContext(string $class): Context { if (!isset($this->contexts[$class])) { throw new ContextNotFoundException(sprintf( From e06ac7d0ab3ac70201a9ad194602288a08738028 Mon Sep 17 00:00:00 2001 From: Kamil Kokot Date: Mon, 4 Mar 2019 14:13:37 +0100 Subject: [PATCH 2/2] Generate changelog for v2.0.4 and v2.0.5 --- CHANGELOG-2.0.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/CHANGELOG-2.0.md b/CHANGELOG-2.0.md index c32ceb4..00a5e8b 100644 --- a/CHANGELOG-2.0.md +++ b/CHANGELOG-2.0.md @@ -1,5 +1,13 @@ # CHANGELOG for `2.0.x` +## v2.0.5 (2019-03-04) + +- [#72](https://github.com/FriendsOfBehat/SymfonyExtension/issues/72) Allow accessing a context in another context ([@pamil](https://github.com/pamil)) + +## v2.0.4 (2019-02-13) + +- [#68](https://github.com/FriendsOfBehat/SymfonyExtension/issues/68) Better compatibility with Behat itself ([@pamil](https://github.com/pamil), [@alanpoulain](https://github.com/alanpoulain)) + ## v2.0.3 (2019-02-07) Removed the possibility to autoconfigure `$minkParameters` without a typehint due to an instable implementation in Symfony.