xref: /PHP-8.4/ext/soap/tests/typemap008.phpt (revision e1b59e9e)
1--TEST--
2SOAP Typemap 8: SoapClient support for typemap's to_xml() (without WSDL, using SoapVar)
3--EXTENSIONS--
4soap
5--INI--
6soap.wsdl_cache_enabled=0
7--FILE--
8<?php
9class TestSoapClient extends SoapClient{
10  function __doRequest($request, $location, $action, $version, $one_way = 0): never {
11        echo $request;
12        exit;
13    }
14}
15
16class book{
17    public $a="a";
18    public $b="c";
19
20}
21
22function book_to_xml($book) {
23    return '<book xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><a xsi:type="xsd:string">'.$book->a.'!</a><b xsi:type="xsd:string">'.$book->b.'!</b></book>';
24}
25
26$options=Array(
27        'uri'      => 'http://schemas.nothing.com',
28        'location' => 'test://',
29        'actor'    => 'http://schemas.nothing.com',
30        'typemap'  => array(array("type_ns"   => "http://schemas.nothing.com",
31                                  "type_name" => "book",
32                                  "to_xml"  => "book_to_xml"))
33        );
34
35$client = new TestSoapClient(NULL, $options);
36$book = new book();
37$book->a = "foo";
38$book->b = "bar";
39$ret = $client->dotest(new SoapVar($book, null, "book", "http://schemas.nothing.com"));
40var_dump($ret);
41echo "ok\n";
42?>
43--EXPECT--
44<?xml version="1.0" encoding="UTF-8"?>
45<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:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"><SOAP-ENV:Body><ns1:dotest><book xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="ns1:book"><a xsi:type="xsd:string">foo!</a><b xsi:type="xsd:string">bar!</b></book></ns1:dotest></SOAP-ENV:Body></SOAP-ENV:Envelope>
46