xref: /PHP-8.2/ext/soap/tests/bugs/bug50762.phpt (revision 8b561d33)
1--TEST--
2Bug #50762 (in WSDL mode Soap Header handler function only being called if defined in WSDL)
3--EXTENSIONS--
4soap
5--FILE--
6<?php
7class testSoap {
8    private $auth;
9    public function authToken($token){
10        $this->auth=true;
11    }
12    public function testHeader($param){
13        return 'header handler ' . ($this->auth ? 'called' : 'not called');
14    }
15}
16
17class LocalSoapClient extends SoapClient {
18  private $server;
19
20  function __construct($wsdl, $options) {
21    parent::__construct($wsdl, $options);
22    $this->server = new SoapServer($wsdl, $options);
23    $this->server->setObject(new testSoap());
24  }
25
26  function __doRequest($request, $location, $action, $version, $one_way = 0): ?string {
27    ob_start();
28    $this->server->handle($request);
29    $response = ob_get_contents();
30    ob_end_clean();
31    return $response;
32  }
33
34}
35
36$cl = new LocalSoapClient(__DIR__.'/bug50762.wsdl', array('cache_wsdl'=>WSDL_CACHE_NONE, 'trace'=>true));
37
38class authToken {
39    public function __construct(public $authToken) {}
40}
41
42$cl->__setSoapHeaders(array(new SoapHeader('http://sova.pronto.ru/', 'authToken', new authToken('tokendata'))));
43echo $cl->testHeader('param') . PHP_EOL;
44?>
45--EXPECT--
46header handler called
47