@@ 152-180 (lines=29) @@ | ||
149 | * @group 6614 |
|
150 | * @group 6616 |
|
151 | */ |
|
152 | public function testWillKeepNewItemsInDirtyCollectionAfterInitialization() : void |
|
153 | { |
|
154 | /* @var $unitOfWork UnitOfWork|\PHPUnit_Framework_MockObject_MockObject */ |
|
155 | $unitOfWork = $this->createMock(UnitOfWork::class); |
|
156 | ||
157 | $this->_emMock->setUnitOfWork($unitOfWork); |
|
158 | ||
159 | $newElement = new \stdClass(); |
|
160 | $persistedElement = new \stdClass(); |
|
161 | ||
162 | $this->collection->add($newElement); |
|
163 | ||
164 | self::assertFalse($this->collection->isInitialized()); |
|
165 | self::assertTrue($this->collection->isDirty()); |
|
166 | ||
167 | $unitOfWork |
|
168 | ->expects(self::once()) |
|
169 | ->method('loadCollection') |
|
170 | ->with($this->collection) |
|
171 | ->willReturnCallback(function (PersistentCollection $persistentCollection) use ($persistedElement) : void { |
|
172 | $persistentCollection->unwrap()->add($persistedElement); |
|
173 | }); |
|
174 | ||
175 | $this->collection->initialize(); |
|
176 | ||
177 | self::assertSame([$persistedElement, $newElement], $this->collection->toArray()); |
|
178 | self::assertTrue($this->collection->isInitialized()); |
|
179 | self::assertTrue($this->collection->isDirty()); |
|
180 | } |
|
181 | ||
182 | /** |
|
183 | * @group 6613 |
|
@@ 231-266 (lines=36) @@ | ||
228 | * @group 6614 |
|
229 | * @group 6616 |
|
230 | */ |
|
231 | public function testWillNotMarkCollectionAsDirtyAfterInitializationIfNoElementsWereAdded() : void |
|
232 | { |
|
233 | /* @var $unitOfWork UnitOfWork|\PHPUnit_Framework_MockObject_MockObject */ |
|
234 | $unitOfWork = $this->createMock(UnitOfWork::class); |
|
235 | ||
236 | $this->_emMock->setUnitOfWork($unitOfWork); |
|
237 | ||
238 | $newElementThatIsAlsoPersisted = new \stdClass(); |
|
239 | $persistedElement = new \stdClass(); |
|
240 | ||
241 | $this->collection->add($newElementThatIsAlsoPersisted); |
|
242 | ||
243 | self::assertFalse($this->collection->isInitialized()); |
|
244 | self::assertTrue($this->collection->isDirty()); |
|
245 | ||
246 | $unitOfWork |
|
247 | ->expects(self::once()) |
|
248 | ->method('loadCollection') |
|
249 | ->with($this->collection) |
|
250 | ->willReturnCallback(function (PersistentCollection $persistentCollection) use ( |
|
251 | $persistedElement, |
|
252 | $newElementThatIsAlsoPersisted |
|
253 | ) : void { |
|
254 | $persistentCollection->unwrap()->add($newElementThatIsAlsoPersisted); |
|
255 | $persistentCollection->unwrap()->add($persistedElement); |
|
256 | }); |
|
257 | ||
258 | $this->collection->initialize(); |
|
259 | ||
260 | self::assertSame( |
|
261 | [$newElementThatIsAlsoPersisted, $persistedElement], |
|
262 | $this->collection->toArray() |
|
263 | ); |
|
264 | self::assertTrue($this->collection->isInitialized()); |
|
265 | self::assertFalse($this->collection->isDirty()); |
|
266 | } |
|
267 | } |
|
268 |