xref: /PHP-8.1/ext/soap/tests/bugs/bug30045.phpt (revision 8ae4b560)
1--TEST--
2Bug #30045 (Cannot pass big integers (> 2147483647) in SOAP requests)
3--EXTENSIONS--
4soap
5simplexml
6--INI--
7soap.wsdl_cache_enabled=1
8--FILE--
9<?php
10
11function foo($type, $num) {
12  return new SoapVar($num, $type);
13}
14
15class LocalSoapClient extends SoapClient {
16
17  function __construct($wsdl, $options) {
18    parent::__construct($wsdl, $options);
19    $this->server = new SoapServer($wsdl, $options);
20    $this->server->addFunction('foo');
21  }
22
23  function __doRequest($request, $location, $action, $version, $one_way = 0): ?string {
24    $xml = simplexml_load_string($request);
25    echo $xml->children("http://schemas.xmlsoap.org/soap/envelope/")->Body->children("http://test-uri")->children()->param1->asXML(),"\n";
26    unset($xml);
27
28    ob_start();
29    $this->server->handle($request);
30    $response = ob_get_contents();
31    ob_end_clean();
32
33    return $response;
34  }
35
36}
37
38$soap = new LocalSoapClient(NULL, array("uri"=>"http://test-uri", "location"=>"test://"));
39
40function test($type, $num) {
41  global $soap;
42  try {
43      printf("  %0.0f\n    ", $num);
44      $ret = $soap->foo($type, new SoapVar($num, $type));
45      printf("    %0.0f\n", $ret);
46    } catch (SoapFault $ex) {
47      var_dump($ex);
48    }
49}
50/*
51echo "byte\n";
52//test(XSD_BYTE, -129);
53test(XSD_BYTE, -128);
54test(XSD_BYTE,  127);
55//test(XSD_BYTE,  128);
56
57echo "\nshort\n";
58//test(XSD_SHORT, -32769);
59test(XSD_SHORT, -32768);
60test(XSD_SHORT,  32767);
61//test(XSD_SHORT,  32768);
62
63echo "\nint\n";
64//test(XSD_INT, -2147483649);
65test(XSD_INT, -2147483648);
66test(XSD_INT,  2147483647);
67//test(XSD_INT,  2147483648);
68
69echo "\nlong\n";
70//test(XSD_LONG, -9223372036854775809);
71test(XSD_LONG, -9223372036854775808);
72test(XSD_LONG,  9223372036854775807);
73//test(XSD_LONG,  9223372036854775808);
74
75echo "\nunsignedByte\n";
76//test(XSD_UNSIGNEDBYTE, -1);
77test(XSD_UNSIGNEDBYTE,  0);
78test(XSD_UNSIGNEDBYTE,  255);
79//test(XSD_UNSIGNEDBYTE,  256);
80
81echo "\nunsignedShort\n";
82//test(XSD_UNSIGNEDSHORT, -1);
83test(XSD_UNSIGNEDSHORT,  0);
84test(XSD_UNSIGNEDSHORT,  65535);
85//test(XSD_UNSIGNEDSHORT,  65536);
86
87echo "\nunsignedInt\n";
88//test(XSD_UNSIGNEDINT, -1);
89test(XSD_UNSIGNEDINT,  0);
90test(XSD_UNSIGNEDINT,  4294967295);
91//test(XSD_UNSIGNEDINT,  4294967296);
92
93echo "\nunsignedLong\n";
94//test(XSD_UNSIGNEDLONG, -1);
95test(XSD_UNSIGNEDLONG,  0);
96test(XSD_UNSIGNEDLONG,  18446744073709551615);
97//test(XSD_UNSIGNEDLONG,  18446744073709551616);
98
99echo "\nnegativeInteger\n";
100test(XSD_NEGATIVEINTEGER, -18446744073709551616);
101test(XSD_NEGATIVEINTEGER, -1);
102//test(XSD_NEGATIVEINTEGER,  0);
103
104echo "\nnonPositiveInteger\n";
105test(XSD_NONPOSITIVEINTEGER, -18446744073709551616);
106test(XSD_NONPOSITIVEINTEGER,  0);
107//test(XSD_NONPOSITIVEINTEGER,  1);
108
109echo "\nnonNegativeInteger\n";
110//test(XSD_NONNEGATIVEINTEGER, -1);
111test(XSD_NONNEGATIVEINTEGER,  0);
112test(XSD_NONNEGATIVEINTEGER,  18446744073709551616);
113
114echo "\nPositiveInteger\n";
115//test(XSD_POSITIVEINTEGER,  0);
116test(XSD_POSITIVEINTEGER,  1);
117test(XSD_POSITIVEINTEGER,  18446744073709551616);
118
119echo "\ninteger\n";
120test(XSD_INTEGER, -18446744073709551616);
121test(XSD_INTEGER,  18446744073709551616);
122*/
123echo "long\n";
124test(XSD_LONG, 2147483647);
125test(XSD_LONG, 2147483648);
126test(XSD_LONG,  4294967296);
127test(XSD_LONG,  8589934592);
128test(XSD_LONG, 17179869184);
129
130echo "\nunsignedLong\n";
131test(XSD_UNSIGNEDLONG,  2147483647);
132test(XSD_UNSIGNEDLONG,  2147483648);
133test(XSD_UNSIGNEDLONG,  4294967296);
134test(XSD_UNSIGNEDLONG,  8589934592);
135test(XSD_UNSIGNEDLONG, 17179869184);
136
137?>
138--EXPECT--
139long
140  2147483647
141    <param1 xsi:type="xsd:long">2147483647</param1>
142    2147483647
143  2147483648
144    <param1 xsi:type="xsd:long">2147483648</param1>
145    2147483648
146  4294967296
147    <param1 xsi:type="xsd:long">4294967296</param1>
148    4294967296
149  8589934592
150    <param1 xsi:type="xsd:long">8589934592</param1>
151    8589934592
152  17179869184
153    <param1 xsi:type="xsd:long">17179869184</param1>
154    17179869184
155
156unsignedLong
157  2147483647
158    <param1 xsi:type="xsd:unsignedLong">2147483647</param1>
159    2147483647
160  2147483648
161    <param1 xsi:type="xsd:unsignedLong">2147483648</param1>
162    2147483648
163  4294967296
164    <param1 xsi:type="xsd:unsignedLong">4294967296</param1>
165    4294967296
166  8589934592
167    <param1 xsi:type="xsd:unsignedLong">8589934592</param1>
168    8589934592
169  17179869184
170    <param1 xsi:type="xsd:unsignedLong">17179869184</param1>
171    17179869184
172