#6613 #6614 #6616 moved integration test basics to a unit test that verifies basic dirty collection initialization semantics
This commit is contained in:
parent
59c5574554
commit
bdae362777
@ -3,7 +3,9 @@
|
|||||||
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\ORM\UnitOfWork;
|
||||||
use Doctrine\Tests\Mocks\ConnectionMock;
|
use Doctrine\Tests\Mocks\ConnectionMock;
|
||||||
use Doctrine\Tests\Mocks\DriverMock;
|
use Doctrine\Tests\Mocks\DriverMock;
|
||||||
use Doctrine\Tests\Mocks\EntityManagerMock;
|
use Doctrine\Tests\Mocks\EntityManagerMock;
|
||||||
@ -23,7 +25,7 @@ class PersistentCollectionTest extends OrmTestCase
|
|||||||
protected $collection;
|
protected $collection;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var \Doctrine\ORM\EntityManagerInterface
|
* @var EntityManagerMock
|
||||||
*/
|
*/
|
||||||
private $_emMock;
|
private $_emMock;
|
||||||
|
|
||||||
@ -126,4 +128,41 @@ class PersistentCollectionTest extends OrmTestCase
|
|||||||
$this->collection->add($dummy);
|
$this->collection->add($dummy);
|
||||||
$this->assertEquals([0], array_keys($this->collection->toArray()));
|
$this->assertEquals([0], array_keys($this->collection->toArray()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @group 6613
|
||||||
|
* @group 6614
|
||||||
|
* @group 6616
|
||||||
|
*/
|
||||||
|
public function testWillKeepNewItemsAfterInitialization()
|
||||||
|
{
|
||||||
|
/* @var $unitOfWork UnitOfWork|\PHPUnit_Framework_MockObject_MockObject */
|
||||||
|
$unitOfWork = $this->createMock(UnitOfWork::class);
|
||||||
|
|
||||||
|
$this->_emMock->setUnitOfWork($unitOfWork);
|
||||||
|
|
||||||
|
$this->setUpPersistentCollection();
|
||||||
|
|
||||||
|
$newElement = new \stdClass();
|
||||||
|
$persistedElement = new \stdClass();
|
||||||
|
|
||||||
|
$this->collection->add($newElement);
|
||||||
|
|
||||||
|
self::assertFalse($this->collection->isInitialized());
|
||||||
|
self::assertTrue($this->collection->isDirty());
|
||||||
|
|
||||||
|
$unitOfWork
|
||||||
|
->expects(self::once())
|
||||||
|
->method('loadCollection')
|
||||||
|
->with($this->collection)
|
||||||
|
->willReturnCallback(function (PersistentCollection $persistentCollection) use ($persistedElement) {
|
||||||
|
$persistentCollection->unwrap()->add($persistedElement);
|
||||||
|
});
|
||||||
|
|
||||||
|
$this->collection->initialize();
|
||||||
|
|
||||||
|
self::assertSame([$persistedElement, $newElement], $this->collection->toArray());
|
||||||
|
self::assertTrue($this->collection->isInitialized());
|
||||||
|
self::assertTrue($this->collection->isDirty());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user