2010-10-05 21:44:30 +02:00
|
|
|
<?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\Tests;
|
|
|
|
|
2010-10-05 22:42:47 +02:00
|
|
|
|
2010-10-07 15:16:56 +02:00
|
|
|
use Bundle\WebServiceBundle\ServiceDefinition\ServiceMethod;
|
|
|
|
|
|
|
|
use Bundle\WebServiceBundle\ServiceDefinition\ServiceDefinition;
|
|
|
|
|
2010-10-05 21:44:30 +02:00
|
|
|
use Symfony\Component\HttpFoundation\Request;
|
|
|
|
|
|
|
|
use Bundle\WebServiceBundle\SoapKernel;
|
2010-10-05 22:42:47 +02:00
|
|
|
use Bundle\WebServiceBundle\Soap\SoapRequest;
|
|
|
|
use Bundle\WebServiceBundle\Soap\SoapResponse;
|
2010-10-05 21:44:30 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* UnitTest for \Bundle\WebServiceBundle\SoapKernel.
|
|
|
|
*
|
|
|
|
* @author Christian Kerl <christian-kerl@web.de>
|
|
|
|
*/
|
|
|
|
class SoapKernelTest extends \PHPUnit_Framework_TestCase
|
|
|
|
{
|
2010-10-05 22:42:47 +02:00
|
|
|
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>';
|
2010-10-05 23:22:12 +02:00
|
|
|
private static $soapResponseContent = '<?xml version="1.0" encoding="UTF-8"?><SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://localhost/"><SOAP-ENV:Body><ns1:math_multiplyResponse><result>200</result></ns1:math_multiplyResponse></SOAP-ENV:Body></SOAP-ENV:Envelope>';
|
2010-10-05 22:42:47 +02:00
|
|
|
|
2010-10-05 21:44:30 +02:00
|
|
|
private $soapKernel;
|
|
|
|
|
|
|
|
public function setUp()
|
|
|
|
{
|
2010-10-07 15:16:56 +02:00
|
|
|
$serviceDefinition = new ServiceDefinition('api');
|
|
|
|
$serviceDefinition->getMethods()->add(new ServiceMethod('math_multiply', 'MathController::multiply'));
|
|
|
|
|
|
|
|
$serviceDefinitionLoader = null;
|
|
|
|
$serviceDefinitionDumper = new StaticFileDumper(__DIR__ . '/fixtures/api.wsdl');
|
|
|
|
|
2010-10-05 22:42:47 +02:00
|
|
|
$httpKernel = $this->getMock('Symfony\\Component\\HttpKernel\\HttpKernelInterface');
|
|
|
|
$httpKernel->expects($this->any())
|
|
|
|
->method('handle')
|
|
|
|
->will($this->returnValue(new SoapResponse(200)));
|
|
|
|
|
2010-10-07 15:16:56 +02:00
|
|
|
$this->soapKernel = new SoapKernel($serviceDefinition, $serviceDefinitionLoader, $serviceDefinitionDumper, $httpKernel);
|
2010-10-05 22:42:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testHandle()
|
|
|
|
{
|
|
|
|
$response = $this->soapKernel->handle(new SoapRequest(self::$soapRequestContent));
|
2010-10-05 21:44:30 +02:00
|
|
|
|
2010-10-05 22:42:47 +02:00
|
|
|
$this->assertEquals(200, $response->getReturnValue());
|
2010-10-05 23:22:12 +02:00
|
|
|
$this->assertXmlStringEqualsXmlString(self::$soapResponseContent, $response->getContent());
|
2010-10-05 21:44:30 +02:00
|
|
|
}
|
|
|
|
|
2010-10-05 22:42:47 +02:00
|
|
|
public function testHandleWithInvalidRequest()
|
2010-10-05 21:44:30 +02:00
|
|
|
{
|
2010-10-07 15:16:56 +02:00
|
|
|
$this->setExpectedException('InvalidArgumentException');
|
|
|
|
|
2010-10-05 21:44:30 +02:00
|
|
|
$this->soapKernel->handle(new Request());
|
|
|
|
}
|
|
|
|
}
|