From faf8b5810841d4447c5ed676aac1881391e8e1bb Mon Sep 17 00:00:00 2001 From: Francis Besset Date: Thu, 1 Sep 2011 20:18:28 +0200 Subject: [PATCH] Fixed error if an array is empty in RpcLiteralRequestMessageBinder --- .../RpcLiteralRequestMessageBinder.php | 15 +++++++---- .../RpcLiteralRequestMessageBinderTest.php | 25 ++++++++++++++++++- 2 files changed, 34 insertions(+), 6 deletions(-) diff --git a/ServiceBinding/RpcLiteralRequestMessageBinder.php b/ServiceBinding/RpcLiteralRequestMessageBinder.php index 557ff4b..5929c9f 100644 --- a/ServiceBinding/RpcLiteralRequestMessageBinder.php +++ b/ServiceBinding/RpcLiteralRequestMessageBinder.php @@ -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; diff --git a/Tests/ServiceBinding/RpcLiteralRequestMessageBinderTest.php b/Tests/ServiceBinding/RpcLiteralRequestMessageBinderTest.php index dcef0f7..dac112a 100644 --- a/Tests/ServiceBinding/RpcLiteralRequestMessageBinderTest.php +++ b/Tests/ServiceBinding/RpcLiteralRequestMessageBinderTest.php @@ -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; }