xref: /php-src/ext/soap/tests/any.phpt (revision e1b59e9e)
1--TEST--
2SOAP handling of <any>
3--EXTENSIONS--
4soap
5--INI--
6precision=14
7soap.wsdl_cache_enabled=0
8--FILE--
9<?php
10class SOAPComplexType {
11    function __construct(public $varString, public $varInt, public $varFloat) {}
12}
13$struct = new SOAPComplexType('arg',34,325.325);
14
15function echoAnyElement($x) {
16    global $g;
17
18    $g = $x;
19    $struct = $x->inputAny->any["SOAPComplexType"];
20    if ($struct instanceof SOAPComplexType) {
21        return array("return" => array("any" => array("SOAPComplexType"=>new SoapVar($struct, SOAP_ENC_OBJECT, "SOAPComplexType", "http://soapinterop.org/xsd", "SOAPComplexType", "http://soapinterop.org/"))));
22    } else {
23        return "?";
24    }
25}
26
27class TestSoapClient extends SoapClient {
28  private $server;
29
30  function __construct($wsdl, $options) {
31    parent::__construct($wsdl, $options);
32    $this->server = new SoapServer($wsdl, $options);
33    $this->server->addFunction('echoAnyElement');
34  }
35
36  function __doRequest($request, $location, $action, $version, $one_way = 0): string {
37    ob_start();
38    $this->server->handle($request);
39    $response = ob_get_contents();
40    ob_end_clean();
41    return $response;
42  }
43}
44
45$client = new TestSoapClient(__DIR__."/interop/Round4/GroupI/round4_groupI_xsd.wsdl",
46                             array("trace"=>1,"exceptions"=>0,
47                             'classmap' => array('SOAPComplexType'=>'SOAPComplexType')));
48$ret = $client->echoAnyElement(
49  array(
50    "inputAny"=>array(
51       "any"=>new SoapVar($struct, SOAP_ENC_OBJECT, "SOAPComplexType", "http://soapinterop.org/xsd", "SOAPComplexType", "http://soapinterop.org/")
52     )));
53var_dump($g);
54var_dump($ret);
55?>
56--EXPECTF--
57object(stdClass)#%d (%d) {
58  ["inputAny"]=>
59  object(stdClass)#%d (%d) {
60    ["any"]=>
61    array(1) {
62      ["SOAPComplexType"]=>
63      object(SOAPComplexType)#%d (%d) {
64        ["varString"]=>
65        string(3) "arg"
66        ["varInt"]=>
67        int(34)
68        ["varFloat"]=>
69        float(325.325)
70      }
71    }
72  }
73}
74object(stdClass)#%d (%d) {
75  ["return"]=>
76  object(stdClass)#%d (%d) {
77    ["any"]=>
78    array(1) {
79      ["SOAPComplexType"]=>
80      object(SOAPComplexType)#%d (%d) {
81        ["varString"]=>
82        string(3) "arg"
83        ["varInt"]=>
84        int(34)
85        ["varFloat"]=>
86        float(325.325)
87      }
88    }
89  }
90}
91