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/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); + } } 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