1
0
mirror of synced 2025-02-02 21:41:45 +03:00

#6613 #6614 #6616 moved integration test basics to a unit test that verifies basic dirty collection initialization semantics

This commit is contained in:
Marco Pivetta 2017-08-11 18:58:05 +02:00
parent 345cf1acf8
commit 04a5b122b0
No known key found for this signature in database
GPG Key ID: 4167D3337FD9D629

View File

@ -3,7 +3,9 @@
namespace Doctrine\Tests\ORM;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\PersistentCollection;
use Doctrine\ORM\UnitOfWork;
use Doctrine\Tests\Mocks\ConnectionMock;
use Doctrine\Tests\Mocks\DriverMock;
use Doctrine\Tests\Mocks\EntityManagerMock;
@ -24,7 +26,7 @@ class PersistentCollectionTest extends OrmTestCase
protected $collection;
/**
* @var \Doctrine\ORM\EntityManagerInterface
* @var EntityManagerMock
*/
private $_emMock;
@ -151,4 +153,41 @@ class PersistentCollectionTest extends OrmTestCase
$this->collection->add($dummy);
$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());
}
}