xref: /PHP-8.2/ext/soap/tests/bugs/bug36226-2.phpt (revision 8b561d33)
1--TEST--
2Bug #36226 (Inconsistent handling when passing nillable arrays)
3--EXTENSIONS--
4soap
5--INI--
6soap.wsdl_cache_enabled=0
7--FILE--
8<?php
9$timestamp = "2005-11-08T11:22:07+03:00";
10$wsdl = __DIR__."/bug36226-2.wsdl";
11
12function PostEvents($x) {
13  var_dump($x);
14  exit();
15  return $x;
16}
17
18class TestSoapClient extends SoapClient {
19  private $server;
20
21  function __construct($wsdl, $options) {
22    parent::__construct($wsdl, $options);
23    $this->server = new SoapServer($wsdl, $options);
24    $this->server->addFunction('PostEvents');
25  }
26
27  function __doRequest($request, $location, $action, $version, $one_way = 0): ?string {
28    echo "$request\n";
29    $this->server->handle($request);
30    return $response;
31  }
32}
33
34$soapClient = new TestSoapClient($wsdl,
35  array(
36    'trace' => 1,
37    'exceptions' => 0,
38    'classmap' => array(
39      'logOnEvent' => 'LogOnEvent',
40      'logOffEvent' => 'LogOffEvent',
41      'events' => 'IVREvents'
42    ),
43    'features' => SOAP_SINGLE_ELEMENT_ARRAYS
44  ));
45
46$logOnEvent = null;
47//$logOnEvent = array();
48$logOffEvents[] = new LogOffEvent(34567, $timestamp, "Smoked");
49//$logOffEvents[] = new LogOffEvent(34568, $timestamp, "SmokeFree");
50$ivrEvents = new IVREvents("1.0", 101, 12345, 'IVR', $logOnEvent, $logOffEvents);
51$result = $soapClient->PostEvents($ivrEvents);
52
53class LogOffEvent {
54  public $audienceMemberId;
55  public $timestamp;
56  public $smokeStatus;
57  public $callInitiator;
58
59  function __construct($audienceMemberId, $timestamp, $smokeStatus) {
60    $this->audienceMemberId = $audienceMemberId;
61    $this->timestamp = $timestamp;
62    $this->smokeStatus = $smokeStatus;
63    $this->callInitiator = "IVR";
64  }
65}
66
67class LogOnEvent {
68  public $audienceMemberId;
69  public $timestamp;
70
71  function __construct($audienceMemberId, $timestamp) {
72    $this->audienceMemberId = $audienceMemberId;
73    $this->timestamp = $timestamp;
74  }
75}
76
77class IVREvents {
78  public $version;
79  public $activityId;
80  public $messageId;
81  public $source;
82  public $logOnEvent;
83  public $logOffEvent;
84
85  function __construct($version, $activityId, $messageId, $source, $logOnEvent=NULL, $logOffEvent=NULL) {
86    $this->version = $version;
87    $this->activityId = $activityId;
88    $this->messageId = $messageId;
89    $this->source = $source;
90    $this->logOnEvent = $logOnEvent;
91    $this->logOffEvent = $logOffEvent;
92  }
93
94}
95?>
96--EXPECT--
97<?xml version="1.0" encoding="UTF-8"?>
98<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://testurl/Message" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><SOAP-ENV:Body><ns1:ivrEvents version="1.0" activityId="101" messageId="12345" source="IVR"><ns1:logOffEvent audienceMemberId="34567" timestamp="2005-11-08T11:22:07+03:00" smokeStatus="Smoked" callInitiator="IVR"/><ns1:logOnEvent xsi:nil="true"/></ns1:ivrEvents></SOAP-ENV:Body></SOAP-ENV:Envelope>
99
100object(IVREvents)#5 (6) {
101  ["version"]=>
102  string(3) "1.0"
103  ["activityId"]=>
104  int(101)
105  ["messageId"]=>
106  int(12345)
107  ["source"]=>
108  string(3) "IVR"
109  ["logOnEvent"]=>
110  NULL
111  ["logOffEvent"]=>
112  array(1) {
113    [0]=>
114    object(LogOffEvent)#6 (4) {
115      ["audienceMemberId"]=>
116      int(34567)
117      ["timestamp"]=>
118      string(25) "2005-11-08T11:22:07+03:00"
119      ["smokeStatus"]=>
120      string(6) "Smoked"
121      ["callInitiator"]=>
122      string(3) "IVR"
123    }
124  }
125}
126