Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,10 @@
"psr-4": {
"Behat\\SoapExtension\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"Behat\\SoapExtension\\Context\\Bootstrap\\": "tests/bootstrap/"
}
}
}
8 changes: 8 additions & 0 deletions docs/behat.yml
Original file line number Diff line number Diff line change
@@ -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().
Expand Down
48 changes: 48 additions & 0 deletions docs/bootstrap/ExtendedSoapContext.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?php

namespace YourCompanyName\CustomFeatureContexts\Bootstrap;

use Behat\SoapExtension\Context\SoapContext;
use PHPUnit_Framework_Assert as Assertions;

/**
* Class ExtendedSoapContext
*
* Don't forget to add it to composer's autoload!
*
* @package YourCompanyName\CustomFeatureContexts\Bootstrap
*/
class ExtendedSoapContext extends SoapContext
{
/**
* @var string
*/
private $a;

/**
* @var string
*/
private $b;

/**
* SetUp necessary arguments for custom usage.
*
* @param array $args
*/
public function __construct(array $args)
{
$this->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);
}
}
10 changes: 10 additions & 0 deletions docs/features/custom_weather_ws.feature
Original file line number Diff line number Diff line change
@@ -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
21 changes: 18 additions & 3 deletions src/ServiceContainer/SoapExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -17,6 +18,8 @@
*/
class SoapExtension implements Extension
{
const SOAP_ID = 'soap.extension';

/**
* {@inheritdoc}
*/
Expand All @@ -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);
}

/**
Expand All @@ -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);
}
}
9 changes: 9 additions & 0 deletions tests/behat.yml
Original file line number Diff line number Diff line change
@@ -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().
Expand Down
41 changes: 41 additions & 0 deletions tests/bootstrap/ExtendedSoapContext.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php

namespace Behat\SoapExtension\Context\Bootstrap;

use Behat\SoapExtension\Context\SoapContext;
use PHPUnit_Framework_Assert as Assertions;

class ExtendedSoapContext extends SoapContext
{
/**
* @var string
*/
private $a;

/**
* @var string
*/
private $b;

/**
* SetUp necessary arguments for custom usage.
*
* @param array $args
*/
public function __construct(array $args)
{
$this->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);
}
}
10 changes: 10 additions & 0 deletions tests/features/extended.feature
Original file line number Diff line number Diff line change
@@ -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