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