When invalid (null) identifiers are provided, an exception should be thrown
This commit is contained in:
parent
da7582d329
commit
9abccba109
@ -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()],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
x
Reference in New Issue
Block a user