2011-07-24 21:30:45 +02:00
|
|
|
<?php
|
|
|
|
/*
|
|
|
|
* This file is part of the BeSimpleSoapBundle.
|
|
|
|
*
|
|
|
|
* (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 BeSimple\SoapBundle\Tests\ServiceBinding;
|
|
|
|
|
|
|
|
use BeSimple\SoapBundle\ServiceBinding\RpcLiteralRequestMessageBinder;
|
2011-08-27 22:12:38 +02:00
|
|
|
use BeSimple\SoapBundle\ServiceDefinition as Definition;
|
|
|
|
use BeSimple\SoapBundle\Tests\fixtures\ServiceBinding as Fixtures;
|
2011-07-24 21:30:45 +02:00
|
|
|
use BeSimple\SoapBundle\Util\Collection;
|
|
|
|
|
|
|
|
class RpcLiteralRequestMessageBinderTest extends \PHPUnit_Framework_TestCase
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @dataProvider messageProvider
|
|
|
|
*/
|
2011-08-27 22:12:38 +02:00
|
|
|
public function testProcessMessage(Definition\Method $method, $message, $assert)
|
2011-07-24 21:30:45 +02:00
|
|
|
{
|
|
|
|
$messageBinder = new RpcLiteralRequestMessageBinder();
|
|
|
|
$result = $messageBinder->processMessage($method, $message);
|
|
|
|
|
|
|
|
$this->assertSame($assert, $result);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testProcessMessageWithComplexType()
|
|
|
|
{
|
|
|
|
$messageBinder = new RpcLiteralRequestMessageBinder();
|
2011-08-27 22:12:38 +02:00
|
|
|
|
|
|
|
$foo = new Fixtures\Foo('foobar', 19395);
|
|
|
|
$result = $messageBinder->processMessage(
|
|
|
|
new Definition\Method('complextype_argument', null, array(), array(
|
|
|
|
new Definition\Argument('foo', new Definition\Type('BeSimple\SoapBundle\Tests\fixtures\ServiceBinding\Foo')),
|
2011-07-24 21:30:45 +02:00
|
|
|
)),
|
2011-08-27 22:12:38 +02:00
|
|
|
array($foo),
|
2011-07-27 22:53:33 +02:00
|
|
|
$this->getDefinitionComplexTypes()
|
2011-07-24 21:30:45 +02:00
|
|
|
);
|
|
|
|
|
2011-08-27 22:12:38 +02:00
|
|
|
$this->assertEquals(array('foo' => $foo), $result);
|
2011-07-24 21:30:45 +02:00
|
|
|
|
2011-07-27 22:53:33 +02:00
|
|
|
|
2011-08-27 22:12:38 +02:00
|
|
|
$foo1 = new Fixtures\Foo('foobar', 29291);
|
|
|
|
$foo2 = new Fixtures\Foo('barfoo', 39392);
|
|
|
|
$foos = new \stdClass();
|
|
|
|
$foos->item = array($foo1, $foo2);
|
2011-07-27 22:53:33 +02:00
|
|
|
|
2011-08-27 22:12:38 +02:00
|
|
|
$result = $messageBinder->processMessage(
|
|
|
|
new Definition\Method('complextype_argument', null, array(), array(
|
|
|
|
new Definition\Argument('foos', new Definition\Type('BeSimple\SoapBundle\Tests\fixtures\ServiceBinding\Foo[]')),
|
2011-07-24 21:30:45 +02:00
|
|
|
)),
|
2011-08-27 22:12:38 +02:00
|
|
|
array($foos),
|
2011-07-27 22:53:33 +02:00
|
|
|
$this->getDefinitionComplexTypes()
|
2011-07-24 21:30:45 +02:00
|
|
|
);
|
|
|
|
|
2011-08-27 22:12:38 +02:00
|
|
|
$this->assertEquals(array('foos' => array($foo1, $foo2)), $result);
|
2011-07-27 00:13:24 +02:00
|
|
|
}
|
|
|
|
|
2011-08-27 22:12:38 +02:00
|
|
|
/**
|
2011-09-01 20:18:28 +02:00
|
|
|
* @expectedException SoapFault
|
2011-08-27 22:12:38 +02:00
|
|
|
*/
|
|
|
|
public function testProcessMessageSoapFault()
|
2011-07-27 00:13:24 +02:00
|
|
|
{
|
|
|
|
$messageBinder = new RpcLiteralRequestMessageBinder();
|
2011-08-27 22:12:38 +02:00
|
|
|
|
|
|
|
$foo = new Fixtures\Foo('foo', null);
|
|
|
|
$result = $messageBinder->processMessage(
|
|
|
|
new Definition\Method('complextype_argument', null, array(), array(
|
|
|
|
new Definition\Argument('foo', new Definition\Type('BeSimple\SoapBundle\Tests\fixtures\ServiceBinding\Foo')),
|
2011-07-27 00:13:24 +02:00
|
|
|
)),
|
2011-08-27 22:12:38 +02:00
|
|
|
array($foo),
|
2011-07-27 22:53:33 +02:00
|
|
|
$this->getDefinitionComplexTypes()
|
2011-07-27 00:13:24 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2011-08-27 22:12:38 +02:00
|
|
|
public function testProcessMessageWithComplexTypeReference()
|
2011-07-27 00:13:24 +02:00
|
|
|
{
|
2011-08-27 22:12:38 +02:00
|
|
|
$messageBinder = new RpcLiteralRequestMessageBinder();
|
2011-07-27 22:53:33 +02:00
|
|
|
|
2011-08-27 22:12:38 +02:00
|
|
|
$foo = new Fixtures\Foo('foo', 2499104);
|
|
|
|
$foos = new \stdClass();
|
|
|
|
$foos->item = array($foo, $foo);
|
2011-07-27 22:53:33 +02:00
|
|
|
|
2011-08-27 22:12:38 +02:00
|
|
|
$result = $messageBinder->processMessage(
|
|
|
|
new Definition\Method('complextype_argument', null, array(), array(
|
|
|
|
new Definition\Argument('foos', new Definition\Type('BeSimple\SoapBundle\Tests\fixtures\ServiceBinding\Foo[]')),
|
2011-07-27 00:13:24 +02:00
|
|
|
)),
|
2011-08-27 22:12:38 +02:00
|
|
|
array($foos),
|
2011-07-27 22:53:33 +02:00
|
|
|
$this->getDefinitionComplexTypes()
|
2011-07-27 00:13:24 +02:00
|
|
|
);
|
|
|
|
|
2011-08-27 22:12:38 +02:00
|
|
|
$this->assertEquals(array('foos' => array($foo, $foo)), $result);
|
2011-07-24 21:30:45 +02:00
|
|
|
}
|
|
|
|
|
2011-08-27 22:12:38 +02:00
|
|
|
public function testProcessMessageWithComplexTypeIntoComplexType()
|
2011-07-27 22:53:33 +02:00
|
|
|
{
|
2011-08-27 22:12:38 +02:00
|
|
|
$messageBinder = new RpcLiteralRequestMessageBinder();
|
2011-07-27 22:53:33 +02:00
|
|
|
|
2011-08-27 22:12:38 +02:00
|
|
|
$foo = new Fixtures\Foo('foo', 38845);
|
|
|
|
$bar = new Fixtures\Bar('bar', null);
|
|
|
|
$fooBar = new Fixtures\FooBar($foo, $bar);
|
2011-07-27 22:53:33 +02:00
|
|
|
|
2011-08-27 22:12:38 +02:00
|
|
|
$result = $messageBinder->processMessage(
|
|
|
|
new Definition\Method('complextype_argument', null, array(), array(
|
|
|
|
new Definition\Argument('fooBar', new Definition\Type('BeSimple\SoapBundle\Tests\fixtures\ServiceBinding\FooBar')),
|
2011-07-27 22:53:33 +02:00
|
|
|
)),
|
2011-08-27 22:12:38 +02:00
|
|
|
array($fooBar),
|
2011-07-27 22:53:33 +02:00
|
|
|
$this->getDefinitionComplexTypes()
|
|
|
|
);
|
|
|
|
|
2011-08-27 22:12:38 +02:00
|
|
|
$this->assertEquals(array('fooBar' => $fooBar), $result);
|
2011-07-27 22:53:33 +02:00
|
|
|
}
|
|
|
|
|
2011-09-01 20:18:28 +02:00
|
|
|
public function testProcessMessageWithEmptyArrayComplexType()
|
|
|
|
{
|
|
|
|
$messageBinder = new RpcLiteralRequestMessageBinder();
|
|
|
|
|
|
|
|
$result = $messageBinder->processMessage(
|
|
|
|
new Definition\Method('empty_array_complex_type', null, array(), array(
|
|
|
|
new Definition\Argument('foo', new Definition\Type('BeSimple\SoapBundle\Tests\fixtures\ServiceBinding\Foo[]')),
|
|
|
|
)),
|
|
|
|
array(new \stdClass()),
|
|
|
|
$this->getDefinitionComplexTypes()
|
|
|
|
);
|
|
|
|
|
|
|
|
$this->assertEquals(array('foo' => array()), $result);
|
|
|
|
}
|
|
|
|
|
2011-07-24 21:30:45 +02:00
|
|
|
public function messageProvider()
|
|
|
|
{
|
|
|
|
$messages = array();
|
|
|
|
|
|
|
|
$messages[] = array(
|
2011-08-27 22:12:38 +02:00
|
|
|
new Definition\Method('no_argument'),
|
2011-07-24 21:30:45 +02:00
|
|
|
array(),
|
|
|
|
array(),
|
|
|
|
);
|
|
|
|
|
|
|
|
$messages[] = array(
|
2011-08-27 22:12:38 +02:00
|
|
|
new Definition\Method('string_argument', null, array(), array(
|
|
|
|
new Definition\Argument('foo', new Definition\Type('string')),
|
2011-07-24 21:30:45 +02:00
|
|
|
)),
|
|
|
|
array('bar'),
|
|
|
|
array('foo' => 'bar'),
|
|
|
|
);
|
|
|
|
|
|
|
|
$messages[] = array(
|
2011-08-27 22:12:38 +02:00
|
|
|
new Definition\Method('string_int_arguments', null, array(), array(
|
|
|
|
new Definition\Argument('foo', new Definition\Type('string')),
|
|
|
|
new Definition\Argument('bar', new Definition\Type('int')),
|
2011-07-24 21:30:45 +02:00
|
|
|
)),
|
|
|
|
array('test', 20),
|
|
|
|
array('foo' => 'test', 'bar' => 20),
|
|
|
|
);
|
|
|
|
|
|
|
|
$strings = new \stdClass();
|
|
|
|
$strings->item = array('foo', 'bar', 'barfoo');
|
|
|
|
$messages[] = array(
|
2011-08-27 22:12:38 +02:00
|
|
|
new Definition\Method('array_string_arguments', null, array(), array(
|
|
|
|
new Definition\Argument('foo', new Definition\Type('string[]')),
|
|
|
|
new Definition\Argument('bar', new Definition\Type('int')),
|
2011-07-24 21:30:45 +02:00
|
|
|
)),
|
|
|
|
array($strings, 4),
|
|
|
|
array('foo' => array('foo', 'bar', 'barfoo'), 'bar' => 4),
|
|
|
|
);
|
|
|
|
|
2011-09-01 20:18:28 +02:00
|
|
|
$messages[] = array(
|
|
|
|
new Definition\Method('empty_array', null, array(), array(
|
|
|
|
new Definition\Argument('foo', new Definition\Type('string[]')),
|
|
|
|
)),
|
|
|
|
array(new \stdClass()),
|
|
|
|
array('foo' => array()),
|
|
|
|
);
|
|
|
|
|
2011-07-24 21:30:45 +02:00
|
|
|
return $messages;
|
|
|
|
}
|
|
|
|
|
2011-07-27 00:13:24 +02:00
|
|
|
private function getDefinitionComplexTypes()
|
2011-07-24 21:30:45 +02:00
|
|
|
{
|
2011-08-27 22:12:38 +02:00
|
|
|
$definitionComplexTypes = array();
|
2011-07-24 21:30:45 +02:00
|
|
|
|
2011-08-27 22:12:38 +02:00
|
|
|
$definitionComplexTypes['BeSimple\SoapBundle\Tests\fixtures\ServiceBinding\Foo'] = $this->createComplexTypeCollection(array(
|
2011-07-27 00:13:24 +02:00
|
|
|
array('foo', 'string'),
|
|
|
|
array('bar', 'int'),
|
|
|
|
));
|
|
|
|
|
2011-08-27 22:12:38 +02:00
|
|
|
$this->definitionComplexTypes['\BeSimple\SoapBundle\Tests\ServiceBinding\fixtures\Bar'] = $this->createComplexTypeCollection(array(
|
|
|
|
array('foo', 'string'),
|
|
|
|
array('bar', 'int', true),
|
2011-07-27 00:13:24 +02:00
|
|
|
));
|
|
|
|
|
2011-08-27 22:12:38 +02:00
|
|
|
$this->definitionComplexTypes['\BeSimple\SoapBundle\Tests\ServiceBinding\fixtures\FooBar'] = $this->createComplexTypeCollection(array(
|
|
|
|
array('foo', 'BeSimple\SoapBundle\Tests\fixtures\ServiceBinding\Foo'),
|
|
|
|
array('bar', 'BeSimple\SoapBundle\Tests\fixtures\ServiceBinding\Bar'),
|
2011-07-27 00:13:24 +02:00
|
|
|
));
|
2011-07-24 21:30:45 +02:00
|
|
|
|
2011-08-27 22:12:38 +02:00
|
|
|
return $definitionComplexTypes;
|
2011-07-24 21:30:45 +02:00
|
|
|
}
|
2011-07-27 00:13:24 +02:00
|
|
|
|
2011-08-27 22:12:38 +02:00
|
|
|
private function createComplexTypeCollection(array $properties)
|
2011-07-27 00:13:24 +02:00
|
|
|
{
|
2011-08-27 22:12:38 +02:00
|
|
|
$collection = new Collection('getName', 'BeSimple\SoapBundle\ServiceDefinition\ComplexType');
|
2011-07-27 00:13:24 +02:00
|
|
|
|
|
|
|
foreach ($properties as $property) {
|
2011-08-27 22:12:38 +02:00
|
|
|
$complexType = new Definition\ComplexType();
|
|
|
|
$complexType->setName($property[0]);
|
|
|
|
$complexType->setValue($property[1]);
|
2011-07-27 00:13:24 +02:00
|
|
|
|
2011-08-27 22:12:38 +02:00
|
|
|
if (isset($property[2])) {
|
|
|
|
$complexType->setNillable($property[2]);
|
|
|
|
}
|
2011-07-27 00:13:24 +02:00
|
|
|
|
2011-08-27 22:12:38 +02:00
|
|
|
$collection->add($complexType);
|
2011-07-27 00:13:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return $collection;
|
|
|
|
}
|
2011-08-27 22:12:38 +02:00
|
|
|
}
|