xref: /PHP-8.1/ext/soap/tests/typemap007.phpt (revision 8ae4b560)
1--TEST--
2SOAP Typemap 7: SoapClient support for typemap's from_xml() (without WSDL)
3--EXTENSIONS--
4soap
5simplexml
6--INI--
7soap.wsdl_cache_enabled=0
8--FILE--
9<?php
10class TestSoapClient extends SoapClient{
11  function __doRequest($request, $location, $action, $version, $one_way = 0): ?string {
12        return <<<EOF
13<?xml version="1.0" encoding="UTF-8"?>
14<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://schemas.nothing.com" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"><SOAP-ENV:Body>
15<ns1:dotest2Response><res xsi:type="ns1:book">
16  <a xsi:type="xsd:string">foo</a>
17  <b xsi:type="xsd:string">bar</b>
18</res>
19</ns1:dotest2Response></SOAP-ENV:Body></SOAP-ENV:Envelope>
20EOF;
21    }
22}
23
24class book{
25    public $a="a";
26    public $b="c";
27
28}
29
30function book_from_xml($xml) {
31    $sxe = simplexml_load_string($xml);
32    $obj = new book;
33    $obj->a = (string)$sxe->a;
34    $obj->b = (string)$sxe->b;
35    return $obj;
36}
37
38$options=Array(
39        'uri'      => 'http://schemas.nothing.com',
40        'location' => 'test://',
41        'actor'    => 'http://schemas.nothing.com',
42        'typemap'  => array(array("type_ns"   => "http://schemas.nothing.com",
43                                  "type_name" => "book",
44                                  "from_xml"  => "book_from_xml"))
45        );
46
47$client = new TestSoapClient(NULL, $options);
48$ret = $client->dotest2("???");
49var_dump($ret);
50echo "ok\n";
51?>
52--EXPECTF--
53object(book)#%d (2) {
54  ["a"]=>
55  string(3) "foo"
56  ["b"]=>
57  string(3) "bar"
58}
59ok
60