2011-10-09 19:41:56 +02:00
|
|
|
<?php
|
|
|
|
|
2017-03-15 10:25:48 +01:00
|
|
|
namespace BeSimple\SoapServer;
|
|
|
|
|
|
|
|
use BeSimple\SoapClient\SoapClientBuilderTest;
|
2017-02-03 15:22:37 +01:00
|
|
|
use BeSimple\SoapCommon\ClassMap;
|
|
|
|
use BeSimple\SoapCommon\SoapOptionsBuilder;
|
2017-03-15 10:25:48 +01:00
|
|
|
use Fixtures\DummyService;
|
|
|
|
use Fixtures\SoapServerHandler;
|
|
|
|
use PHPUnit_Framework_TestCase;
|
|
|
|
|
|
|
|
class SoapServerTest extends PHPUnit_Framework_TestCase
|
2011-10-09 19:41:56 +02:00
|
|
|
{
|
2017-03-15 10:25:48 +01:00
|
|
|
const CACHE_DIR = __DIR__ . '/../../../cache';
|
|
|
|
const FIXTURES_DIR = __DIR__ . '/../../Fixtures';
|
2017-02-03 15:22:37 +01:00
|
|
|
const TEST_LOCAL_WSDL_UK = SoapClientBuilderTest::TEST_LOCAL_WSDL_UK;
|
|
|
|
|
2017-03-15 10:25:48 +01:00
|
|
|
public function testCreateRequest()
|
2011-10-09 19:41:56 +02:00
|
|
|
{
|
2017-02-03 15:22:37 +01:00
|
|
|
$soapServer = $this->getSoapServerBuilder()->build(
|
2017-03-15 10:25:48 +01:00
|
|
|
SoapServerOptionsBuilder::createWithDefaults(new SoapServerHandler()),
|
2017-02-03 15:22:37 +01:00
|
|
|
SoapOptionsBuilder::createWithDefaults(self::TEST_LOCAL_WSDL_UK)
|
|
|
|
);
|
|
|
|
$soapRequest = $soapServer->createRequest('request-url', 'soap-action', 'content/type', 'request-content');
|
2011-10-09 19:41:56 +02:00
|
|
|
|
2017-02-03 15:22:37 +01:00
|
|
|
self::assertEquals('content/type', $soapRequest->getContentType());
|
|
|
|
self::assertEquals('soap-action', $soapRequest->getAction());
|
|
|
|
self::assertEquals('request-content', $soapRequest->getContent());
|
|
|
|
self::assertFalse($soapRequest->hasAttachments());
|
|
|
|
self::assertNull($soapRequest->getAttachments());
|
2011-10-09 19:41:56 +02:00
|
|
|
}
|
|
|
|
|
2017-02-03 15:22:37 +01:00
|
|
|
public function testHandleRequest()
|
2011-10-09 19:41:56 +02:00
|
|
|
{
|
2017-02-03 15:22:37 +01:00
|
|
|
$dummyService = new DummyService();
|
|
|
|
$classMap = new ClassMap();
|
|
|
|
foreach ($dummyService->getClassMap() as $type => $className) {
|
|
|
|
$classMap->add($type, $className);
|
|
|
|
}
|
|
|
|
$soapServerBuilder = new SoapServerBuilder();
|
|
|
|
$soapServerOptions = SoapServerOptionsBuilder::createWithDefaults($dummyService);
|
|
|
|
$soapOptions = SoapOptionsBuilder::createWithClassMap($dummyService->getWsdlPath(), $classMap);
|
|
|
|
$soapServer = $soapServerBuilder->build($soapServerOptions, $soapOptions);
|
|
|
|
|
|
|
|
$request = $soapServer->createRequest(
|
|
|
|
$dummyService->getEndpoint(),
|
|
|
|
'DummyService.dummyServiceMethod',
|
|
|
|
'text/xml;charset=UTF-8',
|
2017-04-04 18:36:18 +02:00
|
|
|
file_get_contents(self::FIXTURES_DIR.'/Message/Request/dummyServiceMethod.message.request')
|
2017-02-03 15:22:37 +01:00
|
|
|
);
|
|
|
|
$response = $soapServer->handleRequest($request);
|
|
|
|
|
|
|
|
file_put_contents(self::CACHE_DIR . '/SoapServerTestResponse.xml', $response->getContent());
|
|
|
|
|
|
|
|
self::assertNotContains("\r\n", $response->getContent(), 'Response cannot contain CRLF line endings');
|
|
|
|
self::assertContains('dummyServiceMethodResponse', $response->getContent());
|
|
|
|
self::assertSame('DummyService.dummyServiceMethod', $response->getAction());
|
|
|
|
self::assertFalse($response->hasAttachments(), 'Response should not contain attachments');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testHandleRequestWithSwa()
|
|
|
|
{
|
|
|
|
$dummyService = new DummyService();
|
|
|
|
$classMap = new ClassMap();
|
|
|
|
foreach ($dummyService->getClassMap() as $type => $className) {
|
|
|
|
$classMap->add($type, $className);
|
|
|
|
}
|
|
|
|
$soapServerBuilder = new SoapServerBuilder();
|
|
|
|
$soapServerOptions = SoapServerOptionsBuilder::createWithDefaults($dummyService);
|
|
|
|
$soapOptions = SoapOptionsBuilder::createSwaWithClassMap($dummyService->getWsdlPath(), $classMap);
|
|
|
|
$soapServer = $soapServerBuilder->build($soapServerOptions, $soapOptions);
|
|
|
|
|
|
|
|
$request = $soapServer->createRequest(
|
|
|
|
$dummyService->getEndpoint(),
|
|
|
|
'DummyService.dummyServiceMethodWithAttachments',
|
|
|
|
'text/xml;charset=UTF-8',
|
2017-04-04 18:36:18 +02:00
|
|
|
file_get_contents(self::FIXTURES_DIR.'/Message/Request/dummyServiceMethodWithAttachments.request.message')
|
2017-02-03 15:22:37 +01:00
|
|
|
);
|
|
|
|
$response = $soapServer->handleRequest($request);
|
|
|
|
|
|
|
|
file_put_contents(self::CACHE_DIR . '/SoapServerTestResponseFromSwaRequestWithNoAttachments.xml', $response->getContent());
|
|
|
|
|
|
|
|
self::assertNotContains("\r\n", $response->getContent(), 'Response cannot contain CRLF line endings');
|
|
|
|
self::assertContains('dummyServiceMethodWithAttachmentsResponse', $response->getContent());
|
|
|
|
self::assertSame('DummyService.dummyServiceMethodWithAttachments', $response->getAction());
|
2017-04-04 18:36:18 +02:00
|
|
|
self::assertFalse($response->hasAttachments(), 'Response should not contain attachments');
|
2017-02-03 15:22:37 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testHandleRequestWithSwaResponse()
|
|
|
|
{
|
|
|
|
$dummyService = new DummyService();
|
|
|
|
$classMap = new ClassMap();
|
|
|
|
foreach ($dummyService->getClassMap() as $type => $className) {
|
|
|
|
$classMap->add($type, $className);
|
|
|
|
}
|
|
|
|
$soapServerBuilder = new SoapServerBuilder();
|
|
|
|
$soapServerOptions = SoapServerOptionsBuilder::createWithDefaults($dummyService);
|
|
|
|
$soapOptions = SoapOptionsBuilder::createSwaWithClassMap($dummyService->getWsdlPath(), $classMap);
|
|
|
|
$soapServer = $soapServerBuilder->build($soapServerOptions, $soapOptions);
|
|
|
|
|
|
|
|
$request = $soapServer->createRequest(
|
|
|
|
$dummyService->getEndpoint(),
|
|
|
|
'DummyService.dummyServiceMethodWithAttachments',
|
|
|
|
'multipart/related; type="text/xml"; start="<rootpart@soapui.org>"; boundary="----=_Part_6_2094841787.1482231370463"',
|
2017-04-04 18:36:18 +02:00
|
|
|
file_get_contents(self::FIXTURES_DIR.'/Message/Request/dummyServiceMethodWithAttachments.request.mimepart.message')
|
2017-02-03 15:22:37 +01:00
|
|
|
);
|
|
|
|
$response = $soapServer->handleRequest($request);
|
|
|
|
|
|
|
|
file_put_contents(self::CACHE_DIR . '/SoapServerTestSwaResponseWithAttachments.xml', $response->getContent());
|
2011-10-09 19:41:56 +02:00
|
|
|
|
2017-02-03 15:22:37 +01:00
|
|
|
self::assertNotContains("\r\n", $response->getContent(), 'Response cannot contain CRLF line endings');
|
|
|
|
self::assertContains('dummyServiceMethodWithAttachmentsResponse', $response->getContent());
|
|
|
|
self::assertSame('DummyService.dummyServiceMethodWithAttachments', $response->getAction());
|
|
|
|
self::assertTrue($response->hasAttachments(), 'Response should contain attachments');
|
|
|
|
self::assertCount(2, $response->getAttachments());
|
2011-10-09 19:41:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public function getSoapServerBuilder()
|
|
|
|
{
|
|
|
|
return new SoapServerBuilder();
|
|
|
|
}
|
2013-07-19 11:28:23 +02:00
|
|
|
}
|