BeSimpleSoap/Tests/SoapKernelTest.php

77 lines
3.3 KiB
PHP
Raw Normal View History

<?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;
use Bundle\WebServiceBundle\Soap\SoapServerFactory;
use Bundle\WebServiceBundle\Converter\ConverterRepository;
use Symfony\Component\HttpFoundation\Request;
use Bundle\WebServiceBundle\SoapKernel;
use Bundle\WebServiceBundle\Soap\SoapRequest;
use Bundle\WebServiceBundle\Soap\SoapResponse;
use Bundle\WebServiceBundle\ServiceBinding\ServiceBinder;
use Bundle\WebServiceBundle\ServiceBinding\RpcLiteralResponseMessageBinder;
use Bundle\WebServiceBundle\ServiceBinding\RpcLiteralRequestMessageBinder;
use Bundle\WebServiceBundle\ServiceDefinition\ServiceDefinition;
use Bundle\WebServiceBundle\ServiceDefinition\Method;
use Bundle\WebServiceBundle\ServiceDefinition\Loader\XmlFileLoader;
/**
* UnitTest for \Bundle\WebServiceBundle\SoapKernel.
*
* @author Christian Kerl <christian-kerl@web.de>
*/
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>';
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>';
private $soapKernel;
public function setUp()
{
$serviceDefinition = new ServiceDefinition('api');
$serviceDefinitionLoader = new XmlFileLoader(__DIR__ . '/fixtures/api-servicedefinition.xml');
$serviceDefinitionLoader->loadServiceDefinition($serviceDefinition);
$serviceDefinitionDumper = new StaticFileDumper(__DIR__ . '/fixtures/api.wsdl');
$requestMessageBinder = new RpcLiteralRequestMessageBinder();
$responseMessageBinder = new RpcLiteralResponseMessageBinder();
$serviceBinder = new ServiceBinder($serviceDefinition, $requestMessageBinder, $responseMessageBinder);
$converterRepository = new ConverterRepository();
$soapServerFactory = new SoapServerFactory($serviceDefinition, $converterRepository, $serviceDefinitionDumper);
$httpKernel = $this->getMock('Symfony\\Component\\HttpKernel\\HttpKernelInterface');
$httpKernel->expects($this->any())
->method('handle')
->will($this->returnValue(new SoapResponse(200)));
$this->soapKernel = new SoapKernel($serviceBinder, $soapServerFactory, $httpKernel);
}
public function testHandle()
{
$response = $this->soapKernel->handle(new SoapRequest(self::$soapRequestContent));
$this->assertEquals(200, $response->getReturnValue());
2010-10-05 23:22:12 +02:00
$this->assertXmlStringEqualsXmlString(self::$soapResponseContent, $response->getContent());
}
public function testHandleWithInvalidRequest()
{
$this->setExpectedException('InvalidArgumentException');
$this->soapKernel->handle(new Request());
}
}