[PropertyAccess] ->getValue() should be read-only

This commit is contained in:
Nicolas Grekas 2016-04-20 17:20:31 +02:00
parent 40b4cb2c4a
commit fa6852968b
2 changed files with 7 additions and 4 deletions

View File

@ -275,10 +275,11 @@ class PropertyAccessor implements PropertyAccessorInterface
(is_array($zval[self::VALUE]) && !isset($zval[self::VALUE][$property]) && !array_key_exists($property, $zval[self::VALUE]))
) {
if ($i + 1 < $propertyPath->getLength()) {
$zval[self::VALUE][$property] = array();
if (isset($zval[self::REF])) {
$zval[self::VALUE][$property] = array();
$zval[self::REF] = $zval[self::VALUE];
} else {
$zval[self::VALUE] = array($property => array());
}
}
}

View File

@ -92,9 +92,11 @@ class PropertyAccessorTest extends \PHPUnit_Framework_TestCase
public function testGetValueReadsArrayWithMissingIndexForCustomPropertyPath()
{
$array = array('child' => array('index' => array()));
$object = new \ArrayObject();
$array = array('child' => array('index' => $object));
$this->assertNull($this->propertyAccessor->getValue($array, '[child][index][firstName]'));
$this->assertNull($this->propertyAccessor->getValue($array, '[child][index][foo][bar]'));
$this->assertSame(array(), $object->getArrayCopy());
}
public function testGetValueReadsProperty()