Merge branch 'DDC-2565' into 2.4
This commit is contained in:
commit
261eacdbfc
@ -757,6 +757,8 @@ final class PersistentCollection implements Collection, Selectable
|
|||||||
*/
|
*/
|
||||||
public function key()
|
public function key()
|
||||||
{
|
{
|
||||||
|
$this->initialize();
|
||||||
|
|
||||||
return $this->coll->key();
|
return $this->coll->key();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -765,6 +767,8 @@ final class PersistentCollection implements Collection, Selectable
|
|||||||
*/
|
*/
|
||||||
public function current()
|
public function current()
|
||||||
{
|
{
|
||||||
|
$this->initialize();
|
||||||
|
|
||||||
return $this->coll->current();
|
return $this->coll->current();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -773,6 +777,8 @@ final class PersistentCollection implements Collection, Selectable
|
|||||||
*/
|
*/
|
||||||
public function next()
|
public function next()
|
||||||
{
|
{
|
||||||
|
$this->initialize();
|
||||||
|
|
||||||
return $this->coll->next();
|
return $this->coll->next();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -6,16 +6,21 @@ use Doctrine\Common\Collections\ArrayCollection;
|
|||||||
use Doctrine\ORM\PersistentCollection;
|
use Doctrine\ORM\PersistentCollection;
|
||||||
use Doctrine\Tests\Mocks\ConnectionMock;
|
use Doctrine\Tests\Mocks\ConnectionMock;
|
||||||
use Doctrine\Tests\Mocks\EntityManagerMock;
|
use Doctrine\Tests\Mocks\EntityManagerMock;
|
||||||
use Doctrine\Tests\Models\ECommerce\ECommerceProduct;
|
use Doctrine\Tests\Models\ECommerce\ECommerceCart;
|
||||||
|
use Doctrine\Tests\OrmTestCase;
|
||||||
require_once __DIR__ . '/../TestInit.php';
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests the lazy-loading capabilities of the PersistentCollection.
|
* Tests the lazy-loading capabilities of the PersistentCollection and the initialization of collections.
|
||||||
* @author Giorgio Sironi <piccoloprincipeazzurro@gmail.com>
|
* @author Giorgio Sironi <piccoloprincipeazzurro@gmail.com>
|
||||||
|
* @author Austin Morris <austin.morris@gmail.com>
|
||||||
*/
|
*/
|
||||||
class PersistentCollectionTest extends \Doctrine\Tests\OrmTestCase
|
class PersistentCollectionTest extends OrmTestCase
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* @var PersistentCollection
|
||||||
|
*/
|
||||||
|
protected $collection;
|
||||||
|
|
||||||
private $_connectionMock;
|
private $_connectionMock;
|
||||||
private $_emMock;
|
private $_emMock;
|
||||||
|
|
||||||
@ -27,6 +32,17 @@ class PersistentCollectionTest extends \Doctrine\Tests\OrmTestCase
|
|||||||
$this->_emMock = EntityManagerMock::create($this->_connectionMock);
|
$this->_emMock = EntityManagerMock::create($this->_connectionMock);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set up the PersistentCollection used for collection initialization tests.
|
||||||
|
*/
|
||||||
|
public function setUpPersistentCollection()
|
||||||
|
{
|
||||||
|
$classMetaData = $this->_emMock->getClassMetadata('Doctrine\Tests\Models\ECommerce\ECommerceCart');
|
||||||
|
$this->collection = new PersistentCollection($this->_emMock, $classMetaData, new ArrayCollection);
|
||||||
|
$this->collection->setInitialized(false);
|
||||||
|
$this->collection->setOwner(new ECommerceCart(), $classMetaData->getAssociationMapping('products'));
|
||||||
|
}
|
||||||
|
|
||||||
public function testCanBePutInLazyLoadingMode()
|
public function testCanBePutInLazyLoadingMode()
|
||||||
{
|
{
|
||||||
$class = $this->_emMock->getClassMetadata('Doctrine\Tests\Models\ECommerce\ECommerceProduct');
|
$class = $this->_emMock->getClassMetadata('Doctrine\Tests\Models\ECommerce\ECommerceProduct');
|
||||||
@ -34,4 +50,34 @@ class PersistentCollectionTest extends \Doctrine\Tests\OrmTestCase
|
|||||||
$collection->setInitialized(false);
|
$collection->setInitialized(false);
|
||||||
$this->assertFalse($collection->isInitialized());
|
$this->assertFalse($collection->isInitialized());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test that PersistentCollection::current() initializes the collection.
|
||||||
|
*/
|
||||||
|
public function testCurrentInitializesCollection()
|
||||||
|
{
|
||||||
|
$this->setUpPersistentCollection();
|
||||||
|
$this->collection->current();
|
||||||
|
$this->assertTrue($this->collection->isInitialized());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test that PersistentCollection::key() initializes the collection.
|
||||||
|
*/
|
||||||
|
public function testKeyInitializesCollection()
|
||||||
|
{
|
||||||
|
$this->setUpPersistentCollection();
|
||||||
|
$this->collection->key();
|
||||||
|
$this->assertTrue($this->collection->isInitialized());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test that PersistentCollection::next() initializes the collection.
|
||||||
|
*/
|
||||||
|
public function testNextInitializesCollection()
|
||||||
|
{
|
||||||
|
$this->setUpPersistentCollection();
|
||||||
|
$this->collection->next();
|
||||||
|
$this->assertTrue($this->collection->isInitialized());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user