Skip to content

Commit 9c1158c

Browse files
committed
SOAP tests fixed
1 parent d5dffb6 commit 9c1158c

File tree

1 file changed

+29
-13
lines changed

1 file changed

+29
-13
lines changed

src/Codeception/Module/SOAP.php

Lines changed: 29 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
*
3333
*/
3434

35+
use Codeception\Exception\ModuleException;
3536
use Codeception\Exception\ModuleRequireException;
3637
use Codeception\Lib\Framework;
3738
use Codeception\Lib\InnerBrowser;
@@ -73,7 +74,7 @@ class SOAP extends \Codeception\Module
7374
/**
7475
* @var XmlStructure
7576
*/
76-
protected $xmlStructure;
77+
protected $xmlStructure = null;
7778

7879
/**
7980
* @var InnerBrowser
@@ -85,6 +86,7 @@ public function _before(\Codeception\TestCase $test)
8586
$this->client = &$this->connectionModule->client;
8687
$this->buildRequest();
8788
$this->xmlResponse = null;
89+
$this->xmlStructure = null;
8890
}
8991

9092
public function _depends()
@@ -108,7 +110,22 @@ private function getClient()
108110
return $this->client;
109111
}
110112

111-
113+
private function getXmlResponse()
114+
{
115+
if (!$this->xmlResponse) {
116+
throw new ModuleException($this, "No XML response, use `\$I->sendSoapRequest` to receive it");
117+
}
118+
return $this->xmlResponse;
119+
}
120+
121+
private function getXmlStructure()
122+
{
123+
if (!$this->xmlStructure) {
124+
$this->xmlStructure = new XmlStructure($this->getXmlResponse());
125+
}
126+
return $this->xmlStructure;
127+
}
128+
112129
/**
113130
* Prepare SOAP header.
114131
* Receives header name and parameters as array.
@@ -198,7 +215,6 @@ public function sendSoapRequest($action, $body = "")
198215

199216
$this->debugSection("Response", $response);
200217
$this->xmlResponse = SoapUtils::toXml($response);
201-
$this->xmlStructure = new XmlStructure($this->xmlResponse);
202218
}
203219

204220
/**
@@ -224,7 +240,7 @@ public function sendSoapRequest($action, $body = "")
224240
public function seeSoapResponseEquals($xml)
225241
{
226242
$xml = SoapUtils::toXml($xml);
227-
$this->assertEquals($this->xmlResponse->C14N(), $xml->C14N());
243+
$this->assertEquals($this->getXmlResponse()->C14N(), $xml->C14N());
228244
}
229245

230246
/**
@@ -250,7 +266,7 @@ public function seeSoapResponseEquals($xml)
250266
public function seeSoapResponseIncludes($xml)
251267
{
252268
$xml = $this->canonicalize($xml);
253-
$this->assertContains($xml, $this->xmlResponse->C14N(), "found in XML Response");
269+
$this->assertContains($xml, $this->getXmlResponse()->C14N(), "found in XML Response");
254270
}
255271

256272

@@ -265,7 +281,7 @@ public function seeSoapResponseIncludes($xml)
265281
public function dontSeeSoapResponseEquals($xml)
266282
{
267283
$xml = SoapUtils::toXml($xml);
268-
\PHPUnit_Framework_Assert::assertXmlStringNotEqualsXmlString($this->xmlResponse->C14N(), $xml->C14N());
284+
\PHPUnit_Framework_Assert::assertXmlStringNotEqualsXmlString($this->getXmlResponse()->C14N(), $xml->C14N());
269285
}
270286

271287

@@ -279,7 +295,7 @@ public function dontSeeSoapResponseEquals($xml)
279295
public function dontSeeSoapResponseIncludes($xml)
280296
{
281297
$xml = $this->canonicalize($xml);
282-
$this->assertNotContains($xml, $this->xmlResponse->C14N(), "found in XML Response");
298+
$this->assertNotContains($xml, $this->getXmlResponse()->C14N(), "found in XML Response");
283299
}
284300

285301
/**
@@ -307,7 +323,7 @@ public function seeSoapResponseContainsStructure($xml)
307323
{
308324
$xml = SoapUtils::toXml($xml);
309325
$this->debugSection("Structure", $xml->saveXML());
310-
$this->assertTrue((bool)$this->xmlValidator->matchXmlStructure($xml), "this structure is in response");
326+
$this->assertTrue((bool)$this->getXmlStructure()->matchXmlStructure($xml), "this structure is in response");
311327
}
312328

313329
/**
@@ -318,7 +334,7 @@ public function dontSeeSoapResponseContainsStructure($xml)
318334
{
319335
$xml = SoapUtils::toXml($xml);
320336
$this->debugSection("Structure", $xml->saveXML());
321-
$this->assertFalse((bool)$this->xmlValidator->matchXmlStructure($xml), "this structure is in response");
337+
$this->assertFalse((bool)$this->getXmlStructure()->matchXmlStructure($xml), "this structure is in response");
322338
}
323339

324340
/**
@@ -334,7 +350,7 @@ public function dontSeeSoapResponseContainsStructure($xml)
334350
*/
335351
public function seeSoapResponseContainsXPath($xpath)
336352
{
337-
$this->assertTrue($this->xmlValidator->matchesXpath($xpath));
353+
$this->assertTrue($this->getXmlStructure()->matchesXpath($xpath));
338354
}
339355

340356
/**
@@ -350,7 +366,7 @@ public function seeSoapResponseContainsXPath($xpath)
350366
*/
351367
public function dontSeeSoapResponseContainsXPath($xpath)
352368
{
353-
$this->assertFalse($this->xmlValidator->matchesXpath($xpath));
369+
$this->assertFalse($this->getXmlStructure()->matchesXpath($xpath));
354370
}
355371

356372

@@ -374,7 +390,7 @@ public function seeResponseCodeIs($code)
374390
*/
375391
public function grabTextContentFrom($cssOrXPath)
376392
{
377-
$el = $this->xmlValidator->matchElement($cssOrXPath);
393+
$el = $this->getXmlStructure()->matchElement($cssOrXPath);
378394
return $el->textContent;
379395
}
380396

@@ -389,7 +405,7 @@ public function grabTextContentFrom($cssOrXPath)
389405
*/
390406
public function grabAttributeFrom($cssOrXPath, $attribute)
391407
{
392-
$el = $this->xmlValidator->matchElement($cssOrXPath);
408+
$el = $this->getXmlStructure()->matchElement($cssOrXPath);
393409
if (!$el->hasAttribute($attribute)) {
394410
$this->fail("Attribute not found in element matched by '$cssOrXPath'");
395411
}

0 commit comments

Comments
 (0)