|
| 1 | +# SOAP |
| 2 | + |
| 3 | + |
| 4 | +Module for testing SOAP WSDL web services. |
| 5 | +Send requests and check if response matches the pattern. |
| 6 | + |
| 7 | +This module can be used either with frameworks or PHPBrowser. |
| 8 | +It tries to guess the framework is is attached to. |
| 9 | +If a endpoint is a full url then it uses PHPBrowser. |
| 10 | + |
| 11 | +### Using Inside Framework |
| 12 | + |
| 13 | +Please note, that PHP SoapServer::handle method sends additional headers. |
| 14 | +This may trigger warning: "Cannot modify header information" |
| 15 | +If you use PHP SoapServer with framework, try to block call to this method in testing environment. |
| 16 | + |
| 17 | +## Status |
| 18 | + |
| 19 | +* Maintainer: **davert** |
| 20 | +* Stability: **stable** |
| 21 | + |
| 22 | + |
| 23 | +## Configuration |
| 24 | + |
| 25 | +* endpoint *required* - soap wsdl endpoint |
| 26 | +* SOAPAction - replace SOAPAction HTTP header (Set to '' to SOAP 1.2) |
| 27 | + |
| 28 | +## Public Properties |
| 29 | + |
| 30 | +* xmlRequest - last SOAP request (DOMDocument) |
| 31 | +* xmlResponse - last SOAP response (DOMDocument) |
| 32 | + |
| 33 | + |
| 34 | +## Actions |
| 35 | + |
| 36 | +### dontSeeSoapResponseContainsStructure |
| 37 | + |
| 38 | +Opposite to `seeSoapResponseContainsStructure` |
| 39 | + * `param` $xml |
| 40 | + |
| 41 | + |
| 42 | +### dontSeeSoapResponseContainsXPath |
| 43 | + |
| 44 | +Checks XML response doesn't contain XPath locator |
| 45 | + |
| 46 | +``` php |
| 47 | +<?php |
| 48 | +$I->dontSeeSoapResponseContainsXPath('//root/user[@id=1]'); |
| 49 | +?> |
| 50 | +``` |
| 51 | + |
| 52 | + * `param` $xpath |
| 53 | + |
| 54 | + |
| 55 | +### dontSeeSoapResponseEquals |
| 56 | + |
| 57 | +Checks XML response equals provided XML. |
| 58 | +Comparison is done by canonicalizing both xml`s. |
| 59 | + |
| 60 | +Parameter can be passed either as XmlBuilder, DOMDocument, DOMNode, XML string, or array (if no attributes). |
| 61 | + |
| 62 | + * `param` $xml |
| 63 | + |
| 64 | + |
| 65 | +### dontSeeSoapResponseIncludes |
| 66 | + |
| 67 | +Checks XML response does not include provided XML. |
| 68 | +Comparison is done by canonicalizing both xml`s. |
| 69 | +Parameter can be passed either as XmlBuilder, DOMDocument, DOMNode, XML string, or array (if no attributes). |
| 70 | + |
| 71 | + * `param` $xml |
| 72 | + |
| 73 | + |
| 74 | +### grabAttributeFrom |
| 75 | + |
| 76 | +Finds and returns attribute of element. |
| 77 | +Element is matched by either CSS or XPath |
| 78 | + |
| 79 | + * `Available since` 1.1 |
| 80 | + * `param` $cssOrXPath |
| 81 | + * `param` $attribute |
| 82 | + * `return` string |
| 83 | + |
| 84 | + |
| 85 | +### grabTextContentFrom |
| 86 | + |
| 87 | +Finds and returns text contents of element. |
| 88 | +Element is matched by either CSS or XPath |
| 89 | + |
| 90 | + * `Available since` 1.1 |
| 91 | + * `param` $cssOrXPath |
| 92 | + * `return` string |
| 93 | + |
| 94 | + |
| 95 | +### haveSoapHeader |
| 96 | + |
| 97 | +Prepare SOAP header. |
| 98 | +Receives header name and parameters as array. |
| 99 | + |
| 100 | +Example: |
| 101 | + |
| 102 | +``` php |
| 103 | +<?php |
| 104 | +$I->haveSoapHeader('AuthHeader', array('username' => 'davert', 'password' => '123345')); |
| 105 | +``` |
| 106 | + |
| 107 | +Will produce header: |
| 108 | + |
| 109 | +``` |
| 110 | + <soapenv:Header> |
| 111 | + <SessionHeader> |
| 112 | + <AuthHeader> |
| 113 | + <username>davert</username> |
| 114 | + <password>12345</password> |
| 115 | + </AuthHeader> |
| 116 | + </soapenv:Header> |
| 117 | +``` |
| 118 | + |
| 119 | + * `param` $header |
| 120 | + * `param array` $params |
| 121 | + |
| 122 | + |
| 123 | +### seeSoapResponseCodeIs |
| 124 | + |
| 125 | +Checks response code from server. |
| 126 | + |
| 127 | + * `param` $code |
| 128 | + |
| 129 | + |
| 130 | +### seeSoapResponseContainsStructure |
| 131 | + |
| 132 | +Checks XML response contains provided structure. |
| 133 | +Response elements will be compared with XML provided. |
| 134 | +Only nodeNames are checked to see elements match. |
| 135 | + |
| 136 | +Example: |
| 137 | + |
| 138 | +``` php |
| 139 | +<?php |
| 140 | + |
| 141 | +$I->seeSoapResponseContainsStructure("<query><name></name></query>"); |
| 142 | +?> |
| 143 | +``` |
| 144 | + |
| 145 | +Use this method to check XML of valid structure is returned. |
| 146 | +This method does not use schema for validation. |
| 147 | +This method does not require path from root to match the structure. |
| 148 | + |
| 149 | + * `param` $xml |
| 150 | + |
| 151 | + |
| 152 | +### seeSoapResponseContainsXPath |
| 153 | + |
| 154 | +Checks XML response with XPath locator |
| 155 | + |
| 156 | +``` php |
| 157 | +<?php |
| 158 | +$I->seeSoapResponseContainsXPath('//root/user[@id=1]'); |
| 159 | +?> |
| 160 | +``` |
| 161 | + |
| 162 | + * `param` $xpath |
| 163 | + |
| 164 | + |
| 165 | +### seeSoapResponseEquals |
| 166 | + |
| 167 | +Checks XML response equals provided XML. |
| 168 | +Comparison is done by canonicalizing both xml`s. |
| 169 | + |
| 170 | +Parameters can be passed either as DOMDocument, DOMNode, XML string, or array (if no attributes). |
| 171 | + |
| 172 | +Example: |
| 173 | + |
| 174 | +``` php |
| 175 | +<?php |
| 176 | +$I->seeSoapResponseEquals("<?xml version="1.0" encoding="UTF-8"?><SOAP-ENV:Envelope><SOAP-ENV:Body><result>1</result></SOAP-ENV:Envelope>"); |
| 177 | + |
| 178 | +$dom = new \DOMDocument(); |
| 179 | +$dom->load($file); |
| 180 | +$I->seeSoapRequestIncludes($dom); |
| 181 | + |
| 182 | +``` |
| 183 | + |
| 184 | + * `param` $xml |
| 185 | + |
| 186 | + |
| 187 | +### seeSoapResponseIncludes |
| 188 | + |
| 189 | +Checks XML response includes provided XML. |
| 190 | +Comparison is done by canonicalizing both xml`s. |
| 191 | +Parameter can be passed either as XmlBuilder, DOMDocument, DOMNode, XML string, or array (if no attributes). |
| 192 | + |
| 193 | +Example: |
| 194 | + |
| 195 | +``` php |
| 196 | +<?php |
| 197 | +$I->seeSoapResponseIncludes("<result>1</result>"); |
| 198 | +$I->seeSoapRequestIncludes(\Codeception\Utils\Soap::response()->result->val(1)); |
| 199 | + |
| 200 | +$dom = new \DDOMDocument(); |
| 201 | +$dom->load('template.xml'); |
| 202 | +$I->seeSoapRequestIncludes($dom); |
| 203 | +?> |
| 204 | +``` |
| 205 | + |
| 206 | + * `param` $xml |
| 207 | + |
| 208 | + |
| 209 | +### sendSoapRequest |
| 210 | + |
| 211 | +Submits request to endpoint. |
| 212 | + |
| 213 | +Requires of api function name and parameters. |
| 214 | +Parameters can be passed either as DOMDocument, DOMNode, XML string, or array (if no attributes). |
| 215 | + |
| 216 | +You are allowed to execute as much requests as you need inside test. |
| 217 | + |
| 218 | +Example: |
| 219 | + |
| 220 | +``` php |
| 221 | +$I->sendSoapRequest('UpdateUser', '<user><id>1</id><name>notdavert</name></user>'); |
| 222 | +$I->sendSoapRequest('UpdateUser', \Codeception\Utils\Soap::request()->user |
| 223 | + ->id->val(1)->parent() |
| 224 | + ->name->val('notdavert'); |
| 225 | +``` |
| 226 | + |
| 227 | + * `param` $request |
| 228 | + * `param` $body |
| 229 | + |
| 230 | +<p> </p><div class="alert alert-warning">Module reference is taken from the source code. <a href="https://github.com/Codeception/module-soap/tree/master/src/Codeception/Module/SOAP.php">Help us to improve documentation. Edit module reference</a></div> |
0 commit comments