Initial commit

This commit is contained in:
Francis Besset
2011-09-03 21:15:51 +02:00
commit fd162d8ca6
7 changed files with 567 additions and 0 deletions

View File

@ -0,0 +1,47 @@
<?xml version="1.0"?>
<definitions xmlns="http://schemas.xmlsoap.org/wsdl/" xmlns:tns="http://foobar/soap/User/1.0/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap-enc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" name="User" targetNamespace="http://foobar/soap/User/1.0/">
<portType name="UserPortType">
<operation name="login" parameterOrder="username password">
<input message="tns:loginRequest"/>
<output message="tns:loginResponse"/>
</operation>
</portType>
<binding name="UserBinding" type="tns:UserPortType">
<soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/>
<operation name="login">
<soap:operation soapAction="http://foobar/soap/User/1.0/login"/>
<input>
<soap:body parts="username password" use="literal" namespace="http://foobar/soap/User/1.0/" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
</input>
<output>
<soap:body parts="return" use="literal" namespace="http://foobar/soap/User/1.0/" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
</output>
</operation>
</binding>
<service name="UserService">
<port name="UserPort" binding="tns:UserBinding">
<soap:address location="http://foobar/soap/user"/>
</port>
</service>
<types>
<xsd:schema targetNamespace="http://foobar/soap/User/1.0/">
<xsd:complexType name="User">
<xsd:all>
<xsd:element name="id" type="xsd:int" nillable="true"/>
<xsd:element name="username" type="xsd:string"/>
<xsd:element name="email" type="xsd:string"/>
<xsd:element name="language" type="xsd:string"/>
<xsd:element name="apiKey" type="xsd:string"/>
<xsd:element name="subscriptionEndAt" type="xsd:dateTime" nillable="true"/>
</xsd:all>
</xsd:complexType>
</xsd:schema>
</types>
<message name="loginRequest">
<part name="username" type="xsd:string"/>
<part name="password" type="xsd:string"/>
</message>
<message name="loginResponse">
<part name="return" type="tns:User"/>
</message>
</definitions>

View File

@ -0,0 +1,76 @@
<?php
/*
* This file is part of the BeSimpleSoapBundle.
*
* (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\Tests\SoapClient\Soap;
use BeSimple\SoapClient\Soap\SoapClient;
class SoapClientTest extends \PHPUnit_Framework_TestCase
{
public function testSetOptions()
{
$soapClient = new SoapClient('foo.wsdl');
$options = array(
'cache_dir' => '/tmp',
'debug' => true,
);
$soapClient->setOptions($options);
$this->assertEquals($options, $soapClient->getOptions());
}
public function testSetOptionsThrowsAnExceptionIfOptionsDoesNotExists()
{
$soapClient = new SoapClient('foo.wsdl');
$this->setExpectedException('InvalidArgumentException');
$soapClient->setOptions(array('bad_option' => true));
}
public function testSetOption()
{
$soapClient = new SoapClient('foo.wsdl');
$soapClient->setOption('debug', true);
$this->assertEquals(true, $soapClient->getOption('debug'));
}
public function testSetOptionThrowsAnExceptionIfOptionDoesNotExists()
{
$soapClient = new SoapClient('foo.wsdl');
$this->setExpectedException('InvalidArgumentException');
$soapClient->setOption('bad_option', 'bar');
}
public function testGetOptionThrowsAnExceptionIfOptionDoesNotExists()
{
$soapClient = new SoapClient('foo.wsdl');
$this->setExpectedException('InvalidArgumentException');
$soapClient->getOption('bad_option');
}
public function testGetSoapOptions()
{
$soapClient = new SoapClient('foo.wsdl', array('debug' => true));
$this->assertEquals(array('cache_wsdl' => WSDL_CACHE_NONE, 'trace' => true), $soapClient->getSoapOptions());
}
public function testGetNativeSoapClient()
{
$soapClient = new SoapClient(__DIR__.'/Fixtures/foobar.wsdl', array('debug' => true));
$this->assertInstanceOf('SoapClient', $soapClient->getNativeSoapClient());
}
}

View File

@ -0,0 +1,89 @@
<?php
/*
* This file is part of the BeSimpleSoapBundle.
*
* (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\Tests\SoapClient\Soap;
use BeSimple\SoapClient\Soap\SoapRequest;
class SoapRequestTest extends \PHPUnit_Framework_TestCase
{
public function testSetFunction()
{
$soapRequest = new SoapRequest();
$soapRequest->setFunction('foo');
$this->assertEquals('foo', $soapRequest->getFunction());
}
public function testSetArguments()
{
$soapRequest = new SoapRequest();
$arguments = array(
'foo' => true,
'bar' => false,
);
$soapRequest->setArguments($arguments);
$this->assertEquals($arguments, $soapRequest->getArguments());
}
public function testGetArgument()
{
$soapRequest = new SoapRequest();
$this->assertEquals(false, $soapRequest->getArgument('foo', false));
$soapRequest->addArgument('foo', 'bar');
$this->assertEquals('bar', $soapRequest->getArgument('foo', false));
}
public function testSetOptions()
{
$soapRequest = new SoapRequest();
$options = array(
'uri' => 'foo',
'soapaction' => 'bar',
);
$soapRequest->setOptions($options);
$this->assertEquals($options, $soapRequest->getOptions());
}
public function testGetOption()
{
$soapRequest = new SoapRequest();
$this->assertEquals(false, $soapRequest->getOption('soapaction'));
$soapRequest->addOption('soapaction', 'foo');
$this->assertEquals('foo', $soapRequest->getOption('soapaction'));
}
public function testConstruct()
{
$soapRequest = new SoapRequest();
$this->assertNull($soapRequest->getFunction());
$this->assertEquals(array(), $soapRequest->getArguments());
$this->assertEquals(array(), $soapRequest->getOptions());
$arguments = array('bar' => 'foobar');
$options = array('soapaction' => 'foobar');
$soapRequest = new SoapRequest('foo', $arguments, $options);
$this->assertEquals('foo', $soapRequest->getFunction());
$this->assertEquals($arguments, $soapRequest->getArguments());
$this->assertEquals($options, $soapRequest->getOptions());
}
}

22
tests/bootstrap.php Normal file
View File

@ -0,0 +1,22 @@
<?php
error_reporting(E_ALL | E_STRICT);
// register silently failing autoloader
spl_autoload_register(function($class) {
if (0 === strpos($class, 'BeSimple\Tests\\')) {
$path = __DIR__.'/../'.strtr($class, '\\', '/').'.php';
if (file_exists($path) && is_readable($path)) {
require_once $path;
return true;
}
} else if (0 === strpos($class, 'BeSimple\SoapClient\\')) {
$path = __DIR__.'/../src/'.($class = strtr($class, '\\', '/')).'.php';
if (file_exists($path) && is_readable($path)) {
require_once $path;
return true;
}
}
});