Merge branch 'fix/#6110-collection-clear-should-also-clear-keys-2.5' into 2.5
Close #6110
This commit is contained in:
commit
4d699789a2
@ -536,6 +536,8 @@ final class PersistentCollection extends AbstractLazyCollection implements Selec
|
|||||||
public function clear()
|
public function clear()
|
||||||
{
|
{
|
||||||
if ($this->initialized && $this->isEmpty()) {
|
if ($this->initialized && $this->isEmpty()) {
|
||||||
|
$this->collection->clear();
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3,7 +3,6 @@
|
|||||||
namespace Doctrine\Tests\ORM;
|
namespace Doctrine\Tests\ORM;
|
||||||
|
|
||||||
use Doctrine\Common\Collections\ArrayCollection;
|
use Doctrine\Common\Collections\ArrayCollection;
|
||||||
use Doctrine\Common\Collections\Collection;
|
|
||||||
use Doctrine\ORM\PersistentCollection;
|
use Doctrine\ORM\PersistentCollection;
|
||||||
use Doctrine\Tests\Mocks\ConnectionMock;
|
use Doctrine\Tests\Mocks\ConnectionMock;
|
||||||
use Doctrine\Tests\Mocks\DriverMock;
|
use Doctrine\Tests\Mocks\DriverMock;
|
||||||
@ -83,4 +82,44 @@ class PersistentCollectionTest extends OrmTestCase
|
|||||||
$this->collection->next();
|
$this->collection->next();
|
||||||
$this->assertTrue($this->collection->isInitialized());
|
$this->assertTrue($this->collection->isInitialized());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @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