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