|
| 1 | +--TEST-- |
| 2 | +GH-15711 (SoapClient can't convert BackedEnum to scalar value) |
| 3 | +--EXTENSIONS-- |
| 4 | +soap |
| 5 | +--INI-- |
| 6 | +soap.wsdl_cache_enabled=0 |
| 7 | +--FILE-- |
| 8 | +<?php |
| 9 | + |
| 10 | +enum TestBackedEnum: string |
| 11 | +{ |
| 12 | + case First = 'BackingValue1'; |
| 13 | + case Second = 'BackingValue2'; |
| 14 | + case Third = 'BackingValue3'; |
| 15 | + case Fourth = 'BackingValue4'; |
| 16 | + case Fifth = 'BackingValue5'; |
| 17 | +} |
| 18 | + |
| 19 | +enum TestNonBackedEnum |
| 20 | +{ |
| 21 | + case First; |
| 22 | +} |
| 23 | + |
| 24 | +class TestSoapClient extends SoapClient { |
| 25 | + function __doRequest($request, $location, $action, $version, $one_way = 0): ?string { |
| 26 | + echo $request; |
| 27 | + } |
| 28 | +} |
| 29 | + |
| 30 | +$client = new TestSoapClient('ext/soap/tests/gh15711.wsdl', ['classmap' => ['book' => 'book']]); |
| 31 | + |
| 32 | +echo "--- Test with backed enum ---\n"; |
| 33 | + |
| 34 | +$book = new stdClass(); |
| 35 | +$book->base64 = TestBackedEnum::First; |
| 36 | +$book->string = TestBackedEnum::Second; |
| 37 | +$book->any = TestBackedEnum::Third; |
| 38 | +$book->hexbin = TestBackedEnum::Fourth; |
| 39 | +$book->nmtokens = TestBackedEnum::Fifth; |
| 40 | + |
| 41 | +try { |
| 42 | + $client->dotest($book); |
| 43 | +} catch (Throwable) {} |
| 44 | + |
| 45 | +echo "--- Test with non-backed enum ---\n"; |
| 46 | + |
| 47 | +$book = new stdClass(); |
| 48 | +$book->base64 = TestNonBackedEnum::First; |
| 49 | +$book->string = TestNonBackedEnum::First; |
| 50 | +$book->any = TestNonBackedEnum::First; |
| 51 | +$book->hexbin = TestNonBackedEnum::First; |
| 52 | +$book->nmtokens = TestNonBackedEnum::First; |
| 53 | + |
| 54 | +try { |
| 55 | + $client->dotest($book); |
| 56 | +} catch (ValueError $e) { |
| 57 | + echo "ValueError: ", $e->getMessage(), "\n"; |
| 58 | +} |
| 59 | + |
| 60 | +?> |
| 61 | +--EXPECT-- |
| 62 | +--- Test with backed enum --- |
| 63 | +<?xml version="1.0" encoding="UTF-8"?> |
| 64 | +<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://schemas.nothing.com" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"><SOAP-ENV:Body><ns1:dotest><dotestReturn xsi:type="ns1:book"><base64 xsi:type="xsd:base64Binary">QmFja2luZ1ZhbHVlMQ==</base64><string xsi:type="xsd:string">BackingValue2</string><any xsi:type="xsd:any"><name xsi:type="xsd:string">Third</name><value xsi:type="xsd:string">BackingValue3</value></any><hexbin xsi:type="xsd:hexBinary">4261636B696E6756616C756534</hexbin><nmtokens>BackingValue5</nmtokens></dotestReturn></ns1:dotest></SOAP-ENV:Body></SOAP-ENV:Envelope> |
| 65 | +--- Test with non-backed enum --- |
| 66 | +ValueError: Non-backed enums have no default serialization |
0 commit comments