Throw an exception instead of a workaround
This commit is contained in:
parent
4a87f00fab
commit
2a7d21ad18
@ -2363,6 +2363,10 @@ class UnitOfWork implements PropertyChangedListener
|
|||||||
*/
|
*/
|
||||||
public function clear($entityName = null)
|
public function clear($entityName = null)
|
||||||
{
|
{
|
||||||
|
if ($entityName !== null && !is_string($entityName)) {
|
||||||
|
throw new \InvalidArgumentException(sprintf('Argument 1 passed to %s() must be a string, %s given', __METHOD__, gettype($entityName)));
|
||||||
|
}
|
||||||
|
|
||||||
if ($entityName === null) {
|
if ($entityName === null) {
|
||||||
$this->identityMap =
|
$this->identityMap =
|
||||||
$this->entityIdentifiers =
|
$this->entityIdentifiers =
|
||||||
@ -3442,10 +3446,6 @@ class UnitOfWork implements PropertyChangedListener
|
|||||||
*/
|
*/
|
||||||
private function clearIdentityMapForEntityName($entityName)
|
private function clearIdentityMapForEntityName($entityName)
|
||||||
{
|
{
|
||||||
if (is_object($entityName)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (! isset($this->identityMap[$entityName])) {
|
if (! isset($this->identityMap[$entityName])) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -351,16 +351,28 @@ class UnitOfWorkTest extends OrmTestCase
|
|||||||
|
|
||||||
public function testClearManagerWithObject()
|
public function testClearManagerWithObject()
|
||||||
{
|
{
|
||||||
|
$this->expectException(\InvalidArgumentException::class);
|
||||||
|
$this->expectExceptionMessage('must be a string');
|
||||||
|
|
||||||
$entity = new Country(456, 'United Kingdom');
|
$entity = new Country(456, 'United Kingdom');
|
||||||
|
|
||||||
$this->_unitOfWork->persist($entity);
|
$this->_unitOfWork->persist($entity);
|
||||||
$this->assertTrue($this->_unitOfWork->isInIdentityMap($entity));
|
$this->assertTrue($this->_unitOfWork->isInIdentityMap($entity));
|
||||||
|
|
||||||
$this->_unitOfWork->clear($entity);
|
$this->_unitOfWork->clear($entity);
|
||||||
|
}
|
||||||
|
|
||||||
// true because entity wasn't a string so it wasn't cleared
|
public function testClearManagerWithNullValue()
|
||||||
|
{
|
||||||
|
$entity = new Country(456, 'United Kingdom');
|
||||||
|
|
||||||
|
$this->_unitOfWork->persist($entity);
|
||||||
$this->assertTrue($this->_unitOfWork->isInIdentityMap($entity));
|
$this->assertTrue($this->_unitOfWork->isInIdentityMap($entity));
|
||||||
$this->assertTrue($this->_unitOfWork->isScheduledForInsert($entity));
|
|
||||||
|
$this->_unitOfWork->clear();
|
||||||
|
|
||||||
|
$this->assertFalse($this->_unitOfWork->isInIdentityMap($entity));
|
||||||
|
$this->assertFalse($this->_unitOfWork->isScheduledForInsert($entity));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
x
Reference in New Issue
Block a user