SoapClient large refactoring & tests update
This commit is contained in:
@ -19,7 +19,7 @@ use BeSimple\SoapCommon\Mime\Part as MimePart;
|
||||
use BeSimple\SoapCommon\Mime\Part;
|
||||
use BeSimple\SoapCommon\SoapRequest;
|
||||
use BeSimple\SoapCommon\SoapRequestFilter;
|
||||
use BeSimple\SoapCommon\SoapResponse;
|
||||
use BeSimple\SoapCommon\SoapResponse as CommonSoapResponse;
|
||||
use BeSimple\SoapCommon\SoapResponseFilter;
|
||||
|
||||
/**
|
||||
@ -47,7 +47,7 @@ class MimeFilter implements SoapRequestFilter, SoapResponseFilter
|
||||
return $request;
|
||||
}
|
||||
|
||||
public function filterResponse(SoapResponse $response, $attachmentType)
|
||||
public function filterResponse(CommonSoapResponse $response, $attachmentType)
|
||||
{
|
||||
$attachmentsToSend = $response->getAttachments();
|
||||
if (count($attachmentsToSend) > 0) {
|
||||
|
@ -13,24 +13,30 @@
|
||||
namespace BeSimple\SoapServer;
|
||||
|
||||
use BeSimple\SoapBundle\Soap\SoapAttachment;
|
||||
use BeSimple\SoapCommon\Mime\Part;
|
||||
use BeSimple\SoapClient\SoapResponseTracingData;
|
||||
use BeSimple\SoapCommon\Mime\PartFactory;
|
||||
use BeSimple\SoapCommon\SoapMessage;
|
||||
|
||||
class SoapResponseFactory
|
||||
{
|
||||
/**
|
||||
* Factory function for SoapResponse.
|
||||
* Factory function for SoapServer\SoapResponse.
|
||||
*
|
||||
* @param string $content Content
|
||||
* @param string $location Location
|
||||
* @param string $action SOAP action
|
||||
* @param string $version SOAP version
|
||||
* @param SoapAttachment[] $attachments SOAP attachments
|
||||
* @param string $content Content
|
||||
* @param string $location Location
|
||||
* @param string $action SOAP action
|
||||
* @param string $version SOAP version
|
||||
* @param SoapAttachment[] $attachments SOAP attachments
|
||||
*
|
||||
* @return SoapResponse
|
||||
*/
|
||||
public static function create($content, $location, $action, $version, $attachments = [])
|
||||
{
|
||||
public static function create(
|
||||
$content,
|
||||
$location,
|
||||
$action,
|
||||
$version,
|
||||
array $attachments = []
|
||||
) {
|
||||
$response = new SoapResponse();
|
||||
$response->setContent($content);
|
||||
$response->setLocation($location);
|
||||
@ -38,10 +44,9 @@ class SoapResponseFactory
|
||||
$response->setVersion($version);
|
||||
$contentType = SoapMessage::getContentTypeForVersion($version);
|
||||
$response->setContentType($contentType);
|
||||
|
||||
if (count($attachments) > 0) {
|
||||
$response->setAttachments(
|
||||
self::createAttachmentParts($attachments)
|
||||
PartFactory::createAttachmentParts($attachments)
|
||||
);
|
||||
}
|
||||
|
||||
@ -49,23 +54,39 @@ class SoapResponseFactory
|
||||
}
|
||||
|
||||
/**
|
||||
* @param SoapAttachment[] $attachments SOAP attachments
|
||||
* @return Part[]
|
||||
* Factory function for SoapServer\SoapResponse.
|
||||
*
|
||||
* @param string $content Content
|
||||
* @param string $location Location
|
||||
* @param string $action SOAP action
|
||||
* @param string $version SOAP version
|
||||
* @param SoapResponseTracingData $tracingData Data value object suitable for tracing SOAP traffic
|
||||
* @param SoapAttachment[] $attachments SOAP attachments
|
||||
*
|
||||
* @return SoapResponse
|
||||
*/
|
||||
private static function createAttachmentParts(array $attachments = [])
|
||||
{
|
||||
$parts = [];
|
||||
foreach ($attachments as $attachment) {
|
||||
$part = new Part(
|
||||
$attachment->getContent(),
|
||||
'application/pdf',
|
||||
'utf-8',
|
||||
Part::ENCODING_BINARY,
|
||||
$attachment->getId()
|
||||
public static function createWithTracingData(
|
||||
$content,
|
||||
$location,
|
||||
$action,
|
||||
$version,
|
||||
SoapResponseTracingData $tracingData,
|
||||
array $attachments = []
|
||||
) {
|
||||
$response = new SoapResponse();
|
||||
$response->setContent($content);
|
||||
$response->setLocation($location);
|
||||
$response->setAction($action);
|
||||
$response->setVersion($version);
|
||||
$response->setTracingData($tracingData);
|
||||
$contentType = SoapMessage::getContentTypeForVersion($version);
|
||||
$response->setContentType($contentType);
|
||||
if (count($attachments) > 0) {
|
||||
$response->setAttachments(
|
||||
PartFactory::createAttachmentParts($attachments)
|
||||
);
|
||||
$parts[] = $part;
|
||||
}
|
||||
|
||||
return $parts;
|
||||
return $response;
|
||||
}
|
||||
}
|
||||
|
@ -30,7 +30,7 @@ use InvalidArgumentException;
|
||||
*
|
||||
* @author Andreas Schamberger <mail@andreass.net>
|
||||
* @author Christian Kerl <christian-kerl@web.de>
|
||||
* @author Petr Bechyně <petr.bechyne@vodafone.com>
|
||||
* @author Petr Bechyně <mail@petrbechyne.com>
|
||||
*/
|
||||
class SoapServer extends \SoapServer
|
||||
{
|
||||
@ -85,16 +85,15 @@ class SoapServer extends \SoapServer
|
||||
*/
|
||||
public function createRequest($requestUrl, $soapAction, $requestContentType, $requestContent = null)
|
||||
{
|
||||
$soapRequest = SoapRequestFactory::create(
|
||||
$soapRequest = SoapRequestFactory::createWithContentType(
|
||||
$requestUrl,
|
||||
$soapAction,
|
||||
$this->soapVersion,
|
||||
$requestContentType,
|
||||
$requestContent
|
||||
);
|
||||
$soapKernel = new SoapKernel();
|
||||
if ($this->soapOptions->hasAttachments()) {
|
||||
$soapRequest = $soapKernel->filterRequest(
|
||||
$soapRequest = SoapKernel::filterRequest(
|
||||
$soapRequest,
|
||||
$this->getAttachmentFilters(),
|
||||
$this->soapOptions->getAttachmentType()
|
||||
@ -180,7 +179,7 @@ class SoapServer extends \SoapServer
|
||||
* @param SoapAttachment[] $attachments
|
||||
* @return SoapResponse
|
||||
*/
|
||||
private function createResponse($requestLocation, $soapAction, $soapVersion, $responseContent = null, $attachments = [])
|
||||
private function createResponse($requestLocation, $soapAction, $soapVersion, $responseContent = null, array $attachments = [])
|
||||
{
|
||||
$soapResponse = SoapResponseFactory::create(
|
||||
$responseContent,
|
||||
@ -189,9 +188,8 @@ class SoapServer extends \SoapServer
|
||||
$soapVersion,
|
||||
$attachments
|
||||
);
|
||||
$soapKernel = new SoapKernel();
|
||||
if ($this->soapOptions->hasAttachments()) {
|
||||
$soapResponse = $soapKernel->filterResponse(
|
||||
$soapResponse = SoapKernel::filterResponse(
|
||||
$soapResponse,
|
||||
$this->getAttachmentFilters(),
|
||||
$this->soapOptions->getAttachmentType()
|
||||
|
@ -18,7 +18,7 @@ use BeSimple\SoapServer\SoapOptions\SoapServerOptions;
|
||||
/**
|
||||
* SoapServerBuilder provides a SoapServer instance from SoapServerOptions and SoapOptions.
|
||||
*
|
||||
* @author Petr Bechyně <petr.bechyne@vodafone.com>
|
||||
* @author Petr Bechyně <mail@petrbechyne.com>
|
||||
*/
|
||||
class SoapServerBuilder
|
||||
{
|
||||
|
35
src/BeSimple/SoapServer/Tests/Attachment/Attachment.php
Normal file
35
src/BeSimple/SoapServer/Tests/Attachment/Attachment.php
Normal file
@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
namespace BeSimple\SoapServer\Tests\Attachment;
|
||||
|
||||
class Attachment
|
||||
{
|
||||
/**
|
||||
* @var string $fileName
|
||||
*/
|
||||
public $fileName;
|
||||
|
||||
/**
|
||||
* @var string $content
|
||||
*/
|
||||
public $contentType;
|
||||
|
||||
/**
|
||||
* @var string $content
|
||||
*/
|
||||
public $content;
|
||||
|
||||
/**
|
||||
* Attachment constructor.
|
||||
*
|
||||
* @param string $fileName
|
||||
* @param string $contentType
|
||||
* @param string $content
|
||||
*/
|
||||
public function __construct($fileName, $contentType, $content)
|
||||
{
|
||||
$this->fileName = $fileName;
|
||||
$this->contentType = $contentType;
|
||||
$this->content = $content;
|
||||
}
|
||||
}
|
@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
namespace BeSimple\SoapServer\Tests\Attachment;
|
||||
|
||||
class AttachmentCollection
|
||||
{
|
||||
/**
|
||||
* @var Attachment[] $attachments
|
||||
*/
|
||||
public $attachments;
|
||||
|
||||
public function __construct(array $attachments = null)
|
||||
{
|
||||
$this->attachments = $attachments;
|
||||
}
|
||||
|
||||
public function hasAttachments()
|
||||
{
|
||||
return $this->attachments !== null && count($this->attachments) > 0;
|
||||
}
|
||||
}
|
106
src/BeSimple/SoapServer/Tests/DummyService.php
Normal file
106
src/BeSimple/SoapServer/Tests/DummyService.php
Normal file
@ -0,0 +1,106 @@
|
||||
<?php
|
||||
|
||||
namespace BeSimple\SoapServer\Tests;
|
||||
|
||||
use BeSimple\SoapBundle\Soap\SoapAttachment;
|
||||
use BeSimple\SoapCommon\AttachmentsHandlerInterface;
|
||||
use BeSimple\SoapCommon\Storage\RequestHandlerAttachmentsStorage;
|
||||
use BeSimple\SoapServer\Tests\Attachment\Attachment;
|
||||
use BeSimple\SoapServer\Tests\Attachment\AttachmentCollection;
|
||||
use ReflectionClass;
|
||||
|
||||
class DummyService implements AttachmentsHandlerInterface
|
||||
{
|
||||
/** @var RequestHandlerAttachmentsStorage */
|
||||
private $requestHandlerAttachmentsStorage;
|
||||
|
||||
public function addAttachmentStorage(RequestHandlerAttachmentsStorage $requestHandlerAttachmentsStorage)
|
||||
{
|
||||
$this->requestHandlerAttachmentsStorage = $requestHandlerAttachmentsStorage;
|
||||
}
|
||||
|
||||
public function getAttachmentStorage()
|
||||
{
|
||||
return $this->requestHandlerAttachmentsStorage;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string[]
|
||||
*/
|
||||
public function getClassMap()
|
||||
{
|
||||
return [
|
||||
'DummyServiceResponse' => DummyServiceResponse::class,
|
||||
'DummyServiceResponseWithAttachments' => DummyServiceResponseWithAttachments::class,
|
||||
'DummyServiceRequest' => DummyServiceRequest::class,
|
||||
'DummyServiceRequestWithAttachments' => DummyServiceRequestWithAttachments::class,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @exclude
|
||||
* @return string
|
||||
*/
|
||||
public function getWsdlPath()
|
||||
{
|
||||
$class = new ReflectionClass(static::class);
|
||||
|
||||
return __DIR__.DIRECTORY_SEPARATOR.$class->getShortName().'.wsdl';
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getEndpoint()
|
||||
{
|
||||
return 'http://my.test/soap/dummyService';
|
||||
}
|
||||
|
||||
/**
|
||||
* @param DummyServiceRequest $dummyServiceRequest
|
||||
* @return DummyServiceResponse
|
||||
*/
|
||||
public function dummyServiceMethod(DummyServiceRequest $dummyServiceRequest)
|
||||
{
|
||||
$dummyServiceHandler = new DummyServiceHandler();
|
||||
|
||||
return $dummyServiceHandler->handle($dummyServiceRequest);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param DummyServiceRequestWithAttachments $dummyServiceRequestWithAttachments
|
||||
* @return DummyServiceResponseWithAttachments
|
||||
*/
|
||||
public function dummyServiceMethodWithAttachments(DummyServiceRequestWithAttachments $dummyServiceRequestWithAttachments)
|
||||
{
|
||||
if ($dummyServiceRequestWithAttachments->hasAttachments() === true) {
|
||||
$attachmentStorage = $this->getAttachmentStorage();
|
||||
$attachments = [];
|
||||
foreach ($attachmentStorage->getAttachments() as $soapAttachment) {
|
||||
$attachments[] = new Attachment(
|
||||
$soapAttachment->getId(),
|
||||
$soapAttachment->getType(),
|
||||
$soapAttachment->getContent()
|
||||
);
|
||||
}
|
||||
$dummyServiceRequestWithAttachments->attachmentCollection = new AttachmentCollection($attachments);
|
||||
}
|
||||
|
||||
$dummyServiceHandlerWithAttachments = new DummyServiceHandlerWithAttachments();
|
||||
$dummyServiceResponseWithAttachments = $dummyServiceHandlerWithAttachments->handle($dummyServiceRequestWithAttachments);
|
||||
|
||||
if ($dummyServiceResponseWithAttachments->hasAttachments() === true) {
|
||||
$soapAttachments = [];
|
||||
foreach ($dummyServiceResponseWithAttachments->attachmentCollection->attachments as $attachment) {
|
||||
$soapAttachments[] = new SoapAttachment(
|
||||
$attachment->fileName,
|
||||
$attachment->contentType,
|
||||
$attachment->content
|
||||
);
|
||||
}
|
||||
$this->addAttachmentStorage(new RequestHandlerAttachmentsStorage($soapAttachments));
|
||||
}
|
||||
|
||||
return $dummyServiceResponseWithAttachments;
|
||||
}
|
||||
}
|
92
src/BeSimple/SoapServer/Tests/DummyService.wsdl
Normal file
92
src/BeSimple/SoapServer/Tests/DummyService.wsdl
Normal file
@ -0,0 +1,92 @@
|
||||
<?xml version="1.0"?>
|
||||
<wsdl:definitions xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns="http://schemas.xmlsoap.org/wsdl/" xmlns:tns="http://schema.testcase" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" targetNamespace="http://schema.testcase">
|
||||
<wsdl:types>
|
||||
<xsd:schema targetNamespace="http://schema.testcase">
|
||||
<xsd:complexType name="SoapHeaderEntity">
|
||||
<xsd:sequence>
|
||||
<xsd:element name="user" type="xsd:string" minOccurs="1">
|
||||
<xsd:annotation>
|
||||
<xsd:documentation>User name for authorization</xsd:documentation>
|
||||
</xsd:annotation>
|
||||
</xsd:element>
|
||||
</xsd:sequence>
|
||||
</xsd:complexType>
|
||||
<xsd:element name="SoapHeader" type="tns:SoapHeaderEntity"/>
|
||||
<xsd:complexType name="DummyServiceRequest">
|
||||
<xsd:sequence>
|
||||
<xsd:element name="dummyAttribute" type="xsd:int" minOccurs="1"/>
|
||||
</xsd:sequence>
|
||||
</xsd:complexType>
|
||||
<xsd:complexType name="DummyServiceResponse">
|
||||
<xsd:sequence>
|
||||
<xsd:element name="status" type="xsd:boolean" minOccurs="1"/>
|
||||
</xsd:sequence>
|
||||
</xsd:complexType>
|
||||
<xsd:complexType name="DummyServiceRequestWithAttachments">
|
||||
<xsd:sequence>
|
||||
<xsd:element name="dummyAttribute" type="xsd:int" minOccurs="1"/>
|
||||
<xsd:element name="includeAttachments" type="xsd:boolean" minOccurs="1"/>
|
||||
</xsd:sequence>
|
||||
</xsd:complexType>
|
||||
<xsd:complexType name="DummyServiceResponseWithAttachments">
|
||||
<xsd:sequence>
|
||||
<xsd:element name="status" type="xsd:boolean" minOccurs="1"/>
|
||||
</xsd:sequence>
|
||||
</xsd:complexType>
|
||||
</xsd:schema>
|
||||
</wsdl:types>
|
||||
<message name="SoapHeader">
|
||||
<part name="SoapHeader" element="tns:SoapHeader"/>
|
||||
</message>
|
||||
<message name="DummyServiceRequest">
|
||||
<part name="request" type="tns:DummyServiceRequest"/>
|
||||
</message>
|
||||
<message name="DummyServiceRequestWithAttachments">
|
||||
<part name="request" type="tns:DummyServiceRequestWithAttachments"/>
|
||||
</message>
|
||||
<message name="DummyServiceResponse">
|
||||
<part name="dummyServiceReturn" type="tns:DummyServiceResponse"/>
|
||||
</message>
|
||||
<message name="DummyServiceResponseWithAttachments">
|
||||
<part name="dummyServiceReturn" type="tns:DummyServiceResponseWithAttachments"/>
|
||||
</message>
|
||||
<wsdl:portType name="DummyServiceSoapPortType">
|
||||
<wsdl:operation name="dummyServiceMethod">
|
||||
<wsdl:input message="tns:DummyServiceRequest"/>
|
||||
<wsdl:output message="tns:DummyServiceResponse"/>
|
||||
</wsdl:operation>
|
||||
<wsdl:operation name="dummyServiceMethodWithAttachments">
|
||||
<wsdl:input message="tns:DummyServiceRequestWithAttachments"/>
|
||||
<wsdl:output message="tns:DummyServiceResponseWithAttachments"/>
|
||||
</wsdl:operation>
|
||||
</wsdl:portType>
|
||||
<binding name="DummyServiceSoapBinding" type="tns:DummyServiceSoapPortType">
|
||||
<soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/>
|
||||
<wsdl:operation name="dummyServiceMethod">
|
||||
<soap:operation soapAction="DummyService.dummyServiceMethod" style="rpc"/>
|
||||
<wsdl:input>
|
||||
<soap:header use="literal" message="tns:SoapHeader" part="SoapHeader" namespace="http://schema.testcase"/>
|
||||
<soap:body use="literal" part="request" namespace="http://schema.testcase"/>
|
||||
</wsdl:input>
|
||||
<wsdl:output>
|
||||
<soap:body use="literal" namespace="http://schema.testcase"/>
|
||||
</wsdl:output>
|
||||
</wsdl:operation>
|
||||
<wsdl:operation name="dummyServiceMethodWithAttachments">
|
||||
<soap:operation soapAction="DummyService.dummyServiceMethodWithAttachments" style="rpc"/>
|
||||
<wsdl:input>
|
||||
<soap:header use="literal" message="tns:SoapHeader" part="SoapHeader" namespace="http://schema.testcase"/>
|
||||
<soap:body use="literal" part="request" namespace="http://schema.testcase"/>
|
||||
</wsdl:input>
|
||||
<wsdl:output>
|
||||
<soap:body use="literal" namespace="http://schema.testcase"/>
|
||||
</wsdl:output>
|
||||
</wsdl:operation>
|
||||
</binding>
|
||||
<wsdl:service name="DummyService">
|
||||
<xsd:documentation>WSDL file for DummyService</xsd:documentation>
|
||||
<port name="DummyServiceSoapPortType" binding="tns:DummyServiceSoapBinding">
|
||||
<soap:address location="http://schema.testcase"/>
|
||||
</port>
|
||||
</wsdl:service>
|
||||
</wsdl:definitions>
|
18
src/BeSimple/SoapServer/Tests/DummyServiceHandler.php
Normal file
18
src/BeSimple/SoapServer/Tests/DummyServiceHandler.php
Normal file
@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
namespace BeSimple\SoapServer\Tests;
|
||||
|
||||
class DummyServiceHandler
|
||||
{
|
||||
/**
|
||||
* @param DummyServiceRequest
|
||||
* @return DummyServiceResponse
|
||||
*/
|
||||
public function handle(DummyServiceRequest $request)
|
||||
{
|
||||
$response = new DummyServiceResponse();
|
||||
$response->status = true;
|
||||
|
||||
return $response;
|
||||
}
|
||||
}
|
@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace BeSimple\SoapServer\Tests;
|
||||
|
||||
use BeSimple\SoapServer\Tests\Attachment\Attachment;
|
||||
use BeSimple\SoapServer\Tests\Attachment\AttachmentCollection;
|
||||
|
||||
class DummyServiceHandlerWithAttachments
|
||||
{
|
||||
/**
|
||||
* @param DummyServiceRequestWithAttachments $request
|
||||
* @return DummyServiceResponseWithAttachments
|
||||
*/
|
||||
public function handle(DummyServiceRequestWithAttachments $request)
|
||||
{
|
||||
$response = new DummyServiceResponseWithAttachments();
|
||||
$response->status = true;
|
||||
if ($request->includeAttachments === true) {
|
||||
if ($request->hasAttachments() === true) {
|
||||
$attachments = [];
|
||||
foreach ($request->attachmentCollection->attachments as $attachment) {
|
||||
$attachments[] = new Attachment($attachment->fileName, $attachment->contentType, $attachment->content);
|
||||
}
|
||||
$response->attachmentCollection = new AttachmentCollection($attachments);
|
||||
}
|
||||
}
|
||||
|
||||
return $response;
|
||||
}
|
||||
}
|
11
src/BeSimple/SoapServer/Tests/DummyServiceRequest.php
Normal file
11
src/BeSimple/SoapServer/Tests/DummyServiceRequest.php
Normal file
@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace BeSimple\SoapServer\Tests;
|
||||
|
||||
class DummyServiceRequest
|
||||
{
|
||||
/**
|
||||
* @var int $dummyAttribute
|
||||
*/
|
||||
public $dummyAttribute;
|
||||
}
|
@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
namespace BeSimple\SoapServer\Tests;
|
||||
|
||||
use BeSimple\SoapServer\Tests\Attachment\AttachmentCollection;
|
||||
|
||||
class DummyServiceRequestWithAttachments
|
||||
{
|
||||
/**
|
||||
* @var int $dummyAttribute
|
||||
*/
|
||||
public $dummyAttribute;
|
||||
|
||||
/**
|
||||
* @var bool $includeAttachments
|
||||
*/
|
||||
public $includeAttachments;
|
||||
|
||||
/**
|
||||
* @var AttachmentCollection $attachmentCollection
|
||||
*/
|
||||
public $attachmentCollection;
|
||||
|
||||
public function hasAttachments()
|
||||
{
|
||||
return $this->attachmentCollection !== null && $this->attachmentCollection->hasAttachments();
|
||||
}
|
||||
}
|
11
src/BeSimple/SoapServer/Tests/DummyServiceResponse.php
Normal file
11
src/BeSimple/SoapServer/Tests/DummyServiceResponse.php
Normal file
@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace BeSimple\SoapServer\Tests;
|
||||
|
||||
class DummyServiceResponse
|
||||
{
|
||||
/**
|
||||
* @var bool $status
|
||||
*/
|
||||
public $status;
|
||||
}
|
@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
namespace BeSimple\SoapServer\Tests;
|
||||
|
||||
use BeSimple\SoapServer\Tests\Attachment\AttachmentCollection;
|
||||
|
||||
class DummyServiceResponseWithAttachments
|
||||
{
|
||||
/**
|
||||
* @var bool $status
|
||||
*/
|
||||
public $status;
|
||||
|
||||
/**
|
||||
* @var AttachmentCollection $attachmentCollection
|
||||
*/
|
||||
public $attachmentCollection;
|
||||
|
||||
public function hasAttachments()
|
||||
{
|
||||
return $this->attachmentCollection !== null && $this->attachmentCollection->hasAttachments();
|
||||
}
|
||||
}
|
@ -12,30 +12,139 @@
|
||||
|
||||
namespace BeSimple\SoapServer\Tests;
|
||||
|
||||
use BeSimple\SoapClient\Tests\SoapClientBuilderTest;
|
||||
use BeSimple\SoapCommon\ClassMap;
|
||||
use BeSimple\SoapCommon\SoapOptions\SoapOptions;
|
||||
use BeSimple\SoapCommon\SoapOptionsBuilder;
|
||||
use BeSimple\SoapServer\SoapOptions\SoapServerOptions;
|
||||
use BeSimple\SoapServer\SoapServerBuilder;
|
||||
use BeSimple\SoapServer\SoapServerOptionsBuilder;
|
||||
|
||||
/**
|
||||
* UnitTest for \BeSimple\SoapServer\SoapServerBuilder
|
||||
*
|
||||
* @author Christian Kerl <christian-kerl@web.de>
|
||||
* @author Petr Bechyne <mail@petrbechyne.com>
|
||||
*/
|
||||
class SoapServerBuilderTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function testUnconfiguredWsdl()
|
||||
{
|
||||
$builder = $this->getSoapServerBuilder();
|
||||
const TEST_LOCAL_WSDL_UK = SoapClientBuilderTest::TEST_LOCAL_WSDL_UK;
|
||||
const CACHE_DIR = __DIR__ . '/../../../../cache';
|
||||
|
||||
$this->setExpectedException('InvalidArgumentException');
|
||||
$builder->build();
|
||||
public function testSoapOptionsCreateWithDefaults()
|
||||
{
|
||||
$defaultOptions = SoapOptionsBuilder::createWithDefaults(self::TEST_LOCAL_WSDL_UK);
|
||||
|
||||
self::assertInstanceOf(SoapOptions::class, $defaultOptions);
|
||||
self::assertEquals(self::TEST_LOCAL_WSDL_UK, $defaultOptions->getWsdlFile());
|
||||
}
|
||||
|
||||
public function testUnconfiguredHandler()
|
||||
public function testSoapClientOptionsCreateWithDefaults()
|
||||
{
|
||||
$builder = $this->getSoapServerBuilder();
|
||||
$builder->withWsdl('my.wsdl');
|
||||
$defaultOptions = SoapServerOptionsBuilder::createWithDefaults(new SoapServerHandler);
|
||||
|
||||
$this->setExpectedException('InvalidArgumentException');
|
||||
$builder->build();
|
||||
self::assertInstanceOf(SoapServerOptions::class, $defaultOptions);
|
||||
self::assertInstanceOf(SoapServerHandler::class, $defaultOptions->getHandlerInstance());
|
||||
}
|
||||
|
||||
public function testSoapServerBuilderBuild()
|
||||
{
|
||||
$soapServer = $this->getSoapServerBuilder()->build(
|
||||
SoapServerOptionsBuilder::createWithDefaults(new SoapServerHandler),
|
||||
SoapOptionsBuilder::createWithDefaults(self::TEST_LOCAL_WSDL_UK)
|
||||
);
|
||||
$soapRequest = $soapServer->createRequest('request-url', 'soap-action', 'content/type', 'request-content');
|
||||
|
||||
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());
|
||||
}
|
||||
|
||||
public function testHandleRequest()
|
||||
{
|
||||
$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',
|
||||
file_get_contents(__DIR__ . DIRECTORY_SEPARATOR . 'testHandleRequest.message')
|
||||
);
|
||||
$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',
|
||||
file_get_contents(__DIR__ . DIRECTORY_SEPARATOR . 'testHandleRequestWithSwa.message')
|
||||
);
|
||||
$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());
|
||||
self::assertFalse($response->hasAttachments(), 'Response should contain attachments');
|
||||
}
|
||||
|
||||
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"',
|
||||
file_get_contents(__DIR__ . DIRECTORY_SEPARATOR . 'testHandleRequestWithSwa.mimepart.message')
|
||||
);
|
||||
$response = $soapServer->handleRequest($request);
|
||||
|
||||
file_put_contents(self::CACHE_DIR . '/SoapServerTestSwaResponseWithAttachments.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());
|
||||
self::assertTrue($response->hasAttachments(), 'Response should contain attachments');
|
||||
self::assertCount(2, $response->getAttachments());
|
||||
}
|
||||
|
||||
public function getSoapServerBuilder()
|
||||
|
7
src/BeSimple/SoapServer/Tests/SoapServerHandler.php
Normal file
7
src/BeSimple/SoapServer/Tests/SoapServerHandler.php
Normal file
@ -0,0 +1,7 @@
|
||||
<?php
|
||||
|
||||
namespace BeSimple\SoapServer\Tests;
|
||||
|
||||
class SoapServerHandler
|
||||
{
|
||||
}
|
14
src/BeSimple/SoapServer/Tests/testHandleRequest.message
Normal file
14
src/BeSimple/SoapServer/Tests/testHandleRequest.message
Normal file
@ -0,0 +1,14 @@
|
||||
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:sch="http://schema.testcase">
|
||||
<soapenv:Header>
|
||||
<sch:SoapHeader>
|
||||
<user>admin</user>
|
||||
</sch:SoapHeader>
|
||||
</soapenv:Header>
|
||||
<soapenv:Body>
|
||||
<sch:dummyServiceMethod>
|
||||
<request>
|
||||
<dummyAttribute>1</dummyAttribute>
|
||||
</request>
|
||||
</sch:dummyServiceMethod>
|
||||
</soapenv:Body>
|
||||
</soapenv:Envelope>
|
@ -0,0 +1,15 @@
|
||||
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:sch="http://schema.testcase">
|
||||
<soapenv:Header>
|
||||
<sch:SoapHeader>
|
||||
<user>admin</user>
|
||||
</sch:SoapHeader>
|
||||
</soapenv:Header>
|
||||
<soapenv:Body>
|
||||
<sch:dummyServiceMethodWithAttachments>
|
||||
<request>
|
||||
<dummyAttribute>2</dummyAttribute>
|
||||
<includeAttachments>false</includeAttachments>
|
||||
</request>
|
||||
</sch:dummyServiceMethodWithAttachments>
|
||||
</soapenv:Body>
|
||||
</soapenv:Envelope>
|
@ -0,0 +1,62 @@
|
||||
|
||||
------=_Part_6_2094841787.1482231370463
|
||||
Content-Type: text/xml; charset=UTF-8
|
||||
Content-Transfer-Encoding: 8bit
|
||||
Content-ID: <rootpart@soapui.org>
|
||||
|
||||
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:sch="http://schema.testcase">
|
||||
<soapenv:Header>
|
||||
<sch:SoapHeader>
|
||||
<user>admin</user>
|
||||
</sch:SoapHeader>
|
||||
</soapenv:Header>
|
||||
<soapenv:Body>
|
||||
<sch:dummyServiceMethodWithAttachments>
|
||||
<request>
|
||||
<dummyAttribute>3</dummyAttribute>
|
||||
<includeAttachments>true</includeAttachments>
|
||||
</request>
|
||||
</sch:dummyServiceMethodWithAttachments>
|
||||
</soapenv:Body>
|
||||
</soapenv:Envelope>
|
||||
------=_Part_6_2094841787.1482231370463
|
||||
Content-Type: text/html; charset=us-ascii; name=test-page.html
|
||||
Content-Transfer-Encoding: 7bit
|
||||
Content-ID: <test-page.html>
|
||||
Content-Disposition: attachment; name="test-page.html"; filename="test-page.html"
|
||||
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
|
||||
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||||
<html xmlns="http://www.w3.org/1999/xhtml">
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
|
||||
<title>Test file page</title>
|
||||
<style type="text/css">
|
||||
<!--
|
||||
h1 {
|
||||
font-family: Arial, Helvetica, sans-serif;
|
||||
font-size: 11pt;
|
||||
}
|
||||
-->
|
||||
</style>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<h1>Hello World!</h1>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
------=_Part_6_2094841787.1482231370463
|
||||
Content-Type: application/x-sh; name=testscript.sh
|
||||
Content-Transfer-Encoding: binary
|
||||
Content-ID: <testscript.sh>
|
||||
Content-Disposition: attachment; name="testscript.sh"; filename="testscript.sh"
|
||||
|
||||
#!/bin/sh
|
||||
### ====================================================================== ###
|
||||
## ##
|
||||
## Test Script ##
|
||||
## ##
|
||||
### ====================================================================== ###
|
||||
|
||||
------=_Part_6_2094841787.1482231370463--
|
Reference in New Issue
Block a user