xref: /PHP-8.1/ext/soap/tests/server031.phpt (revision 75a678a7)
1--TEST--
2SOAP Server 31: Handling classes which implements Iterator
3--EXTENSIONS--
4soap
5--INI--
6soap.wsdl_cache_enabled=0
7--FILE--
8<?php
9class ItemArray implements Iterator {
10    private $a = array();
11
12    public function __construct(array $a) {
13        $this->a = $a;
14    }
15
16    public function rewind(): void    { reset($this->a); }
17    public function current(): mixed   { return current($this->a); }
18    public function key(): mixed       { return key($this->a); }
19    public function next(): void      { next($this->a); }
20    public function valid(): bool     { return (current($this->a) !== false); }
21}
22
23class Item {
24    public $text;
25
26    public function __construct($n) {
27        $this->text = 'text'.$n;
28    }
29}
30
31class handlerClass {
32    public function getItems()
33    {
34        return new ItemArray(array(
35                new Item(0),
36                new Item(1),
37                new Item(2),
38                new Item(3),
39                new Item(4),
40                new Item(5),
41                new Item(6),
42                new Item(7),
43                new Item(8),
44                new Item(9)
45            ));
46    }
47}
48
49$server = new SoapServer(__DIR__."/server030.wsdl");
50$server->setClass('handlerClass');
51
52$HTTP_RAW_POST_DATA = <<<EOF
53<?xml version="1.0" encoding="ISO-8859-1"?>
54<SOAP-ENV:Envelope
55  SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
56  xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
57  <SOAP-ENV:Body>
58    <getItems/>
59  </SOAP-ENV:Body>
60</SOAP-ENV:Envelope>
61EOF;
62
63$server->handle($HTTP_RAW_POST_DATA);
64echo "ok\n";
65?>
66--EXPECT--
67<?xml version="1.0" encoding="UTF-8"?>
68<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://testuri.org" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"><SOAP-ENV:Body><ns1:getItemsResponse><getItemsReturn SOAP-ENC:arrayType="ns1:Item[10]" xsi:type="ns1:ItemArray"><item xsi:type="ns1:Item"><text xsi:type="xsd:string">text0</text></item><item xsi:type="ns1:Item"><text xsi:type="xsd:string">text1</text></item><item xsi:type="ns1:Item"><text xsi:type="xsd:string">text2</text></item><item xsi:type="ns1:Item"><text xsi:type="xsd:string">text3</text></item><item xsi:type="ns1:Item"><text xsi:type="xsd:string">text4</text></item><item xsi:type="ns1:Item"><text xsi:type="xsd:string">text5</text></item><item xsi:type="ns1:Item"><text xsi:type="xsd:string">text6</text></item><item xsi:type="ns1:Item"><text xsi:type="xsd:string">text7</text></item><item xsi:type="ns1:Item"><text xsi:type="xsd:string">text8</text></item><item xsi:type="ns1:Item"><text xsi:type="xsd:string">text9</text></item></getItemsReturn></ns1:getItemsResponse></SOAP-ENV:Body></SOAP-ENV:Envelope>
69ok
70