From 66eb10fa010de74617c6b3d3bc46eeb0bfb983f4 Mon Sep 17 00:00:00 2001 From: kolotaev Date: Mon, 12 Feb 2018 23:29:20 +0300 Subject: [PATCH 1/2] Load extension parameters via simple ContextInitializer instead of EnvironmentLoader. It allows us to extend SoapContext in custom FeatureContexts. Otherwise EnvironmentLoader always add SoapContext steps on every test thus causing potential steps duplication in SoapContext and its descendant classes. --- src/ServiceContainer/SoapExtension.php | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/src/ServiceContainer/SoapExtension.php b/src/ServiceContainer/SoapExtension.php index c60404b..15bafc1 100644 --- a/src/ServiceContainer/SoapExtension.php +++ b/src/ServiceContainer/SoapExtension.php @@ -4,11 +4,12 @@ */ namespace Behat\SoapExtension\ServiceContainer; -use Behat\EnvironmentLoader; use Behat\Testwork\ServiceContainer\Extension; use Behat\Testwork\ServiceContainer\ExtensionManager; +use Behat\Behat\Context\ServiceContainer\ContextExtension; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition; +use Symfony\Component\DependencyInjection\Definition; /** * Class SoapExtension. @@ -17,6 +18,8 @@ */ class SoapExtension implements Extension { + const SOAP_ID = 'soap.extension'; + /** * {@inheritdoc} */ @@ -37,8 +40,7 @@ public function initialize(ExtensionManager $extensionManager) */ public function load(ContainerBuilder $container, array $config) { - $loader = new EnvironmentLoader($this, $container, $config); - $loader->load(); + $this->loadContextInitializer($container, $config); } /** @@ -64,4 +66,17 @@ public function configure(ArrayNodeDefinition $builder) $config->end(); } + + /** + * Loads context initializer into given Container. + * + * @param ContainerBuilder $container + * @param array $config + */ + private function loadContextInitializer(ContainerBuilder $container, $config) + { + $definition = new Definition('Behat\SoapExtension\Context\SoapContextInitializer', array($config)); + $definition->addTag(ContextExtension::INITIALIZER_TAG); + $container->setDefinition('soap.context_initializer', $definition); + } } From a3df2e47e5a5090be8c0f2892f1b79f4c9d77a26 Mon Sep 17 00:00:00 2001 From: kolotaev Date: Fri, 16 Feb 2018 18:34:43 +0300 Subject: [PATCH 2/2] ContextInitializer instead of EnvironmentLoader tests --- composer.json | 5 +++ docs/behat.yml | 8 +++++ docs/bootstrap/ExtendedSoapContext.php | 48 +++++++++++++++++++++++++ docs/features/custom_weather_ws.feature | 10 ++++++ tests/behat.yml | 9 +++++ tests/bootstrap/ExtendedSoapContext.php | 41 +++++++++++++++++++++ tests/features/extended.feature | 10 ++++++ 7 files changed, 131 insertions(+) create mode 100644 docs/bootstrap/ExtendedSoapContext.php create mode 100644 docs/features/custom_weather_ws.feature create mode 100644 tests/bootstrap/ExtendedSoapContext.php create mode 100644 tests/features/extended.feature diff --git a/composer.json b/composer.json index 5d9b84b..8ca1112 100644 --- a/composer.json +++ b/composer.json @@ -25,5 +25,10 @@ "psr-4": { "Behat\\SoapExtension\\": "src/" } + }, + "autoload-dev": { + "psr-4": { + "Behat\\SoapExtension\\Context\\Bootstrap\\": "tests/bootstrap/" + } } } diff --git a/docs/behat.yml b/docs/behat.yml index 9c819b9..fbb3fbb 100644 --- a/docs/behat.yml +++ b/docs/behat.yml @@ -1,7 +1,15 @@ default: + autoload: + 'YourCompanyName\CustomFeatureContexts\Bootstrap': %paths.base%/docs/bootstrap suites: default: contexts: {} + custom: + contexts: + - YourCompanyName\CustomFeatureContexts\Bootstrap\ExtendedSoapContext: + args: + a: "Mountain View" + b: "Sunnyvale" extensions: Behat\SoapExtension: # An associative array as second argument for \SoapClient::__soapCall(). diff --git a/docs/bootstrap/ExtendedSoapContext.php b/docs/bootstrap/ExtendedSoapContext.php new file mode 100644 index 0000000..713fc46 --- /dev/null +++ b/docs/bootstrap/ExtendedSoapContext.php @@ -0,0 +1,48 @@ +a = $args['a']; + $this->b = $args['b']; + } + + /** + * @param string $c + * + * @Then /^I want to check that "(.*)" equals to A and not B$/ + */ + public function iCheckThatValueEqualsToANotB($c) + { + Assertions::assertEquals($this->a, $c); + Assertions::assertNotEquals($this->b, $c); + } +} diff --git a/docs/features/custom_weather_ws.feature b/docs/features/custom_weather_ws.feature new file mode 100644 index 0000000..d4b5273 --- /dev/null +++ b/docs/features/custom_weather_ws.feature @@ -0,0 +1,10 @@ +Feature: Simple test example + As a SOAP Extension user + I want to be able to use my own extended SOAPContext + So that I can add additional steps that work in conjunction with the basic SOAPContext functionality + + Scenario: WeatherWS SOAP and custom properties test with predefined A and B + Given I am working with SOAP service WSDL "http://wsf.cdyne.com/WeatherWS/Weather.asmx?WSDL" + And I call SOAP function "GetCityForecastByZIP" with params list: + | ZIP | 94040 | + And I want to check that "Mountain View" equals to A and not B diff --git a/tests/behat.yml b/tests/behat.yml index 9c819b9..360e5f3 100644 --- a/tests/behat.yml +++ b/tests/behat.yml @@ -1,7 +1,16 @@ default: + autoload: + 'Behat\SoapExtension\Context\Bootstrap': %paths.base%/tests/bootstrap suites: default: contexts: {} + extended: + contexts: + - Behat\SoapExtension\Context\Bootstrap\ExtendedSoapContext: + args: + a: "Mountain View" + b: "Sunnyvale" + extensions: Behat\SoapExtension: # An associative array as second argument for \SoapClient::__soapCall(). diff --git a/tests/bootstrap/ExtendedSoapContext.php b/tests/bootstrap/ExtendedSoapContext.php new file mode 100644 index 0000000..6df9c84 --- /dev/null +++ b/tests/bootstrap/ExtendedSoapContext.php @@ -0,0 +1,41 @@ +a = $args['a']; + $this->b = $args['b']; + } + + /** + * @param string $c + * + * @Then /^I want to check that "(.*)" equals to A and not B$/ + */ + public function iCheckThatValueEqualsToANotB($c) + { + Assertions::assertEquals($this->a, $c); + Assertions::assertNotEquals($this->b, $c); + } +} diff --git a/tests/features/extended.feature b/tests/features/extended.feature new file mode 100644 index 0000000..d4b5273 --- /dev/null +++ b/tests/features/extended.feature @@ -0,0 +1,10 @@ +Feature: Simple test example + As a SOAP Extension user + I want to be able to use my own extended SOAPContext + So that I can add additional steps that work in conjunction with the basic SOAPContext functionality + + Scenario: WeatherWS SOAP and custom properties test with predefined A and B + Given I am working with SOAP service WSDL "http://wsf.cdyne.com/WeatherWS/Weather.asmx?WSDL" + And I call SOAP function "GetCityForecastByZIP" with params list: + | ZIP | 94040 | + And I want to check that "Mountain View" equals to A and not B