Skip to content

Commit f94af82

Browse files
committed
add unit tests
1 parent 5a42fae commit f94af82

File tree

3 files changed

+215
-0
lines changed

3 files changed

+215
-0
lines changed

Tests/Client.php

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,44 @@
44

55
class Client extends \SoapClient
66
{
7+
public function __getLastRequest()
8+
{
9+
return file_get_contents(__DIR__ . '/resources/oneline.xml');
10+
}
11+
public function __getLastResponse()
12+
{
13+
return file_get_contents(__DIR__ . '/resources/oneline.xml');
14+
}
15+
public function __getLastRequestHeaders()
16+
{
17+
return "X-Header-1: valud-1\r\n".
18+
"X-Header-2: valud-2\r\n".
19+
"X-Header-Date: 2015-03-02T21:36:87\r\n".
20+
"X-Header-Content-Type: text/xml; charset=utf-8\r\n";
21+
}
22+
public function getLastRequestHeadersAsArray()
23+
{
24+
return array(
25+
'X-Header-1' => 'valud-1',
26+
'X-Header-2' => 'valud-2',
27+
'X-Header-Date' => '2015-03-02T21:36:87',
28+
'X-Header-Content-Type' => 'text/xml; charset=utf-8',
29+
);
30+
}
31+
public function __getLastResponseHeaders()
32+
{
33+
return "X-Header-1: valud-1\r\n".
34+
"X-Header-2: valud-2\r\n".
35+
"X-Header-Date: 2015-03-02T21:36:87\r\n".
36+
"X-Header-Content-Type: text/xml; charset=utf-8\r\n";
37+
}
38+
public function getLastResponseHeadersAsArray()
39+
{
40+
return array(
41+
'X-Header-1' => 'valud-1',
42+
'X-Header-2' => 'valud-2',
43+
'X-Header-Date' => '2015-03-02T21:36:87',
44+
'X-Header-Content-Type' => 'text/xml; charset=utf-8',
45+
);
46+
}
747
}

Tests/SoapClient.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,22 @@ public function getSoapClientClassName($soapClientClassName = null)
1010
{
1111
return parent::getSoapClientClassName(empty($soapClientClassName) ? '\\WsdlToPhp\\PackageBase\\Tests\\Client' : $soapClientClassName);
1212
}
13+
/**
14+
* @return Client
15+
*/
16+
public static function getSoapClient()
17+
{
18+
return parent::getSoapClient();
19+
}
20+
/**
21+
*
22+
*/
23+
public function search()
24+
{
25+
try {
26+
self::getSoapClient()->search();
27+
} catch (\SoapFault $soapFault) {
28+
$this->saveLastError(__METHOD__, $soapFault);
29+
}
30+
}
1331
}

Tests/SoapClientTest.php

Lines changed: 157 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
namespace WsdlToPhp\PackageBase\Tests;
44

55

6+
use WsdlToPhp\PackageBase\Utils;
7+
68
use WsdlToPhp\PackageBase\Tests\SoapClient;
79

810
class SoapClientTest extends TestCase
@@ -37,6 +39,161 @@ public function testSoapClient()
3739

