1
0
mirror of synced 2025-02-09 08:49:26 +03:00

When invalid (null) identifiers are provided, an exception should be thrown

This commit is contained in:
Marco Pivetta 2016-07-07 19:58:43 +02:00
parent da7582d329
commit 9abccba109

View File

@ -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()],
];
}
}
/**