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
|
|
|
}
|
|
|
|
|
2012-01-12 11:45:15 +01:00
|
|
|
public function testProcessMessageComplexTypeWithArrays()
|
|
|
|
{
|
|
|
|
$messageBinder = new RpcLiteralRequestMessageBinder();
|
|
|
|
|
|
|
|
$array = array(1, 2, 3, 4);
|
|
|
|
$stdClass = new \stdClass();
|
|
|
|
$stdClass->item = $array;
|
|
|
|
$simpleArrays = new Fixtures\SimpleArrays(null, new \stdClass(), $stdClass);
|
|
|
|
|
|
|
|
$result = $messageBinder->processMessage(
|
|
|
|
new Definition\Method('complextype_with_array', null, array(), array(
|
|
|
|
new Definition\Argument('simple_arrays', new Definition\Type('BeSimple\SoapBundle\Tests\fixtures\ServiceBinding\SimpleArrays')),
|
|
|
|
)),
|
|
|
|
array($simpleArrays),
|
|
|
|
$this->getDefinitionComplexTypes()
|
|
|
|
);
|
|
|
|
|
|
|
|
$result = $result['simple_arrays'];
|
|
|
|
$this->assertEquals(array(), $result->array1);
|
|
|
|
$this->assertEquals(array(), $result->getArray2());
|
|
|
|
$this->assertEquals($array, $result->getArray3());
|
|
|
|
}
|
|
|
|
|
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-09-08 21:25:45 +02:00
|
|
|
public function testProccessMessagePreventInfiniteRecursion()
|
|
|
|
{
|
|
|
|
$messageBinder = new RpcLiteralRequestMessageBinder();
|
|
|
|
|
|
|
|
$foo = new Fixtures\FooRecursive('foo', '');
|
|
|
|
$bar = new Fixtures\BarRecursive($foo, 10394);
|
2011-09-13 21:34:39 +02:00
|
|
|
$foo->bar = $bar;
|
2011-09-08 21:25:45 +02:00
|
|
|
|
|
|
|
$result = $messageBinder->processMessage(
|
|
|
|
new Definition\Method('prevent_infinite_recursion', null, array(), array(
|
|
|
|
new Definition\Argument('foo_recursive', new Definition\Type('BeSimple\SoapBundle\Tests\fixtures\ServiceBinding\FooRecursive')),
|
|
|
|
)),
|
|
|
|
array($foo),
|
|
|
|
$this->getDefinitionComplexTypes()
|
|
|
|
);
|
|
|
|
|
|
|
|
$this->assertEquals(array('foo_recursive' => $foo), $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-09-08 21:24:40 +02:00
|
|
|
$definitionComplexTypes['BeSimple\SoapBundle\Tests\fixtures\ServiceBinding\Bar'] = $this->createComplexTypeCollection(array(
|
2011-08-27 22:12:38 +02:00
|
|
|
array('foo', 'string'),
|
|
|
|
array('bar', 'int', true),
|
2011-07-27 00:13:24 +02:00
|
|
|
));
|
|
|
|
|
2011-09-08 21:24:40 +02:00
|
|
|
$definitionComplexTypes['BeSimple\SoapBundle\Tests\fixtures\ServiceBinding\FooBar'] = $this->createComplexTypeCollection(array(
|
2011-08-27 22:12:38 +02:00
|
|
|
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
|
|
|
|
2012-01-12 11:45:15 +01:00
|
|
|
$definitionComplexTypes['BeSimple\SoapBundle\Tests\fixtures\ServiceBinding\SimpleArrays'] = $this->createComplexTypeCollection(array(
|
|
|
|
array('array1', 'string[]', true),
|
|
|
|
array('array2', 'string[]'),
|
|
|
|
array('array3', 'string[]'),
|
|
|
|
));
|
|
|
|
|
2011-09-08 21:25:45 +02:00
|
|
|
$definitionComplexTypes['BeSimple\SoapBundle\Tests\fixtures\ServiceBinding\FooRecursive'] = $this->createComplexTypeCollection(array(
|
|
|
|
array('bar', 'BeSimple\SoapBundle\Tests\fixtures\ServiceBinding\BarRecursive'),
|
|
|
|
));
|
|
|
|
|
|
|
|
$definitionComplexTypes['BeSimple\SoapBundle\Tests\fixtures\ServiceBinding\BarRecursive'] = $this->createComplexTypeCollection(array(
|
|
|
|
array('foo', 'BeSimple\SoapBundle\Tests\fixtures\ServiceBinding\FooRecursive'),
|
|
|
|
));
|
|
|
|
|
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;
|
|
|
|
}
|
2012-01-12 11:45:15 +01:00
|
|
|
}
|