Merge branch 'fix/#6110-collection-clear-should-also-clear-keys'
Close #6110
This commit is contained in:
commit
c148059593
@ -542,6 +542,8 @@ final class PersistentCollection extends AbstractLazyCollection implements Selec
|
||||
public function clear()
|
||||
{
|
||||
if ($this->initialized && $this->isEmpty()) {
|
||||
$this->collection->clear();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -107,4 +107,44 @@ class PersistentCollectionTest extends OrmTestCase
|
||||
$this->assertSame("dummy", $this->collection->get(2));
|
||||
$this->assertSame(null, $this->collection->get(3));
|
||||
}
|
||||
|
||||
/**
|
||||
* @group 6110
|
||||
*/
|
||||
public function testRemovingElementsAlsoRemovesKeys()
|
||||
{
|
||||
$this->setUpPersistentCollection();
|
||||
|
||||
$this->collection->add('dummy');
|
||||
$this->assertEquals([0], array_keys($this->collection->toArray()));
|
||||
|
||||
$this->collection->removeElement('dummy');
|
||||
$this->assertEquals([], array_keys($this->collection->toArray()));
|
||||
}
|
||||
|
||||
/**
|
||||
* @group 6110
|
||||
*/
|
||||
public function testClearWillAlsoClearKeys()
|
||||
{
|
||||
$this->setUpPersistentCollection();
|
||||
|
||||
$this->collection->add('dummy');
|
||||
$this->collection->clear();
|
||||
$this->assertEquals([], array_keys($this->collection->toArray()));
|
||||
}
|
||||
|
||||
/**
|
||||
* @group 6110
|
||||
*/
|
||||
public function testClearWillAlsoResetKeyPositions()
|
||||
{
|
||||
$this->setUpPersistentCollection();
|
||||
|
||||
$this->collection->add('dummy');
|
||||
$this->collection->removeElement('dummy');
|
||||
$this->collection->clear();
|
||||
$this->collection->add('dummy');
|
||||
$this->assertEquals([0], array_keys($this->collection->toArray()));
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user