Fixed bug if a complex type contains a collection

This commit is contained in:
Francis Besset 2012-01-12 11:45:15 +01:00
parent f0031e8923
commit cfe949b781
4 changed files with 72 additions and 5 deletions

View File

@ -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()));
}

View File

@ -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;
}
}
}

View File

@ -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;
}
}
}

View File

@ -0,0 +1,28 @@
<?php
namespace BeSimple\SoapBundle\Tests\fixtures\ServiceBinding;
class SimpleArrays
{
public $array1;
private $array2;
private $array3;
public function __construct($array1, $array2, $array3)
{
$this->array1 = $array1;
$this->array2 = $array2;
$this->array3 = $array3;
}
public function getArray2()
{
return $this->array2;
}
public function getArray3()
{
return $this->array3;
}
}