UnitTests are now located in tests directory & tiny improvements

This commit is contained in:
Petr Bechyně
2017-03-15 10:25:48 +01:00
parent 21d705bbfa
commit d3023b1a5a
115 changed files with 206 additions and 3816 deletions

View File

@ -1,35 +0,0 @@
<?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;
}
}

View File

@ -1,21 +0,0 @@
<?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;
}
}

View File

@ -1,106 +0,0 @@
<?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;
}
}

View File

@ -1,92 +0,0 @@
<?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>

View File

@ -1,18 +0,0 @@
<?php
namespace BeSimple\SoapServer\Tests;
class DummyServiceHandler
{
/**
* @param DummyServiceRequest
* @return DummyServiceResponse
*/
public function handle(DummyServiceRequest $request)
{
$response = new DummyServiceResponse();
$response->status = true;
return $response;
}
}

View File

@ -1,30 +0,0 @@
<?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;
}
}

View File

@ -1,11 +0,0 @@
<?php
namespace BeSimple\SoapServer\Tests;
class DummyServiceRequest
{
/**
* @var int $dummyAttribute
*/
public $dummyAttribute;
}

View File

@ -1,28 +0,0 @@
<?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();
}
}

View File

@ -1,11 +0,0 @@
<?php
namespace BeSimple\SoapServer\Tests;
class DummyServiceResponse
{
/**
* @var bool $status
*/
public $status;
}

View File

@ -1,23 +0,0 @@
<?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();
}
}

View File

@ -1,154 +0,0 @@
<?php
/*
* This file is part of the BeSimpleSoapServer.
*
* (c) Christian Kerl <christian-kerl@web.de>
* (c) Francis Besset <francis.besset@gmail.com>
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/
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
{
const TEST_LOCAL_WSDL_UK = SoapClientBuilderTest::TEST_LOCAL_WSDL_UK;
const CACHE_DIR = __DIR__ . '/../../../../cache';
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 testSoapClientOptionsCreateWithDefaults()
{
$defaultOptions = SoapServerOptionsBuilder::createWithDefaults(new SoapServerHandler);
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()
{
return new SoapServerBuilder();
}
}

View File

@ -1,7 +0,0 @@
<?php
namespace BeSimple\SoapServer\Tests;
class SoapServerHandler
{
}

View File

@ -1,14 +0,0 @@
<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>

View File

@ -1,15 +0,0 @@
<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>

View File

@ -1,62 +0,0 @@
------=_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--