PersistentCollection
should still accept null
and array
as constructor argument, as it did before
This commit is contained in:
parent
cb3179865b
commit
c2f6b09ee0
@ -3,8 +3,10 @@
|
|||||||
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\EntityManagerMock;
|
use Doctrine\Tests\Mocks\EntityManagerMock;
|
||||||
use Doctrine\Tests\Models\ECommerce\ECommerceCart;
|
use Doctrine\Tests\Models\ECommerce\ECommerceCart;
|
||||||
use Doctrine\Tests\OrmTestCase;
|
use Doctrine\Tests\OrmTestCase;
|
||||||
@ -21,15 +23,16 @@ class PersistentCollectionTest extends OrmTestCase
|
|||||||
*/
|
*/
|
||||||
protected $collection;
|
protected $collection;
|
||||||
|
|
||||||
private $_connectionMock;
|
/**
|
||||||
|
* @var \Doctrine\ORM\EntityManagerInterface
|
||||||
|
*/
|
||||||
private $_emMock;
|
private $_emMock;
|
||||||
|
|
||||||
protected function setUp()
|
protected function setUp()
|
||||||
{
|
{
|
||||||
parent::setUp();
|
parent::setUp();
|
||||||
// SUT
|
|
||||||
$this->_connectionMock = new ConnectionMock(array(), new \Doctrine\Tests\Mocks\DriverMock());
|
$this->_emMock = EntityManagerMock::create(new ConnectionMock([], new DriverMock()));
|
||||||
$this->_emMock = EntityManagerMock::create($this->_connectionMock);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -80,4 +83,39 @@ class PersistentCollectionTest extends OrmTestCase
|
|||||||
$this->collection->next();
|
$this->collection->next();
|
||||||
$this->assertTrue($this->collection->isInitialized());
|
$this->assertTrue($this->collection->isInitialized());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testAcceptsArrayAsConstructorArgument()
|
||||||
|
{
|
||||||
|
$metadata = $this->_emMock->getClassMetadata('Doctrine\Tests\Models\ECommerce\ECommerceCart');
|
||||||
|
|
||||||
|
$collection = new PersistentCollection($this->_emMock, $metadata, []);
|
||||||
|
|
||||||
|
$this->assertEmpty($collection);
|
||||||
|
$this->tryGenericCollectionOperations($collection);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testAcceptsNullAsConstructorArgument()
|
||||||
|
{
|
||||||
|
$metadata = $this->_emMock->getClassMetadata('Doctrine\Tests\Models\ECommerce\ECommerceCart');
|
||||||
|
|
||||||
|
$collection = new PersistentCollection($this->_emMock, $metadata, null);
|
||||||
|
|
||||||
|
$this->assertEmpty($collection);
|
||||||
|
$this->tryGenericCollectionOperations($collection);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function tryGenericCollectionOperations(Collection $collection)
|
||||||
|
{
|
||||||
|
$count = count($collection);
|
||||||
|
$object = new \stdClass();
|
||||||
|
|
||||||
|
$collection->add($object);
|
||||||
|
|
||||||
|
$this->assertTrue($collection->contains($object));
|
||||||
|
$this->assertCount($count + 1, $collection);
|
||||||
|
|
||||||
|
$collection->removeElement($object);
|
||||||
|
|
||||||
|
$this->assertCount($count, $collection);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user