From 479f8c8b997372dd38ee0a58dd7100fd2024d394 Mon Sep 17 00:00:00 2001 From: Soliman Date: Mon, 6 Jan 2020 10:40:50 +0100 Subject: [PATCH] Update unit tests --- UPGRADE.md | 9 +++++++- lib/Doctrine/ORM/UnitOfWork.php | 3 ++- .../Tests/Mocks/ConnectionCommitFailMock.php | 22 ------------------- tests/Doctrine/Tests/ORM/UnitOfWorkTest.php | 16 +++++++------- 4 files changed, 18 insertions(+), 32 deletions(-) delete mode 100644 tests/Doctrine/Tests/Mocks/ConnectionCommitFailMock.php diff --git a/UPGRADE.md b/UPGRADE.md index c6c6eaaa01..12a10deb83 100644 --- a/UPGRADE.md +++ b/UPGRADE.md @@ -1,3 +1,10 @@ +# Upgrade to 2.8 + +## Minor BC BREAK: Failed commit now throw OptimisticLockException + +Method `Doctrine\ORM\UnitOfWork#commit()` can throw an OptimisticLockException when a commit silently fails and returns false +since `Doctrine\DBAL\Connection#commit()` signature changed from returning void to boolean + # Upgrade to 2.7 ## Added `Doctrine\ORM\AbstractQuery#enableResultCache()` and `Doctrine\ORM\AbstractQuery#disableResultCache()` methods @@ -24,7 +31,7 @@ Method `Doctrine\ORM\AbstractQuery#useResultCache()` is deprecated because it is and `disableResultCache()`. It will be removed in 3.0. ## Deprecated code generators and related console commands - + These console commands have been deprecated: * `orm:convert-mapping` diff --git a/lib/Doctrine/ORM/UnitOfWork.php b/lib/Doctrine/ORM/UnitOfWork.php index f28b612754..8070989de5 100644 --- a/lib/Doctrine/ORM/UnitOfWork.php +++ b/lib/Doctrine/ORM/UnitOfWork.php @@ -47,6 +47,7 @@ use Throwable; use UnexpectedValueException; use function get_class; +use function is_object; /** * The UnitOfWork is responsible for tracking changes to objects during an @@ -425,7 +426,7 @@ public function commit($entity = null) } // Commit failed silently - if ( ! $conn->commit()) { + if (false === $conn->commit()) { $object = is_object($entity) ? $entity : null; throw new OptimisticLockException('Commit failed', $object); diff --git a/tests/Doctrine/Tests/Mocks/ConnectionCommitFailMock.php b/tests/Doctrine/Tests/Mocks/ConnectionCommitFailMock.php deleted file mode 100644 index c31b50bf4f..0000000000 --- a/tests/Doctrine/Tests/Mocks/ConnectionCommitFailMock.php +++ /dev/null @@ -1,22 +0,0 @@ -_connectionMock = new ConnectionCommitFailMock([], new DriverMock()); - $this->eventManager = $this->getMockBuilder(EventManager::class)->getMock(); - $this->_emMock = EntityManagerMock::create($this->_connectionMock, null, $this->eventManager); - $this->_unitOfWork = new UnitOfWorkMock($this->_emMock); - $this->_emMock->setUnitOfWork($this->_unitOfWork); + $this->_connectionMock = $this->getMockBuilder(ConnectionMock::class) + ->setConstructorArgs([[], new DriverMock()]) + ->setMethods(['commit']) + ->getMock(); + + $this->_connectionMock->method('commit')->willReturn(false); // Setup fake persister and id generator $userPersister = new EntityPersisterMock($this->_emMock, $this->_emMock->getClassMetadata(ForumUser::class)); @@ -810,7 +810,7 @@ public function testCommitThrowOptimisticLockExceptionWhenConnectionCommitReturn $this->_unitOfWork->setEntityPersister(ForumUser::class, $userPersister); // Create a test user - $user = new ForumUser(); + $user = new ForumUser(); $user->username = 'Jasper'; $this->_unitOfWork->persist($user);