[PropertyAccess] Fixed PropertyPathBuilder remove that fails to reset internal indexes

This commit is contained in:
Greg ORIOL 2019-02-27 09:57:18 +01:00 committed by Fabien Potencier
parent 4203bef6f3
commit 479dff4f8a
2 changed files with 23 additions and 3 deletions

View File

@ -257,9 +257,8 @@ class PropertyPathBuilder
}
// All remaining elements should be removed
for (; $i < $length; ++$i) {
unset($this->elements[$i], $this->isIndex[$i]);
}
$this->elements = \array_slice($this->elements, 0, $i);
$this->isIndex = \array_slice($this->isIndex, 0, $i);
} else {
$diff = $insertionLength - $cutLength;

View File

@ -285,4 +285,25 @@ class PropertyPathBuilderTest extends TestCase
{
$this->builder->remove(-1);
}
public function testRemoveAndAppendAtTheEnd()
{
$this->builder->remove($this->builder->getLength() - 1);
$path = new PropertyPath('old1[old2].old3[old4][old5]');
$this->assertEquals($path, $this->builder->getPropertyPath());
$this->builder->appendProperty('old7');
$path = new PropertyPath('old1[old2].old3[old4][old5].old7');
$this->assertEquals($path, $this->builder->getPropertyPath());
$this->builder->remove($this->builder->getLength() - 1);
$path = new PropertyPath('old1[old2].old3[old4][old5]');
$this->assertEquals($path, $this->builder->getPropertyPath());
}
}