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