Skip to content

Commit 88331fe

Browse files
committed
ext/soap: ext/soap: Add some SoapServer tests about handling errors
1 parent 87323af commit 88331fe

File tree

3 files changed

+110
-0
lines changed

3 files changed

+110
-0
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
--TEST--
2+
SoapServer constructor with an invalid encoding option
3+
--EXTENSIONS--
4+
soap
5+
--FILE--
6+
<?php
7+
8+
class ExtendedSoapServer extends SoapServer {}
9+
10+
$wsdl = 'irrelevant';
11+
$options = [
12+
'encoding' => 'non-sense',
13+
];
14+
try {
15+
$client = new SoapServer($wsdl, $options);
16+
} catch (Throwable $e) {
17+
echo $e::class, ': ', $e->getMessage(), PHP_EOL;
18+
}
19+
try {
20+
$client = new ExtendedSoapServer($wsdl, $options);
21+
} catch (Throwable $e) {
22+
echo $e::class, ': ', $e->getMessage(), PHP_EOL;
23+
}
24+
25+
26+
?>
27+
--EXPECT--
28+
<?xml version="1.0" encoding="UTF-8"?>
29+
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"><SOAP-ENV:Body><SOAP-ENV:Fault><faultcode>SOAP-ENV:Server</faultcode><faultstring>SoapServer::__construct(): Invalid 'encoding' option - 'non-sense'</faultstring></SOAP-ENV:Fault></SOAP-ENV:Body></SOAP-ENV:Envelope>
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
--TEST--
2+
SoapServer constructor with an invalid encoding option
3+
--EXTENSIONS--
4+
soap
5+
--FILE--
6+
<?php
7+
8+
class ExtendedSoapServer extends SoapServer {}
9+
10+
$wsdl = 'irrelevant';
11+
$options = [
12+
'soap_version' => 1111,
13+
];
14+
try {
15+
$client = new SoapServer($wsdl, $options);
16+
} catch (Throwable $e) {
17+
echo $e::class, ': ', $e->getMessage(), PHP_EOL;
18+
}
19+
try {
20+
$client = new ExtendedSoapServer($wsdl, $options);
21+
} catch (Throwable $e) {
22+
echo $e::class, ': ', $e->getMessage(), PHP_EOL;
23+
}
24+
25+
26+
?>
27+
--EXPECT--
28+
<?xml version="1.0" encoding="UTF-8"?>
29+
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"><SOAP-ENV:Body><SOAP-ENV:Fault><faultcode>SOAP-ENV:Server</faultcode><faultstring>SoapServer::__construct(): 'soap_version' option must be SOAP_1_1 or SOAP_1_2</faultstring></SOAP-ENV:Fault></SOAP-ENV:Body></SOAP-ENV:Envelope>
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
--TEST--
2+
SoapServer in non WSDL mode without required options
3+
--EXTENSIONS--
4+
soap
5+
--FILE--
6+
<?php
7+
8+
class ExtendedSoapServer extends SoapServer {}
9+
10+
echo "\$options not provided\n";
11+
try {
12+
$client = new SoapServer(null);
13+
} catch (Throwable $e) {
14+
echo $e::class, ': ', $e->getMessage(), PHP_EOL;
15+
}
16+
try {
17+
$client = new ExtendedSoapServer(null);
18+
} catch (Throwable $e) {
19+
echo $e::class, ': ', $e->getMessage(), PHP_EOL;
20+
}
21+
22+
echo "Empty \$options array\n";
23+
$options = [];
24+
try {
25+
$client = new SoapServer(null, $options);
26+
} catch (Throwable $e) {
27+
echo $e::class, ': ', $e->getMessage(), PHP_EOL;
28+
}
29+
try {
30+
$client = new ExtendedSoapServer(null, $options);
31+
} catch (Throwable $e) {
32+
echo $e::class, ': ', $e->getMessage(), PHP_EOL;
33+
}
34+
35+
echo "\$options array only sets \"uri\" option\n";
36+
$options = ['uri' => 'https://example.com'];
37+
try {
38+
$client = new SoapServer(null, $options);
39+
} catch (Throwable $e) {
40+
echo $e::class, ': ', $e->getMessage(), PHP_EOL;
41+
}
42+
try {
43+
$client = new ExtendedSoapServer(null, $options);
44+
} catch (Throwable $e) {
45+
echo $e::class, ': ', $e->getMessage(), PHP_EOL;
46+
}
47+
48+
?>
49+
--EXPECT--
50+
$options not provided
51+
<?xml version="1.0" encoding="UTF-8"?>
52+
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"><SOAP-ENV:Body><SOAP-ENV:Fault><faultcode>SOAP-ENV:Server</faultcode><faultstring>SoapServer::__construct(): 'uri' option is required in nonWSDL mode</faultstring></SOAP-ENV:Fault></SOAP-ENV:Body></SOAP-ENV:Envelope>

0 commit comments

Comments
 (0)