Skip to content

Commit 844ce77

Browse files
authored
Added runtime deprecation to UnitOfWork::commit() and clear() (#9327)
1 parent cf3a185 commit 844ce77

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

lib/Doctrine/ORM/UnitOfWork.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,15 @@ public function __construct(EntityManagerInterface $em)
340340
*/
341341
public function commit($entity = null)
342342
{
343+
if ($entity !== null) {
344+
Deprecation::triggerIfCalledFromOutside(
345+
'doctrine/orm',
346+
'https://github.com/doctrine/orm/issues/8459',
347+
'Calling %s() with any arguments to commit specific entities is deprecated and will not be supported in Doctrine ORM 3.0.',
348+
__METHOD__
349+
);
350+
}
351+
343352
$connection = $this->em->getConnection();
344353

345354
if ($connection instanceof PrimaryReadReplicaConnection) {
@@ -2554,6 +2563,13 @@ public function clear($entityName = null)
25542563
$this->eagerLoadingEntities =
25552564
$this->orphanRemovals = [];
25562565
} else {
2566+
Deprecation::triggerIfCalledFromOutside(
2567+
'doctrine/orm',
2568+
'https://github.com/doctrine/orm/issues/8460',
2569+
'Calling %s() with any arguments to clear specific entities is deprecated and will not be supported in Doctrine ORM 3.0.',
2570+
__METHOD__
2571+
);
2572+
25572573
$this->clearIdentityMapForEntityName($entityName);
25582574
$this->clearEntityInsertionsForEntityName($entityName);
25592575
}

tests/Doctrine/Tests/ORM/UnitOfWorkTest.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use Doctrine\Common\Collections\ArrayCollection;
88
use Doctrine\Common\Collections\Collection;
99
use Doctrine\Common\EventManager;
10+
use Doctrine\Deprecations\PHPUnit\VerifyDeprecations;
1011
use Doctrine\ORM\EntityNotFoundException;
1112
use Doctrine\ORM\Events;
1213
use Doctrine\ORM\Mapping\ClassMetadata;
@@ -50,6 +51,8 @@
5051
*/
5152
class UnitOfWorkTest extends OrmTestCase
5253
{
54+
use VerifyDeprecations;
55+
5356
/**
5457
* SUT
5558
*
@@ -226,6 +229,9 @@ public function testChangeTrackingNotifyIndividualCommit(): void
226229

227230
$this->_unitOfWork->persist($entity);
228231
$this->_unitOfWork->persist($entity2);
232+
233+
$this->expectDeprecationWithIdentifier('https://github.com/doctrine/orm/issues/8459');
234+
229235
$this->_unitOfWork->commit($entity);
230236
$this->_unitOfWork->commit();
231237

@@ -393,6 +399,8 @@ public function testPersistedEntityAndClearManager(): void
393399
$this->_unitOfWork->persist($entity2);
394400
self::assertTrue($this->_unitOfWork->isInIdentityMap($entity2));
395401

402+
$this->expectDeprecationWithIdentifier('https://github.com/doctrine/orm/issues/8460');
403+
396404
$this->_unitOfWork->clear(Country::class);
397405
self::assertTrue($this->_unitOfWork->isInIdentityMap($entity1));
398406
self::assertFalse($this->_unitOfWork->isInIdentityMap($entity2));
@@ -414,6 +422,8 @@ public function testEntityChangeSetIsNotClearedAfterFlushOnSingleEntity(): void
414422
$this->_unitOfWork->persist($entity1);
415423
$this->_unitOfWork->persist($entity2);
416424

425+
$this->expectDeprecationWithIdentifier('https://github.com/doctrine/orm/issues/8459');
426+
417427
$this->_unitOfWork->commit($entity1);
418428
self::assertEmpty($this->_unitOfWork->getEntityChangeSet($entity1));
419429
self::assertCount(1, $this->_unitOfWork->getEntityChangeSet($entity2));
@@ -436,6 +446,8 @@ public function testEntityChangeSetIsNotClearedAfterFlushOnArrayOfEntities(): vo
436446
$this->_unitOfWork->persist($entity2);
437447
$this->_unitOfWork->persist($entity3);
438448

449+
$this->expectDeprecationWithIdentifier('https://github.com/doctrine/orm/issues/8459');
450+
439451
$this->_unitOfWork->commit([$entity1, $entity3]);
440452

441453
self::assertEmpty($this->_unitOfWork->getEntityChangeSet($entity1));

0 commit comments

Comments
 (0)