Code Duplication    Length = 29-36 lines in 2 locations

tests/Doctrine/Tests/ORM/PersistentCollectionTest.php 2 locations

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