[Form] fix failing tests for remove call on an objectCollection

This commit is contained in:
jaugustin 2012-05-08 21:09:09 +02:00 committed by Bernhard Schussek
parent 076a104e86
commit 9215c4478f

View File

@ -489,6 +489,7 @@ class PropertyPath implements \IteratorAggregate
// Collection with matching adder/remover in $objectOrArray // Collection with matching adder/remover in $objectOrArray
if ($addMethod && $removeMethod) { if ($addMethod && $removeMethod) {
$itemsToAdd = is_object($value) ? clone $value : $value; $itemsToAdd = is_object($value) ? clone $value : $value;
$itemToRemove = array();
$previousValue = $this->readProperty($objectOrArray, $currentIndex); $previousValue = $this->readProperty($objectOrArray, $currentIndex);
if (is_array($previousValue) || $previousValue instanceof Traversable) { if (is_array($previousValue) || $previousValue instanceof Traversable) {
@ -503,11 +504,15 @@ class PropertyPath implements \IteratorAggregate
} }
} }
// Item not found, remove // Item not found, add to remove list
$objectOrArray->$removeMethod($previousItem); $itemToRemove[] = $previousItem;
} }
} }
foreach ($itemToRemove as $item) {
$objectOrArray->$removeMethod($item);
}
foreach ($itemsToAdd as $item) { foreach ($itemsToAdd as $item) {
$objectOrArray->$addMethod($item); $objectOrArray->$addMethod($item);
} }