Closed 4n70w4 closed 4 years ago
Good question!
Did you try using the second argument of json_encode, JSON_FORCE_OBJECT, to see the output?
Maybe it will help having more clues...
Moreover, I currrently can't tell how the Mockery works and if it affects the results or not...
I just had a flash! You must ensure that the value SOAP_SINGLE_ELEMENT_ARRAYS is defined for the features
SoapClient option which is set when using the PackageBase classes, as you can see at https://github.com/WsdlToPhp/PackageBase/blob/develop/src/AbstractSoapClientBase.php#L165. By default with the PackageBase, arrays elements are always returned as an array even if there is only one element in the array in order to preserve consistency.
Be sure it is the case when mocking the SoapClient.
@mikaelcom thanks!
Just need add features
option.
$soapClient = \Mockery::mock(SoapClient::class, [$str, ['features' => SOAP_SINGLE_ELEMENT_ARRAYS | SOAP_USE_XSI_ARRAY_TYPE, 'classmap' => ClassMap::get()]])->makePartial();
Great! I let you close the issue then if applicable.
Hi! Help me understand why this magic happens. Perhaps I somehow did the test wrong. But it's confusing that the difference is just wrapping in an array.
Also i tried 3.2.1 and the same result.
I have response from production:
https://gist.github.com/4n70w4/2acd951e312264b414e721319ee32625
json_encode($result)
:https://gist.github.com/4n70w4/1d432a52f626d96779d6755936b66e8a
Also i make unit test and mock
__doRequest
of\SoapClient
. But in this casejson_encode($result)
have differents:https://gist.github.com/4n70w4/8ace5f896ef557d8e312e56ad1a2082d
In production case
$.CreateNonActiveSubscriberResult.ValidationResult.Fields.ModelValidationResult
isarray of object
, but in mock case it isobject
.My test method:
I try native
\WsdlToPhp\PackageBase\AbstractSoapClientBase
and\SoapClient
and my ownSoapClientBase extends AbstractSoapClientBase
andSoapClient extends \SoapClient
but the same results. I have no idea what else to try tuning.https://service.synerdocs.ru/ExchangeService.svc?wsdl