Fixed error if an array is empty in RpcLiteralRequestMessageBinder

This commit is contained in:
Francis Besset 2011-09-01 20:18:28 +02:00
parent 958efd3431
commit faf8b58108
2 changed files with 34 additions and 6 deletions

View File

@ -49,16 +49,17 @@ class RpcLiteralRequestMessageBinder implements MessageBinderInterface
if (preg_match('/^([^\[]+)\[\]$/', $phpType, $match)) {
$isArray = true;
$array = array();
$phpType = $match[1];
}
// @TODO Fix array reference
if (isset($this->definitionComplexTypes[$phpType])) {
if ($isArray) {
$array = array();
foreach ($message->item as $complexType) {
$array[] = $this->checkComplexType($phpType, $complexType);
if (isset($message->item)) {
foreach ($message->item as $complexType) {
$array[] = $this->checkComplexType($phpType, $complexType);
}
}
$message = $array;
@ -66,7 +67,11 @@ class RpcLiteralRequestMessageBinder implements MessageBinderInterface
$message = $this->checkComplexType($phpType, $message);
}
} elseif ($isArray) {
$message = $message->item;
if (isset($message->item)) {
$message = $message->item;
} else {
$message = $array;
}
}
return $message;

View File

@ -61,7 +61,7 @@ class RpcLiteralRequestMessageBinderTest extends \PHPUnit_Framework_TestCase
}
/**
* @expectedException SoapFault
* @expectedException SoapFault
*/
public function testProcessMessageSoapFault()
{
@ -115,6 +115,21 @@ class RpcLiteralRequestMessageBinderTest extends \PHPUnit_Framework_TestCase
$this->assertEquals(array('fooBar' => $fooBar), $result);
}
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);
}
public function messageProvider()
{
$messages = array();
@ -153,6 +168,14 @@ class RpcLiteralRequestMessageBinderTest extends \PHPUnit_Framework_TestCase
array('foo' => array('foo', 'bar', 'barfoo'), 'bar' => 4),
);
$messages[] = array(
new Definition\Method('empty_array', null, array(), array(
new Definition\Argument('foo', new Definition\Type('string[]')),
)),
array(new \stdClass()),
array('foo' => array()),
);
return $messages;
}