Skip to content

Commit 8f4add0

Browse files
committed
ext/soap: Add some SoapClient tests about handling errors
1 parent 90be701 commit 8f4add0

File tree

2 files changed

+87
-0
lines changed

2 files changed

+87
-0
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
--TEST--
2+
SoapClient constructor with an invalid encoding option
3+
--EXTENSIONS--
4+
soap
5+
--FILE--
6+
<?php
7+
8+
class ExtendedSoapClient extends SoapClient {}
9+
10+
$wsdl = 'irrelevant';
11+
$options = [
12+
'encoding' => 'non-sense',
13+
];
14+
try {
15+
$client = new SoapClient($wsdl, $options);
16+
} catch (Throwable $e) {
17+
echo $e::class, ': ', $e->getMessage(), PHP_EOL;
18+
}
19+
try {
20+
$client = new ExtendedSoapClient($wsdl, $options);
21+
} catch (Throwable $e) {
22+
echo $e::class, ': ', $e->getMessage(), PHP_EOL;
23+
}
24+
25+
26+
?>
27+
--EXPECT--
28+
SoapFault: SoapClient::__construct(): Invalid 'encoding' option - 'non-sense'
29+
SoapFault: SoapClient::__construct(): Invalid 'encoding' option - 'non-sense'
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
--TEST--
2+
SoapClient in non WSDL mode without required options
3+
--EXTENSIONS--
4+
soap
5+
--FILE--
6+
<?php
7+
8+
class ExtendedSoapClient extends SoapClient {}
9+
10+
echo "\$options not provided\n";
11+
try {
12+
$client = new SoapClient(null);
13+
} catch (Throwable $e) {
14+
echo $e::class, ': ', $e->getMessage(), PHP_EOL;
15+
}
16+
try {
17+
$client = new ExtendedSoapClient(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 SoapClient(null, $options);
26+
} catch (Throwable $e) {
27+
echo $e::class, ': ', $e->getMessage(), PHP_EOL;
28+
}
29+
try {
30+
$client = new ExtendedSoapClient(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 SoapClient(null, $options);
39+
} catch (Throwable $e) {
40+
echo $e::class, ': ', $e->getMessage(), PHP_EOL;
41+
}
42+
try {
43+
$client = new ExtendedSoapClient(null, $options);
44+
} catch (Throwable $e) {
45+
echo $e::class, ': ', $e->getMessage(), PHP_EOL;
46+
}
47+
48+
?>
49+
--EXPECT--
50+
$options not provided
51+
SoapFault: SoapClient::__construct(): 'location' and 'uri' options are required in nonWSDL mode
52+
SoapFault: SoapClient::__construct(): 'location' and 'uri' options are required in nonWSDL mode
53+
Empty $options array
54+
SoapFault: SoapClient::__construct(): 'uri' option is required in nonWSDL mode
55+
SoapFault: SoapClient::__construct(): 'uri' option is required in nonWSDL mode
56+
$options array only sets "uri" option
57+
SoapFault: SoapClient::__construct(): 'location' option is required in nonWSDL mode
58+
SoapFault: SoapClient::__construct(): 'location' option is required in nonWSDL mode

0 commit comments

Comments
 (0)