parent
b0681e5fcf
commit
27da3dcb4a
|
@ -18,7 +18,6 @@ use Symfony\Component\HttpKernel\HttpKernelInterface;
|
|||
use Bundle\WebServiceBundle\Soap\SoapRequest;
|
||||
use Bundle\WebServiceBundle\Soap\SoapResponse;
|
||||
|
||||
use Bundle\WebServiceBundle\Util\OutputBuffer;
|
||||
use Bundle\WebServiceBundle\Util\String;
|
||||
|
||||
/**
|
||||
|
@ -68,12 +67,11 @@ class SoapKernel implements HttpKernelInterface
|
|||
{
|
||||
$this->soapRequest = $this->checkRequest($request);
|
||||
|
||||
$this->soapResponse->setContent(OutputBuffer::get(
|
||||
function() use($this)
|
||||
{
|
||||
ob_start();
|
||||
$this->soapServer->handle($this->soapRequest->getRawContent());
|
||||
}
|
||||
));
|
||||
|
||||
$soapResponseContent = ob_get_clean();
|
||||
$this->soapResponse->setContent($soapResponseContent);
|
||||
|
||||
return $this->soapResponse;
|
||||
}
|
||||
|
@ -121,7 +119,7 @@ class SoapKernel implements HttpKernelInterface
|
|||
|
||||
if(!is_a($request, __NAMESPACE__ . '\\Soap\\SoapRequest'))
|
||||
{
|
||||
throw new InvalidArgumentException();
|
||||
throw new \InvalidArgumentException();
|
||||
}
|
||||
|
||||
return $request;
|
||||
|
@ -138,9 +136,9 @@ class SoapKernel implements HttpKernelInterface
|
|||
*/
|
||||
protected function checkResponse(Response $response)
|
||||
{
|
||||
if($response == null || !is_a($request, __NAMESPACE__ . '\\Soap\\SoapResponse'))
|
||||
if($response == null || !is_a($response, __NAMESPACE__ . '\\Soap\\SoapResponse'))
|
||||
{
|
||||
throw new InvalidArgumentException();
|
||||
throw new \InvalidArgumentException();
|
||||
}
|
||||
|
||||
return $response;
|
||||
|
|
|
@ -10,9 +10,12 @@
|
|||
|
||||
namespace Bundle\WebServiceBundle\Tests;
|
||||
|
||||
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
|
||||
use Bundle\WebServiceBundle\SoapKernel;
|
||||
use Bundle\WebServiceBundle\Soap\SoapRequest;
|
||||
use Bundle\WebServiceBundle\Soap\SoapResponse;
|
||||
|
||||
/**
|
||||
* UnitTest for \Bundle\WebServiceBundle\SoapKernel.
|
||||
|
@ -21,19 +24,34 @@ use Bundle\WebServiceBundle\SoapKernel;
|
|||
*/
|
||||
class SoapKernelTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
private static $soapRequestContent = '<?xml version="1.0"?><soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://localhost/"><soapenv:Header/><soapenv:Body><ns1:math_multiply><a>10</a><b>20</b></ns1:math_multiply></soapenv:Body></soapenv:Envelope>';
|
||||
private static $soapResponseContent = '<?xml version="1.0"?><soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://localhost/"><soapenv:Header/><soapenv:Body><ns1:math_multiply><result>200</result></ns1:math_multiply></soapenv:Body></soapenv:Envelope>';
|
||||
|
||||
private $soapKernel;
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
$soapServer = new \SoapServer();
|
||||
$soapServer = new \SoapServer(__DIR__ . '/fixtures/api.wsdl');
|
||||
$httpKernel = $this->getMock('Symfony\\Component\\HttpKernel\\HttpKernelInterface');
|
||||
$httpKernel->expects($this->any())
|
||||
->method('handle')
|
||||
->will($this->returnValue(new SoapResponse(200)));
|
||||
|
||||
$this->soapKernel = new SoapKernel($soapServer, null);
|
||||
$this->soapKernel = new SoapKernel($soapServer, $httpKernel);
|
||||
}
|
||||
|
||||
public function testHandle()
|
||||
{
|
||||
$response = $this->soapKernel->handle(new SoapRequest(self::$soapRequestContent));
|
||||
|
||||
$this->assertEquals(200, $response->getReturnValue());
|
||||
$this->assertEquals(self::$soapResponseContent, $response->getContent());
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException InvalidArgumentException
|
||||
*/
|
||||
public function testInvalidRequest()
|
||||
public function testHandleWithInvalidRequest()
|
||||
{
|
||||
$this->soapKernel->handle(new Request());
|
||||
}
|
||||
|
|
|
@ -0,0 +1,145 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<wsdl:definitions xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns="http://schemas.xmlsoap.org/wsdl/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" name="MathApi" targetNamespace="http://localhost/" xmlns:tns="http://localhost/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">
|
||||
<wsdl:types xmlns:xsd="http://www.w3.org/2001/XMLSchema">
|
||||
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://www.w3.org/2001/XMLSchema" targetNamespace="http://localhost/">
|
||||
<xsd:complexType name="AuthHeader">
|
||||
<xsd:sequence>
|
||||
<xsd:element name="username" type="xsd:string"/>
|
||||
<xsd:element name="password" type="xsd:string"/>
|
||||
</xsd:sequence>
|
||||
</xsd:complexType>
|
||||
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="AuthHeaderElement" type="tns:AuthHeader"/>
|
||||
<xsd:complexType name="DoubleArray">
|
||||
<xsd:sequence>
|
||||
<xsd:element name="item" type="xsd:double" minOccurs="0" maxOccurs="unbounded"/>
|
||||
</xsd:sequence>
|
||||
</xsd:complexType>
|
||||
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="DoubleArrayElement" type="tns:DoubleArray"/>
|
||||
<xsd:complexType name="ComplexNumber">
|
||||
<xsd:sequence>
|
||||
<xsd:element name="realPart" type="xsd:double"/>
|
||||
<xsd:element name="imaginaryPart" type="xsd:double"/>
|
||||
</xsd:sequence>
|
||||
</xsd:complexType>
|
||||
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="ComplexNumberElement" type="tns:ComplexNumber"/>
|
||||
<xsd:complexType name="ComplexNumberArray">
|
||||
<xsd:sequence>
|
||||
<xsd:element name="item" type="tns:ComplexNumber" minOccurs="0" maxOccurs="unbounded"/>
|
||||
</xsd:sequence>
|
||||
</xsd:complexType>
|
||||
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="ComplexNumberArrayElement" type="tns:ComplexNumberArray"/>
|
||||
</xsd:schema>
|
||||
</wsdl:types>
|
||||
<wsdl:portType name="MathApiPortType">
|
||||
<wsdl:operation name="math_multiply" parameterOrder="a b">
|
||||
<wsdl:input message="tns:math_multiplyRequest"/>
|
||||
<wsdl:output message="tns:math_multiplyResponse"/>
|
||||
</wsdl:operation>
|
||||
<wsdl:operation name="SimpleMultiply" parameterOrder="a b">
|
||||
<wsdl:input message="tns:SimpleMultiplyRequest"/>
|
||||
<wsdl:output message="tns:SimpleMultiplyResponse"/>
|
||||
</wsdl:operation>
|
||||
<wsdl:operation name="SimpleMultiplyWithHeader" parameterOrder="AuthHeader a b">
|
||||
<wsdl:input message="tns:SimpleMultiplyWithHeaderRequest"/>
|
||||
<wsdl:output message="tns:SimpleMultiplyWithHeaderResponse"/>
|
||||
</wsdl:operation>
|
||||
<wsdl:operation name="ArrayMultiply" parameterOrder="factors">
|
||||
<wsdl:input message="tns:ArrayMultiplyRequest"/>
|
||||
<wsdl:output message="tns:ArrayMultiplyResponse"/>
|
||||
</wsdl:operation>
|
||||
<wsdl:operation name="ComplexMultiply" parameterOrder="input">
|
||||
<wsdl:input message="tns:ComplexMultiplyRequest"/>
|
||||
<wsdl:output message="tns:ComplexMultiplyResponse"/>
|
||||
</wsdl:operation>
|
||||
</wsdl:portType>
|
||||
<wsdl:binding xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" name="MathApiBinding" type="tns:MathApiPortType">
|
||||
<soap:binding xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/>
|
||||
<wsdl:operation xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" name="math_multiply">
|
||||
<soap:operation xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" soapAction="http://localhost/math_multiply" style="rpc"/>
|
||||
<wsdl:input xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/">
|
||||
<soap:body xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" parts="a b" use="literal" namespace="http://localhost/" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
|
||||
</wsdl:input>
|
||||
<wsdl:output xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/">
|
||||
<soap:body xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" parts="result" use="literal" namespace="http://localhost/" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
|
||||
</wsdl:output>
|
||||
</wsdl:operation>
|
||||
<wsdl:operation xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" name="SimpleMultiply">
|
||||
<soap:operation xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" soapAction="http://localhost/SimpleMultiply" style="rpc"/>
|
||||
<wsdl:input xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/">
|
||||
<soap:body xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" parts="a b" use="literal" namespace="http://localhost/" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
|
||||
</wsdl:input>
|
||||
<wsdl:output xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/">
|
||||
<soap:body xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" parts="result" use="literal" namespace="http://localhost/" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
|
||||
</wsdl:output>
|
||||
</wsdl:operation>
|
||||
<wsdl:operation xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" name="SimpleMultiplyWithHeader">
|
||||
<soap:operation xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" soapAction="http://localhost/SimpleMultiplyWithHeader" style="rpc"/>
|
||||
<wsdl:input xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/">
|
||||
<soap:body xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" parts="a b" use="literal" namespace="http://localhost/" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
|
||||
<soap:header xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" message="tns:SimpleMultiplyWithHeaderRequest" part="AuthHeader" use="literal" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
|
||||
</wsdl:input>
|
||||
<wsdl:output xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/">
|
||||
<soap:body xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" parts="result" use="literal" namespace="http://localhost/" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
|
||||
<soap:header xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" message="tns:SimpleMultiplyWithHeaderResponse" part="AuthHeader" use="literal" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
|
||||
</wsdl:output>
|
||||
</wsdl:operation>
|
||||
<wsdl:operation xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" name="ArrayMultiply">
|
||||
<soap:operation xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" soapAction="http://localhost/ArrayMultiply" style="rpc"/>
|
||||
<wsdl:input xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/">
|
||||
<soap:body xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" parts="factors" use="literal" namespace="http://localhost/" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
|
||||
</wsdl:input>
|
||||
<wsdl:output xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/">
|
||||
<soap:body xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" parts="result" use="literal" namespace="http://localhost/" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
|
||||
</wsdl:output>
|
||||
</wsdl:operation>
|
||||
<wsdl:operation xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" name="ComplexMultiply">
|
||||
<soap:operation xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" soapAction="http://localhost/ComplexMultiply" style="rpc"/>
|
||||
<wsdl:input xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/">
|
||||
<soap:body xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" parts="input" use="literal" namespace="http://localhost/" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
|
||||
</wsdl:input>
|
||||
<wsdl:output xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/">
|
||||
<soap:body xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" parts="result" use="literal" namespace="http://localhost/" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
|
||||
</wsdl:output>
|
||||
</wsdl:operation>
|
||||
</wsdl:binding>
|
||||
<wsdl:message name="math_multiplyRequest">
|
||||
<wsdl:part name="a" type="xsd:double"/>
|
||||
<wsdl:part name="b" type="xsd:double"/>
|
||||
</wsdl:message>
|
||||
<wsdl:message name="math_multiplyResponse">
|
||||
<wsdl:part name="result" type="xsd:double"/>
|
||||
</wsdl:message>
|
||||
<wsdl:message name="SimpleMultiplyRequest">
|
||||
<wsdl:part name="a" type="xsd:double"/>
|
||||
<wsdl:part name="b" type="xsd:double"/>
|
||||
</wsdl:message>
|
||||
<wsdl:message name="SimpleMultiplyResponse">
|
||||
<wsdl:part name="result" type="xsd:double"/>
|
||||
</wsdl:message>
|
||||
<wsdl:message name="SimpleMultiplyWithHeaderRequest">
|
||||
<wsdl:part name="AuthHeader" element="tns:AuthHeaderElement"/>
|
||||
<wsdl:part name="a" type="xsd:double"/>
|
||||
<wsdl:part name="b" type="xsd:double"/>
|
||||
</wsdl:message>
|
||||
<wsdl:message name="SimpleMultiplyWithHeaderResponse">
|
||||
<wsdl:part name="AuthHeader" element="tns:AuthHeaderElement"/>
|
||||
<wsdl:part name="result" type="xsd:double"/>
|
||||
</wsdl:message>
|
||||
<wsdl:message name="ArrayMultiplyRequest">
|
||||
<wsdl:part name="factors" type="tns:DoubleArray"/>
|
||||
</wsdl:message>
|
||||
<wsdl:message name="ArrayMultiplyResponse">
|
||||
<wsdl:part name="result" type="xsd:double"/>
|
||||
</wsdl:message>
|
||||
<wsdl:message name="ComplexMultiplyRequest">
|
||||
<wsdl:part name="input" type="tns:ComplexNumberArray"/>
|
||||
</wsdl:message>
|
||||
<wsdl:message name="ComplexMultiplyResponse">
|
||||
<wsdl:part name="result" type="tns:ComplexNumber"/>
|
||||
</wsdl:message>
|
||||
<wsdl:service xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" name="MathApiService">
|
||||
<wsdl:port xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" name="MathApiPort" binding="tns:MathApiBinding">
|
||||
<soap:address xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" location="http://localhost/MathApi.php"/>
|
||||
</wsdl:port>
|
||||
</wsdl:service>
|
||||
</wsdl:definitions>
|
|
@ -1,33 +0,0 @@
|
|||
<?php
|
||||
/*
|
||||
* This file is part of the WebServiceBundle.
|
||||
*
|
||||
* (c) Christian Kerl <christian-kerl@web.de>
|
||||
*
|
||||
* This source file is subject to the MIT license that is bundled
|
||||
* with this source code in the file LICENSE.
|
||||
*/
|
||||
|
||||
namespace Bundle\WebServiceBundle\Util;
|
||||
|
||||
/**
|
||||
* OutputBuffer provides utility methods to work with PHP's output buffer.
|
||||
*
|
||||
* @author Christian Kerl <christian-kerl@web.de>
|
||||
*/
|
||||
class OutputBuffer
|
||||
{
|
||||
/**
|
||||
* Gets the output created by the given callable.
|
||||
*
|
||||
* @param callable $callback A callable to execute
|
||||
*
|
||||
* @return string The output
|
||||
*/
|
||||
static public function get($callback)
|
||||
{
|
||||
ob_start();
|
||||
$callback();
|
||||
return ob_get_clean();
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue