SoapFault handling refactored: client now returns server fault codes + more details in message
This commit is contained in:
25
tests/BeSimple/SoapCommon/Fault/SoapFaultParserTest.php
Normal file
25
tests/BeSimple/SoapCommon/Fault/SoapFaultParserTest.php
Normal file
@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
namespace BeSimple\SoapCommon\Fault;
|
||||
|
||||
use PHPUnit_Framework_TestCase;
|
||||
use SoapFault;
|
||||
|
||||
class SoapFaultParserTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function testParse()
|
||||
{
|
||||
$soapFaultXml = '<?xml version="1.0" encoding="UTF-8"?><SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"><SOAP-ENV:Body><SOAP-ENV:Fault><faultcode>911</faultcode><faultstring>This is a dummy SoapFault.</faultstring></SOAP-ENV:Fault></SOAP-ENV:Body></SOAP-ENV:Envelope>';
|
||||
$soapFault = SoapFaultParser::parseSoapFault($soapFaultXml);
|
||||
|
||||
self::assertInstanceOf(SoapFault::class, $soapFault);
|
||||
self::assertEquals(
|
||||
'911',
|
||||
$soapFault->faultcode
|
||||
);
|
||||
self::assertEquals(
|
||||
'This is a dummy SoapFault.',
|
||||
$soapFault->getMessage()
|
||||
);
|
||||
}
|
||||
}
|
@ -17,6 +17,7 @@ use Fixtures\DummyServiceMethodWithIncomingLargeSwaRequest;
|
||||
use Fixtures\DummyServiceMethodWithOutgoingLargeSwaRequest;
|
||||
use Fixtures\GenerateTestRequest;
|
||||
use PHPUnit_Framework_TestCase;
|
||||
use SoapFault;
|
||||
use SoapHeader;
|
||||
|
||||
class SoapServerAndSoapClientCommunicationTest extends PHPUnit_Framework_TestCase
|
||||
@ -124,6 +125,44 @@ class SoapServerAndSoapClientCommunicationTest extends PHPUnit_Framework_TestCas
|
||||
);
|
||||
}
|
||||
|
||||
public function testSoapCallSwaWithLargeSwaResponseWithSoapFault()
|
||||
{
|
||||
$soapClient = $this->getSoapBuilder()->buildWithSoapHeader(
|
||||
SoapClientOptionsBuilder::createWithEndpointLocation(
|
||||
self::TEST_HTTP_URL.'/SwaSenderSoapFaultEndpoint.php'
|
||||
),
|
||||
SoapOptionsBuilder::createSwaWithClassMap(
|
||||
self::TEST_HTTP_URL.'/SwaSenderEndpoint.php?wsdl',
|
||||
new ClassMap([
|
||||
'GenerateTestRequest' => GenerateTestRequest::class,
|
||||
]),
|
||||
SoapOptions::SOAP_CACHE_TYPE_NONE
|
||||
),
|
||||
new SoapHeader('http://schema.testcase', 'SoapHeader', [
|
||||
'user' => 'admin',
|
||||
])
|
||||
);
|
||||
|
||||
$this->setExpectedException(SoapFault::class);
|
||||
|
||||
try {
|
||||
$soapClient->soapCall('dummyServiceMethodWithOutgoingLargeSwa', []);
|
||||
} catch (SoapFault $e) {
|
||||
self::assertEquals(
|
||||
'911',
|
||||
$e->faultcode
|
||||
);
|
||||
self::assertEquals(
|
||||
'SOAP HTTP call failed: Curl error "0" with message: occurred while connecting to http://localhost:8000/tests/SwaSenderSoapFaultEndpoint.php with HTTP response code 500 with Message: This is a dummy SoapFault. and Code: 911',
|
||||
$e->getMessage()
|
||||
);
|
||||
|
||||
throw $e;
|
||||
}
|
||||
|
||||
self::fail('Expected SoapFault was not thrown');
|
||||
}
|
||||
|
||||
public function testSoapCallWithLargeSwaRequest()
|
||||
{
|
||||
$soapClient = $this->getSoapBuilder()->buildWithSoapHeader(
|
||||
|
9
tests/SwaSenderSoapFaultEndpoint.php
Normal file
9
tests/SwaSenderSoapFaultEndpoint.php
Normal file
@ -0,0 +1,9 @@
|
||||
<?php
|
||||
|
||||
const FIXTURES_DIR = __DIR__.'/Fixtures';
|
||||
|
||||
$soapServer = new \SoapServer(FIXTURES_DIR.'/DummyService.wsdl');
|
||||
$soapServer->fault(
|
||||
911,
|
||||
'This is a dummy SoapFault.'
|
||||
);
|
Reference in New Issue
Block a user