From 131164b7f6082bb3f50176e3edb6be9966273271 Mon Sep 17 00:00:00 2001 From: Benjamin Eberlei Date: Wed, 1 May 2013 19:39:21 +0200 Subject: [PATCH] [DDC-1984] Throw exception if passing null into UnitOfWork#lock() - which can happen when EntityManager#find() tries to lock entity that was just deleted by another process. --- lib/Doctrine/ORM/UnitOfWork.php | 4 ++++ tests/Doctrine/Tests/ORM/UnitOfWorkTest.php | 9 +++++++++ 2 files changed, 13 insertions(+) diff --git a/lib/Doctrine/ORM/UnitOfWork.php b/lib/Doctrine/ORM/UnitOfWork.php index 498c4a699..b45e4921b 100644 --- a/lib/Doctrine/ORM/UnitOfWork.php +++ b/lib/Doctrine/ORM/UnitOfWork.php @@ -2270,6 +2270,10 @@ class UnitOfWork implements PropertyChangedListener */ public function lock($entity, $lockMode, $lockVersion = null) { + if ($entity === null) { + throw new \InvalidArgumentException("No entity passed to UnitOfWork#lock()."); + } + if ($this->getEntityState($entity, self::STATE_DETACHED) != self::STATE_MANAGED) { throw ORMInvalidArgumentException::entityNotManaged($entity); } diff --git a/tests/Doctrine/Tests/ORM/UnitOfWorkTest.php b/tests/Doctrine/Tests/ORM/UnitOfWorkTest.php index 9a645d52e..97f60f859 100644 --- a/tests/Doctrine/Tests/ORM/UnitOfWorkTest.php +++ b/tests/Doctrine/Tests/ORM/UnitOfWorkTest.php @@ -220,6 +220,15 @@ class UnitOfWorkTest extends \Doctrine\Tests\OrmTestCase // This commit should not raise an E_NOTICE $this->_unitOfWork->commit(); } + + /** + * @group DDC-1984 + */ + public function testLockWithoutEntityThrowsException() + { + $this->setExpectedException('InvalidArgumentException'); + $this->_unitOfWork->lock(null, null, null); + } } /**