xref: /PHP-8.0/ext/soap/tests/bug47021.phpt (revision 95f25837)
1--TEST--
2Bug #47021 SoapClient (SoapClient stumbles over WSDL delivered with "Transfer-Encoding: chunked")
3--INI--
4soap.wsdl_cache_enabled=0
5--SKIPIF--
6<?php
7require 'skipif.inc';
8require __DIR__.'/../../standard/tests/http/server.inc';
9http_server_skipif();
10--FILE--
11<?php
12require __DIR__.'/../../standard/tests/http/server.inc';
13
14function chunk_body($body, $n)
15{
16    $chunks = str_split($body, $n);
17    $chunks[] = '';
18
19    foreach ($chunks as $k => $v) {
20        $chunks[$k] = sprintf("%08x\r\n%s\r\n", strlen($v), $v);
21    }
22
23    return join('', $chunks);
24}
25
26$wsdl = file_get_contents(__DIR__.'/server030.wsdl');
27
28$soap = <<<EOF
29<?xml version="1.0" encoding="UTF-8"?>
30<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>
31EOF;
32
33$responses = [
34    "data://text/plain,HTTP/1.1 200 OK\r\n".
35    "Content-Type: text/xml;charset=utf-8\r\n".
36    "Transfer-Encoding: \t  chunked\t \r\n".
37    "Connection: close\r\n".
38    "\r\n".
39    chunk_body($wsdl, 64),
40    "data://text/plain,HTTP/1.1 200 OK\r\n".
41    "Content-Type: text/xml;charset=utf-8\r\n".
42    "Transfer-Encoding: \t  chunked\t \r\n".
43    "Connection: close\r\n".
44    "\r\n".
45    chunk_body($soap, 156),
46];
47
48
49['pid' => $pid, 'uri' => $uri] = http_server($responses);
50
51$options = [
52    'trace' => true,
53    'location' => $uri,
54];
55
56class BugSoapClient extends SoapClient
57{
58    public function __doRequest($request, $location, $action, $version, $one_way = null)
59    {
60        $response = parent::__doRequest($request, $location, $action, $version, $one_way);
61
62        var_dump(strlen($response));
63
64        return $response;
65    }
66}
67
68$client = new BugSoapClient($uri, $options);
69
70var_dump(count($client->getItems()));
71
72http_server_kill($pid);
73
74--EXPECT--
75int(1291)
76int(10)
77