xref: /PHP-8.2/ext/soap/tests/bugs/bug31755.phpt (revision f4865010)
1--TEST--
2Bug #31755 (Cannot create SOAP header in no namespace)
3--EXTENSIONS--
4soap
5--FILE--
6<?php
7class MySoapClient extends SoapClient {
8    public function __doRequest($request, $location, $action, $version, $one_way = 0): string {
9        echo $request, "\n";
10        return '';
11    }
12}
13$client = new MySoapClient(null, array(
14    'location' => 'http://localhost', 'uri' => 'myNS', 'exceptions' => false
15));
16
17try {
18    new SOAPHeader('', 'foo', 'bar');
19} catch (ValueError $exception) {
20    echo $exception->getMessage() . "\n";
21}
22
23$header = new SOAPHeader('namespace', 'foo', 'bar');
24$response= $client->__soapCall('function', array(), null, $header);
25
26print $client->__getLastRequest();
27?>
28--EXPECT--
29SoapHeader::__construct(): Argument #1 ($namespace) cannot be empty
30<?xml version="1.0" encoding="UTF-8"?>
31<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="myNS" xmlns:ns2="namespace" 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:Header><ns2:foo>bar</ns2:foo></SOAP-ENV:Header><SOAP-ENV:Body><ns1:function/></SOAP-ENV:Body></SOAP-ENV:Envelope>
32