| layout | title |
|---|---|
doc |
SOAP - Codeception - Documentation |
If you use Codeception installed using composer, install this module with the following command:
{% highlight yaml %} composer require --dev codeception/module-soap
{% endhighlight %}
Alternatively, you can enable SOAP module in suite configuration file and run
{% highlight yaml %} codecept init upgrade4
{% endhighlight %}
This module was bundled with Codeception 2 and 3, but since version 4 it is necessary to install it separately.
Some modules are bundled with PHAR files.
Warning. Using PHAR file and composer in the same project can cause unexpected errors.
Module for testing SOAP WSDL web services. Send requests and check if response matches the pattern.
This module can be used either with frameworks or PHPBrowser. It tries to guess the framework is is attached to. If a endpoint is a full url then it uses PHPBrowser.
Please note, that PHP SoapServer::handle method sends additional headers. This may trigger warning: "Cannot modify header information" If you use PHP SoapServer with framework, try to block call to this method in testing environment.
- Maintainer: davert
- Stability: stable
- Contact: [email protected]
- endpoint required - soap wsdl endpoint
- SOAPAction - replace SOAPAction HTTP header (Set to '' to SOAP 1.2)
- xmlRequest - last SOAP request (DOMDocument)
- xmlResponse - last SOAP response (DOMDocument)
Opposite to seeSoapResponseContainsStructure
param$xml
Checks XML response doesn't contain XPath locator
{% highlight php %}
dontSeeSoapResponseContainsXPath('//root/user[@id=1]'); ?>{% endhighlight %}
param$xpath
Checks XML response equals provided XML. Comparison is done by canonicalizing both xml`s.
Parameter can be passed either as XmlBuilder, DOMDocument, DOMNode, XML string, or array (if no attributes).
param$xml
Checks XML response does not include provided XML. Comparison is done by canonicalizing both xml`s. Parameter can be passed either as XmlBuilder, DOMDocument, DOMNode, XML string, or array (if no attributes).
param$xml
Finds and returns attribute of element. Element is matched by either CSS or XPath
Available since1.1param$cssOrXPathparam$attributereturnstring
Finds and returns text contents of element. Element is matched by either CSS or XPath
Available since1.1param$cssOrXPathreturnstring
Prepare SOAP header. Receives header name and parameters as array.
Example:
{% highlight php %}
haveSoapHeader('AuthHeader', array('username' => 'davert', 'password' => '123345')); {% endhighlight %} Will produce header: {% highlight yaml %} davert 12345 {% endhighlight %} * `param` $header * `param array` $params #### seeSoapResponseCodeIs Checks response code from server. * `param` $code #### seeSoapResponseContainsStructure Checks XML response contains provided structure. Response elements will be compared with XML provided. Only nodeNames are checked to see elements match. Example: {% highlight php %} seeSoapResponseContainsStructure(""); ?>{% endhighlight %}
Use this method to check XML of valid structure is returned. This method does not use schema for validation. This method does not require path from root to match the structure.
param$xml
Checks XML response with XPath locator
{% highlight php %}
seeSoapResponseContainsXPath('//root/user[@id=1]'); ?>{% endhighlight %}
param$xpath
Checks XML response equals provided XML. Comparison is done by canonicalizing both xml`s.
Parameters can be passed either as DOMDocument, DOMNode, XML string, or array (if no attributes).
Example:
{% highlight php %}
seeSoapResponseEquals("1");$dom = new \DOMDocument(); $dom->load($file); $I->seeSoapRequestIncludes($dom);
{% endhighlight %}
param$xml
Checks XML response includes provided XML. Comparison is done by canonicalizing both xml`s. Parameter can be passed either as XmlBuilder, DOMDocument, DOMNode, XML string, or array (if no attributes).
Example:
{% highlight php %}
seeSoapResponseIncludes("1"); $I->seeSoapRequestIncludes(\Codeception\Utils\Soap::response()->result->val(1)); $dom = new \DDOMDocument(); $dom->load('template.xml'); $I->seeSoapRequestIncludes($dom); ?>{% endhighlight %}
param$xml
Submits request to endpoint.
Requires of api function name and parameters. Parameters can be passed either as DOMDocument, DOMNode, XML string, or array (if no attributes).
You are allowed to execute as much requests as you need inside test.
Example:
{% highlight php %}
$I->sendSoapRequest('UpdateUser', '1notdavert'); $I->sendSoapRequest('UpdateUser', \Codeception\Utils\Soap::request()->user ->id->val(1)->parent() ->name->val('notdavert');
{% endhighlight %}
param$requestparam$body