Minor bugfixes of SoapFault handling
SoapFault is now properly prefixed so that SoapFaultSourceGetter identifies them correctly, missing exceptions option is now processed in SoapServer
This commit is contained in:
parent
b45202f40a
commit
ecffdc18fd
|
@ -318,14 +318,14 @@ class SoapClient extends \SoapClient
|
|||
} else if ($curlResponse->curlStatusFailed()) {
|
||||
|
||||
return $this->throwSoapFaultByTracing(
|
||||
SoapFaultPrefixEnum::PREFIX_DEFAULT.'-'.SoapFaultEnum::SOAP_FAULT_HTTP.'-'.$curlResponse->getHttpResponseStatusCode(),
|
||||
SoapFaultEnum::SOAP_FAULT_HTTP.'-'.$curlResponse->getHttpResponseStatusCode(),
|
||||
$curlResponse->getCurlErrorMessage(),
|
||||
$soapResponseTracingData
|
||||
);
|
||||
} else {
|
||||
|
||||
return $this->throwSoapFaultByTracing(
|
||||
SoapFaultPrefixEnum::PREFIX_DEFAULT.'-'.SoapFaultEnum::SOAP_FAULT_SOAP_CLIENT_ERROR,
|
||||
SoapFaultEnum::SOAP_FAULT_SOAP_CLIENT_ERROR,
|
||||
'Cannot process curl response with unresolved status: ' . $curlResponse->getCurlStatus(),
|
||||
$soapResponseTracingData
|
||||
);
|
||||
|
|
|
@ -4,7 +4,7 @@ namespace BeSimple\SoapCommon\Fault;
|
|||
|
||||
class SoapFaultEnum
|
||||
{
|
||||
const SOAP_FAULT_WSDL = 'wsdl';
|
||||
const SOAP_FAULT_HTTP = 'http';
|
||||
const SOAP_FAULT_SOAP_CLIENT_ERROR = 'soap-client-error';
|
||||
const SOAP_FAULT_WSDL = SoapFaultPrefixEnum::PREFIX_DEFAULT.'-'.'wsdl';
|
||||
const SOAP_FAULT_HTTP = SoapFaultPrefixEnum::PREFIX_DEFAULT.'-'.'http';
|
||||
const SOAP_FAULT_SOAP_CLIENT_ERROR = SoapFaultPrefixEnum::PREFIX_DEFAULT.'-'.'soap-client-error';
|
||||
}
|
||||
|
|
|
@ -13,13 +13,13 @@ class SoapFaultSourceGetter
|
|||
|
||||
public static function isBeSimpleSoapFault(SoapFault $soapFault)
|
||||
{
|
||||
$defaultPrefix = SoapFaultPrefixEnum::PREFIX_DEFAULT;
|
||||
$nativeSoapFaultPrefix = SoapFaultPrefixEnum::PREFIX_DEFAULT.'-';
|
||||
|
||||
if (strpos($soapFault->getCode(), $defaultPrefix) === 0) {
|
||||
if (strpos($soapFault->faultcode, $nativeSoapFaultPrefix) === 0) {
|
||||
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -121,6 +121,7 @@ class SoapServerOptions
|
|||
{
|
||||
$optionsAsArray = [
|
||||
'keep_alive' => $this->isKeepAlive(),
|
||||
'exceptions' => $this->isExceptions(),
|
||||
];
|
||||
|
||||
return $optionsAsArray;
|
||||
|
|
|
@ -0,0 +1,64 @@
|
|||
<?php
|
||||
|
||||
namespace BeSimple\SoapCommon\Fault;
|
||||
|
||||
use PHPUnit_Framework_TestCase;
|
||||
use SoapFault;
|
||||
|
||||
class SoapFaultSourceGetterTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
const FIXTURES_DIR = __DIR__ . '/../../Fixtures';
|
||||
|
||||
/**
|
||||
* @param SoapFault $soapFault
|
||||
* @dataProvider provideNativeSoapFaults
|
||||
*/
|
||||
public function testWithNativeSoapFault(SoapFault $soapFault)
|
||||
{
|
||||
self::assertTrue(SoapFaultSourceGetter::isNativeSoapFault($soapFault));
|
||||
self::assertFalse(SoapFaultSourceGetter::isBeSimpleSoapFault($soapFault));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param SoapFault $soapFault
|
||||
* @dataProvider provideBeSimpleSoapFaults
|
||||
*/
|
||||
public function testWithBeSimpleSoapFault(SoapFault $soapFault)
|
||||
{
|
||||
self::assertFalse(SoapFaultSourceGetter::isNativeSoapFault($soapFault));
|
||||
self::assertTrue(SoapFaultSourceGetter::isBeSimpleSoapFault($soapFault));
|
||||
}
|
||||
|
||||
public function provideNativeSoapFaults()
|
||||
{
|
||||
return [
|
||||
[$this->getNativeSoapFaultFromClient()],
|
||||
// @todo: add more test cases for Soap Server \SoapFault
|
||||
];
|
||||
}
|
||||
|
||||
public function provideBeSimpleSoapFaults()
|
||||
{
|
||||
return [
|
||||
[new SoapFault(SoapFaultEnum::SOAP_FAULT_HTTP, 'HTTP Connection error')],
|
||||
[new SoapFault(SoapFaultEnum::SOAP_FAULT_SOAP_CLIENT_ERROR, 'SOAP Client error')],
|
||||
[new SoapFault(SoapFaultEnum::SOAP_FAULT_WSDL, 'WSDL error')],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return SoapFault
|
||||
*/
|
||||
private function getNativeSoapFaultFromClient()
|
||||
{
|
||||
try {
|
||||
$soapClient = @new \SoapClient('non-existing-wsdl-throwing-soapfault');
|
||||
$soapClient->__call('no-function', []);
|
||||
} catch (SoapFault $e) {
|
||||
|
||||
return $e;
|
||||
}
|
||||
|
||||
self::fail('Cannot generate native PHP SoapFault from Client, please review the test');
|
||||
}
|
||||
}
|
|
@ -24,7 +24,6 @@ class SoapServerAndSoapClientCommunicationTest extends PHPUnit_Framework_TestCas
|
|||
const CACHE_DIR = __DIR__ . '/../../cache';
|
||||
const FIXTURES_DIR = __DIR__ . '/../Fixtures';
|
||||
const TEST_HTTP_URL = 'http://localhost:8000/tests';
|
||||
const TEST_LOCAL_WSDL_UK = SoapClientBuilderTest::TEST_LOCAL_WSDL_UK;
|
||||
const LARGE_SWA_FILE = self::FIXTURES_DIR.'/large-test-file.docx';
|
||||
|
||||
private $localWebServerProcess;
|
||||
|
|
Loading…
Reference in New Issue