[PropertyAccessor] Added test to allow null value for a array
This commit is contained in:
parent
d5e9de2f94
commit
9706b090c0
@ -117,10 +117,15 @@ class PropertyAccessor implements PropertyAccessorInterface
|
||||
|
||||
$property = $propertyPath->getElement($i);
|
||||
$isIndex = $propertyPath->isIndex($i);
|
||||
$isArrayAccess = is_array($objectOrArray) || $objectOrArray instanceof \ArrayAccess;
|
||||
|
||||
// Create missing nested arrays on demand
|
||||
if ($isIndex && $isArrayAccess && !isset($objectOrArray[$property])) {
|
||||
if (
|
||||
$isIndex &&
|
||||
(
|
||||
($objectOrArray instanceof \ArrayAccess && !isset($objectOrArray[$property])) ||
|
||||
(is_array($objectOrArray) && !array_key_exists($property, $objectOrArray))
|
||||
)
|
||||
) {
|
||||
$objectOrArray[$property] = $i + 1 < $propertyPath->getLength() ? array() : null;
|
||||
}
|
||||
|
||||
|
@ -221,6 +221,12 @@ class PropertyAccessorTest extends \PHPUnit_Framework_TestCase
|
||||
$this->propertyAccessor->getValue('', 'foobar');
|
||||
}
|
||||
|
||||
public function testGetValueWhenArrayValueIsNull()
|
||||
{
|
||||
$this->propertyAccessor = new PropertyAccessor(false, true);
|
||||
$this->assertNull($this->propertyAccessor->getValue(array('index' => array('nullable' => null)), '[index][nullable]'));
|
||||
}
|
||||
|
||||
public function testSetValueUpdatesArrays()
|
||||
{
|
||||
$array = array();
|
||||
|
Reference in New Issue
Block a user