From cfe949b78159031cc46a08ae81ac44d8228c4c9c Mon Sep 17 00:00:00 2001 From: Francis Besset Date: Thu, 12 Jan 2012 11:45:15 +0100 Subject: [PATCH] Fixed bug if a complex type contains a collection --- .../RpcLiteralRequestMessageBinder.php | 6 ++++ .../RpcLiteralResponseMessageBinder.php | 12 ++++--- .../RpcLiteralRequestMessageBinderTest.php | 31 ++++++++++++++++++- .../fixtures/ServiceBinding/SimpleArrays.php | 28 +++++++++++++++++ 4 files changed, 72 insertions(+), 5 deletions(-) create mode 100644 Tests/fixtures/ServiceBinding/SimpleArrays.php diff --git a/ServiceBinding/RpcLiteralRequestMessageBinder.php b/ServiceBinding/RpcLiteralRequestMessageBinder.php index edef394..21cfe17 100644 --- a/ServiceBinding/RpcLiteralRequestMessageBinder.php +++ b/ServiceBinding/RpcLiteralRequestMessageBinder.php @@ -98,6 +98,12 @@ class RpcLiteralRequestMessageBinder implements MessageBinderInterface $value = $this->processType($type->getValue(), $value); + if ($p->isPublic()) { + $message->{$type->getName()} = $value; + } else { + $p->setValue($message, $value); + } + if (!$type->isNillable() && null === $value) { throw new \SoapFault('SOAP_ERROR_COMPLEX_TYPE', sprintf('"%s:%s" cannot be null.', ucfirst(Wsdl::translateType($phpType)), $type->getName())); } diff --git a/ServiceBinding/RpcLiteralResponseMessageBinder.php b/ServiceBinding/RpcLiteralResponseMessageBinder.php index 5cb6310..d4e57df 100644 --- a/ServiceBinding/RpcLiteralResponseMessageBinder.php +++ b/ServiceBinding/RpcLiteralResponseMessageBinder.php @@ -76,13 +76,17 @@ class RpcLiteralResponseMessageBinder implements MessageBinderInterface $p = $r->getProperty($type->getName()); if ($p->isPublic()) { $value = $message->{$type->getName()}; - - $message->{$type->getName()} = $this->processType($type->getValue(), $value); } else { $p->setAccessible(true); $value = $p->getValue($message); + } - $p->setValue($message, $this->processType($type->getValue(), $value)); + $value = $this->processType($type->getValue(), $value); + + if ($p->isPublic()) { + $message->{$type->getName()} = $value; + } else { + $p->setValue($message, $value); } if (!$type->isNillable() && null === $value) { @@ -92,4 +96,4 @@ class RpcLiteralResponseMessageBinder implements MessageBinderInterface return $message; } -} \ No newline at end of file +} diff --git a/Tests/ServiceBinding/RpcLiteralRequestMessageBinderTest.php b/Tests/ServiceBinding/RpcLiteralRequestMessageBinderTest.php index c656611..b48adf7 100644 --- a/Tests/ServiceBinding/RpcLiteralRequestMessageBinderTest.php +++ b/Tests/ServiceBinding/RpcLiteralRequestMessageBinderTest.php @@ -115,6 +115,29 @@ class RpcLiteralRequestMessageBinderTest extends \PHPUnit_Framework_TestCase $this->assertEquals(array('fooBar' => $fooBar), $result); } + 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()); + } + public function testProcessMessageWithEmptyArrayComplexType() { $messageBinder = new RpcLiteralRequestMessageBinder(); @@ -217,6 +240,12 @@ class RpcLiteralRequestMessageBinderTest extends \PHPUnit_Framework_TestCase array('bar', 'BeSimple\SoapBundle\Tests\fixtures\ServiceBinding\Bar'), )); + $definitionComplexTypes['BeSimple\SoapBundle\Tests\fixtures\ServiceBinding\SimpleArrays'] = $this->createComplexTypeCollection(array( + array('array1', 'string[]', true), + array('array2', 'string[]'), + array('array3', 'string[]'), + )); + $definitionComplexTypes['BeSimple\SoapBundle\Tests\fixtures\ServiceBinding\FooRecursive'] = $this->createComplexTypeCollection(array( array('bar', 'BeSimple\SoapBundle\Tests\fixtures\ServiceBinding\BarRecursive'), )); @@ -246,4 +275,4 @@ class RpcLiteralRequestMessageBinderTest extends \PHPUnit_Framework_TestCase return $collection; } -} \ No newline at end of file +} diff --git a/Tests/fixtures/ServiceBinding/SimpleArrays.php b/Tests/fixtures/ServiceBinding/SimpleArrays.php new file mode 100644 index 0000000..e17a640 --- /dev/null +++ b/Tests/fixtures/ServiceBinding/SimpleArrays.php @@ -0,0 +1,28 @@ +array1 = $array1; + $this->array2 = $array2; + $this->array3 = $array3; + } + + public function getArray2() + { + return $this->array2; + } + + public function getArray3() + { + return $this->array3; + } +}