From 9abccba1093bbefbd4b08e676b74265ceaa8dbfa Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Thu, 7 Jul 2016 19:58:43 +0200 Subject: [PATCH] When invalid (null) identifiers are provided, an exception should be thrown --- tests/Doctrine/Tests/ORM/UnitOfWorkTest.php | 56 +++++++++++++++++++++ 1 file changed, 56 insertions(+) diff --git a/tests/Doctrine/Tests/ORM/UnitOfWorkTest.php b/tests/Doctrine/Tests/ORM/UnitOfWorkTest.php index 67121e1a4..e94a187d7 100644 --- a/tests/Doctrine/Tests/ORM/UnitOfWorkTest.php +++ b/tests/Doctrine/Tests/ORM/UnitOfWorkTest.php @@ -6,6 +6,7 @@ use Doctrine\Common\Collections\ArrayCollection; use Doctrine\Common\NotifyPropertyChanged; use Doctrine\Common\PropertyChangedListener; use Doctrine\ORM\Mapping\ClassMetadata; +use Doctrine\ORM\ORMInvalidArgumentException; use Doctrine\ORM\UnitOfWork; use Doctrine\Tests\Mocks\ConnectionMock; use Doctrine\Tests\Mocks\DriverMock; @@ -422,6 +423,61 @@ class UnitOfWorkTest extends OrmTestCase 'boolean false' => [$booleanFalse, ''], ]; } + + /** + * @dataProvider entitiesWithInvalidIdentifiersProvider + * + * @param object $entity + * + * @return void + */ + public function testAddToIdentityMapInvalidIdentifiers($entity) + { + $this->_unitOfWork->registerManaged( + $entity, + $this->_emMock->getClassMetadata(get_class($entity))->getIdentifierValues($entity), + [] + ); + + $this->expectException(ORMInvalidArgumentException::class); + + $this->_unitOfWork->addToIdentityMap($entity); + } + + + public function entitiesWithInvalidIdentifiersProvider() + { + $emptyString = new EntityWithStringIdentifier(); + + $emptyString->id = ''; + + $nonEmptyString = new EntityWithStringIdentifier(); + + $nonEmptyString->id = uniqid('id', true); + + $emptyStrings = new EntityWithCompositeStringIdentifier(); + + $emptyStrings->id1 = ''; + $emptyStrings->id2 = ''; + + $nonEmptyStrings = new EntityWithCompositeStringIdentifier(); + + $nonEmptyStrings->id1 = uniqid('id1', true); + $nonEmptyStrings->id2 = uniqid('id2', true); + + $booleanTrue = new EntityWithBooleanIdentifier(); + + $booleanTrue->id = true; + + $booleanFalse = new EntityWithBooleanIdentifier(); + + $booleanFalse->id = false; + + return [ + 'null string, single field' => [new EntityWithStringIdentifier()], + 'null strings, two fieldds' => [new EntityWithCompositeStringIdentifier()], + ]; + } } /**