3840
$this->assertInstanceOf('\\WsdlToPhp\\PackageBase\\Tests\\Client', $soapClient->getSoapClient());
3941
}
42+
/**
43+
*
44+
*/
45+
public function testSetLocation()
46+
{
47+
$soapClient = new SoapClient(array(
48+
SoapClient::WSDL_URL => __DIR__ . '/resources/bingsearch.wsdl',
49+
SoapClient::WSDL_CLASSMAP => self::classMap(),
50+
));
51+
52+
$soapClient->setLocation('http://api.bing.net:80/soap.asm');
53+
54+
$this->assertSAme('http://api.bing.net:80/soap.asm', $soapClient->getSoapClient()->location);
55+
}
56+
/**
57+
*
58+
*/
59+
public function testGetLastRequestAsString()
60+
{
61+
$soapClient = new SoapClient(array(
62+
SoapClient::WSDL_URL => __DIR__ . '/resources/bingsearch.wsdl',
63+
SoapClient::WSDL_CLASSMAP => self::classMap(),
64+
));
65+
66+
$this->assertSame(Utils::getFormatedXml(file_get_contents(__DIR__ . '/resources/oneline.xml')), $soapClient->getLastRequest(false));
67+
}
68+
/**
69+
*
70+
*/
71+
public function testGetLastRequestAsDomDocument()
72+
{
73+
$soapClient = new SoapClient(array(
74+
SoapClient::WSDL_URL => __DIR__ . '/resources/bingsearch.wsdl',
75+
SoapClient::WSDL_CLASSMAP => self::classMap(),
76+
));
77+
78+
$this->assertInstanceOf('\\DOMDocument', $soapClient->getLastRequest(true));
79+
}
80+
/**
81+
*
82+
*/
83+
public function testGetLastResponseAsString()
84+
{
85+
$soapClient = new SoapClient(array(
86+
SoapClient::WSDL_URL => __DIR__ . '/resources/bingsearch.wsdl',
87+
SoapClient::WSDL_CLASSMAP => self::classMap(),
88+
));
89+
90+
$this->assertSame(Utils::getFormatedXml(file_get_contents(__DIR__ . '/resources/oneline.xml')), $soapClient->getLastResponse(false));
91+
}
92+
/**
93+
*
94+
*/
95+
public function testGetLastResponseAsDomDocument()
96+
{
97+
$soapClient = new SoapClient(array(
98+
SoapClient::WSDL_URL => __DIR__ . '/resources/bingsearch.wsdl',
99+
SoapClient::WSDL_CLASSMAP => self::classMap(),
100+
));
101+
102+
$this->assertInstanceOf('\\DOMDocument', $soapClient->getLastResponse(true));
103+
}
104+
/**
105+
*
106+
*/
107+
public function testGetLastRequestHeadersAsString()
108+
{
109+
$soapClient = new SoapClient(array(
110+
SoapClient::WSDL_URL => __DIR__ . '/resources/bingsearch.wsdl',
111+
SoapClient::WSDL_CLASSMAP => self::classMap(),
112+
));
113+
114+
$this->assertSame($soapClient->getSoapClient()->__getLastRequestHeaders(), $soapClient->getLastRequestHeaders(false));
115+
}
116+
/**
117+
*
118+
*/
119+
public function testGetLastRequestHeadersAsArray()
120+
{
121+
$soapClient = new SoapClient(array(
122+
SoapClient::WSDL_URL => __DIR__ . '/resources/bingsearch.wsdl',
123+
SoapClient::WSDL_CLASSMAP => self::classMap(),
124+
));
125+
126+
$this->assertSame($soapClient->getSoapClient()->getLastRequestHeadersAsArray(), $soapClient->getLastRequestHeaders(true));
127+
}
128+
/**
129+
*
130+
*/
131+
public function testGetLastResponseHeadersAsString()
132+
{
133+
$soapClient = new SoapClient(array(
134+
SoapClient::WSDL_URL => __DIR__ . '/resources/bingsearch.wsdl',
135+
SoapClient::WSDL_CLASSMAP => self::classMap(),
136+
));
137+
138+
$this->assertSame($soapClient->getSoapClient()->__getLastResponseHeaders(), $soapClient->getLastResponseHeaders(false));
139+
}
140+
/**
141+
*
142+
*/
143+
public function testGetLastResponseHeadersAsArray()
144+
{
145+
$soapClient = new SoapClient(array(
146+
SoapClient::WSDL_URL => __DIR__ . '/resources/bingsearch.wsdl',
147+
SoapClient::WSDL_CLASSMAP => self::classMap(),
148+
));
149+
150+
$this->assertSame($soapClient->getSoapClient()->getLastResponseHeadersAsArray(), $soapClient->getLastResponseHeaders(true));
151+
}
152+
/**
153+
*
154+
*/
155+
public function testSetGetLastErrorForMethod()
156+
{
157+
$soapClient = new SoapClient(array(
158+
SoapClient::WSDL_URL => __DIR__ . '/resources/bingsearch.wsdl',
159+
SoapClient::WSDL_CLASSMAP => self::classMap(),
160+
));
161+
162+
// this call should fail as no parameter is defined in the request
163+
$soapClient->search();
164+
165+
$this->assertInstanceOf('\\SoapFault', $soapClient->getLastErrorForMethod('WsdlToPhp\PackageBase\Tests\SoapClient::search'));
166+
}
167+
/**
168+
*
169+
*/
170+
public function testSetGetLastError()
171+
{
172+
$soapClient = new SoapClient(array(
173+
SoapClient::WSDL_URL => __DIR__ . '/resources/bingsearch.wsdl',
174+
SoapClient::WSDL_CLASSMAP => self::classMap(),
175+
));
176+
177+
// this call should fail as no parameter is defined in the request
178+
$soapClient->search();
179+
180+
$this->assertCount(1, $soapClient->getLastError());
181+
}
182+
/**
183+
*
184+
*/
185+
public function testSetGetResult()
186+
{
187+
$soapClient = new SoapClient(array(
188+
SoapClient::WSDL_URL => __DIR__ . '/resources/bingsearch.wsdl',
189+
SoapClient::WSDL_CLASSMAP => self::classMap(),
190+
));
191+
192+
// this call should fail as no parameter is defined in the request
193+
$soapClient->search();
194+
195+
$this->assertNull($soapClient->getResult());
196+
}
40197
/**
41198
* @return string[]
42199
*/

0 commit comments

Comments
 (0)