1
0
mirror of synced 2025-02-02 21:41:45 +03:00

Basic tests around addToIdentityMap with valid string identifiers (empty string allowed)

This commit is contained in:
Marco Pivetta 2016-07-07 19:27:49 +02:00
parent 5761d07c46
commit 12789ee6ca

View File

@ -363,6 +363,43 @@ class UnitOfWorkTest extends OrmTestCase
[new ArrayCollection()],
];
}
/**
* @dataProvider entitiesWithValidIdentifiersProvider
*
* @param object $entity
*
* @return void
*/
public function testAddToIdentityMapValidIdentifiers($entity)
{
$this->_unitOfWork->registerManaged(
$entity,
$this->_emMock->getClassMetadata(get_class($entity))->getIdentifierValues($entity),
[]
);
$this->_unitOfWork->addToIdentityMap($entity);
self::assertInternalType('string', $this->_unitOfWork->getEntityIdentifier($entity));
// note: cloning to avoid lookup by spl_object_hash()
self::assertTrue($this->_unitOfWork->isInIdentityMap(clone $entity));
}
public function entitiesWithValidIdentifiersProvider()
{
$emptyString = new EntityWithStringIdentifier();
$emptyString->id = '';
$nonEmptyString = new EntityWithStringIdentifier();
$nonEmptyString->id = uniqid('', true);
return [
'empty string, single field' => [$emptyString],
'non-empty string, single field' => [$nonEmptyString],
];
}
}
/**
@ -469,3 +506,43 @@ class VersionedAssignedIdentifierEntity
*/
public $version;
}
/** @Entity */
class EntityWithStringIdentifier
{
/**
* @Id @Column(type="string")
*
* @var string|null
*/
public $id;
}
/** @Entity */
class EntityWithBooleanIdentifier
{
/**
* @Id @Column(type="boolean")
*
* @var bool|null
*/
public $id;
}
/** @Entity */
class EntityWithCompositeStringIdentifier
{
/**
* @Id @Column(type="string")
*
* @var string|null
*/
public $id1;
/**
* @Id @Column(type="string")
*
* @var string|null
*/
public $id2;
}