From 12789ee6cacc2cad32c9b244e8e41bef8b7b3529 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Thu, 7 Jul 2016 19:27:49 +0200 Subject: [PATCH 01/14] Basic tests around `addToIdentityMap` with valid string identifiers (empty string allowed) --- tests/Doctrine/Tests/ORM/UnitOfWorkTest.php | 77 +++++++++++++++++++++ 1 file changed, 77 insertions(+) diff --git a/tests/Doctrine/Tests/ORM/UnitOfWorkTest.php b/tests/Doctrine/Tests/ORM/UnitOfWorkTest.php index 9b0c6a8f5..51823aa27 100644 --- a/tests/Doctrine/Tests/ORM/UnitOfWorkTest.php +++ b/tests/Doctrine/Tests/ORM/UnitOfWorkTest.php @@ -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; +} From 549bfe127c79266f64b6534ffed81799570760f3 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Thu, 7 Jul 2016 19:34:24 +0200 Subject: [PATCH 02/14] Correcting test case: expecting identifier hashes to support empty strings --- tests/Doctrine/Tests/ORM/UnitOfWorkTest.php | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/tests/Doctrine/Tests/ORM/UnitOfWorkTest.php b/tests/Doctrine/Tests/ORM/UnitOfWorkTest.php index 51823aa27..b0b38b9e2 100644 --- a/tests/Doctrine/Tests/ORM/UnitOfWorkTest.php +++ b/tests/Doctrine/Tests/ORM/UnitOfWorkTest.php @@ -368,10 +368,11 @@ class UnitOfWorkTest extends OrmTestCase * @dataProvider entitiesWithValidIdentifiersProvider * * @param object $entity + * @param string $idHash * * @return void */ - public function testAddToIdentityMapValidIdentifiers($entity) + public function testAddToIdentityMapValidIdentifiers($entity, $idHash) { $this->_unitOfWork->registerManaged( $entity, @@ -380,9 +381,8 @@ class UnitOfWorkTest extends OrmTestCase ); $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)); + self::assertSame($entity, $this->_unitOfWork->getByIdHash($idHash, get_class($entity))); } public function entitiesWithValidIdentifiersProvider() @@ -395,9 +395,15 @@ class UnitOfWorkTest extends OrmTestCase $nonEmptyString->id = uniqid('', true); + $emptyStrings = new EntityWithCompositeStringIdentifier(); + + $emptyStrings->id1 = ''; + $emptyStrings->id2 = ''; + return [ - 'empty string, single field' => [$emptyString], - 'non-empty string, single field' => [$nonEmptyString], + 'empty string, single field' => [$emptyString, ''], + 'non-empty string, single field' => [$nonEmptyString, $nonEmptyString->id], + 'empty strings, two fields' => [$emptyStrings, ' '], ]; } } From 29d9f344e88e9281345c799188919d5764c9217a Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Thu, 7 Jul 2016 19:35:39 +0200 Subject: [PATCH 03/14] Non-empty composite key identifiers should also be supported --- tests/Doctrine/Tests/ORM/UnitOfWorkTest.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/tests/Doctrine/Tests/ORM/UnitOfWorkTest.php b/tests/Doctrine/Tests/ORM/UnitOfWorkTest.php index b0b38b9e2..6b5f63a6f 100644 --- a/tests/Doctrine/Tests/ORM/UnitOfWorkTest.php +++ b/tests/Doctrine/Tests/ORM/UnitOfWorkTest.php @@ -393,17 +393,23 @@ class UnitOfWorkTest extends OrmTestCase $nonEmptyString = new EntityWithStringIdentifier(); - $nonEmptyString->id = uniqid('', true); + $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); + return [ 'empty string, single field' => [$emptyString, ''], 'non-empty string, single field' => [$nonEmptyString, $nonEmptyString->id], 'empty strings, two fields' => [$emptyStrings, ' '], + 'non-empty strings, two fields' => [$nonEmptyStrings, $nonEmptyStrings->id1 . ' ' . $nonEmptyStrings->id2], ]; } } From aa1fda6d5fb940b2ad888e40c13c30a52f69a3a8 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Thu, 7 Jul 2016 19:38:48 +0200 Subject: [PATCH 04/14] Checking for boolean true/false identifiers --- tests/Doctrine/Tests/ORM/UnitOfWorkTest.php | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/tests/Doctrine/Tests/ORM/UnitOfWorkTest.php b/tests/Doctrine/Tests/ORM/UnitOfWorkTest.php index 6b5f63a6f..b26fce19f 100644 --- a/tests/Doctrine/Tests/ORM/UnitOfWorkTest.php +++ b/tests/Doctrine/Tests/ORM/UnitOfWorkTest.php @@ -405,11 +405,21 @@ class UnitOfWorkTest extends OrmTestCase $nonEmptyStrings->id1 = uniqid('id1', true); $nonEmptyStrings->id2 = uniqid('id2', true); + $booleanTrue = new EntityWithBooleanIdentifier(); + + $booleanTrue->id = true; + + $booleanFalse = new EntityWithBooleanIdentifier(); + + $booleanFalse->id = false; + return [ 'empty string, single field' => [$emptyString, ''], 'non-empty string, single field' => [$nonEmptyString, $nonEmptyString->id], 'empty strings, two fields' => [$emptyStrings, ' '], 'non-empty strings, two fields' => [$nonEmptyStrings, $nonEmptyStrings->id1 . ' ' . $nonEmptyStrings->id2], + 'boolean true' => [$booleanTrue, '1'], + 'boolean false' => [$booleanTrue, ''], ]; } } From da7582d32976edd151ea76dd05fcee05067d9e41 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Thu, 7 Jul 2016 19:43:03 +0200 Subject: [PATCH 05/14] Typo fix: s/$booleanTrue/$booleanFalse (C&P mistake) --- tests/Doctrine/Tests/ORM/UnitOfWorkTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Doctrine/Tests/ORM/UnitOfWorkTest.php b/tests/Doctrine/Tests/ORM/UnitOfWorkTest.php index b26fce19f..67121e1a4 100644 --- a/tests/Doctrine/Tests/ORM/UnitOfWorkTest.php +++ b/tests/Doctrine/Tests/ORM/UnitOfWorkTest.php @@ -419,7 +419,7 @@ class UnitOfWorkTest extends OrmTestCase 'empty strings, two fields' => [$emptyStrings, ' '], 'non-empty strings, two fields' => [$nonEmptyStrings, $nonEmptyStrings->id1 . ' ' . $nonEmptyStrings->id2], 'boolean true' => [$booleanTrue, '1'], - 'boolean false' => [$booleanTrue, ''], + 'boolean false' => [$booleanFalse, ''], ]; } } From 9abccba1093bbefbd4b08e676b74265ceaa8dbfa Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Thu, 7 Jul 2016 19:58:43 +0200 Subject: [PATCH 06/14] 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()], + ]; + } } /** From 5b8b548bd4b91118ace8da96c6e01e5ed8aee445 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Thu, 7 Jul 2016 20:08:24 +0200 Subject: [PATCH 07/14] When invalid (null) identifiers are provided, an exception should be thrown --- tests/Doctrine/Tests/ORM/UnitOfWorkTest.php | 32 ++++++--------------- 1 file changed, 8 insertions(+), 24 deletions(-) diff --git a/tests/Doctrine/Tests/ORM/UnitOfWorkTest.php b/tests/Doctrine/Tests/ORM/UnitOfWorkTest.php index e94a187d7..cab05d56d 100644 --- a/tests/Doctrine/Tests/ORM/UnitOfWorkTest.php +++ b/tests/Doctrine/Tests/ORM/UnitOfWorkTest.php @@ -447,35 +447,19 @@ class UnitOfWorkTest extends OrmTestCase public function entitiesWithInvalidIdentifiersProvider() { - $emptyString = new EntityWithStringIdentifier(); + $firstNullString = new EntityWithCompositeStringIdentifier(); - $emptyString->id = ''; + $firstNullString->id2 = uniqid('id2', true); - $nonEmptyString = new EntityWithStringIdentifier(); + $secondNullString = new EntityWithCompositeStringIdentifier(); - $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; + $secondNullString->id1 = uniqid('id1', true); return [ - 'null string, single field' => [new EntityWithStringIdentifier()], - 'null strings, two fieldds' => [new EntityWithCompositeStringIdentifier()], + 'null string, single field' => [new EntityWithStringIdentifier()], + 'null strings, two fields' => [new EntityWithCompositeStringIdentifier()], + 'first null string, two fields' => [$firstNullString], + 'second null string, two fields' => [$secondNullString], ]; } } From 282917426747fcb11d7beaf669af0eb571266402 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Thu, 7 Jul 2016 20:28:21 +0200 Subject: [PATCH 08/14] Simplified test: invalid entities must make it in the `UnitOfWork` manually, via `registerManaged` --- tests/Doctrine/Tests/ORM/UnitOfWorkTest.php | 25 +++++++-------------- 1 file changed, 8 insertions(+), 17 deletions(-) diff --git a/tests/Doctrine/Tests/ORM/UnitOfWorkTest.php b/tests/Doctrine/Tests/ORM/UnitOfWorkTest.php index cab05d56d..4ecbdc3e0 100644 --- a/tests/Doctrine/Tests/ORM/UnitOfWorkTest.php +++ b/tests/Doctrine/Tests/ORM/UnitOfWorkTest.php @@ -375,11 +375,7 @@ class UnitOfWorkTest extends OrmTestCase */ public function testAddToIdentityMapValidIdentifiers($entity, $idHash) { - $this->_unitOfWork->registerManaged( - $entity, - $this->_emMock->getClassMetadata(get_class($entity))->getIdentifierValues($entity), - [] - ); + $this->_unitOfWork->persist($entity); $this->_unitOfWork->addToIdentityMap($entity); // note: cloning to avoid lookup by spl_object_hash() @@ -428,20 +424,15 @@ class UnitOfWorkTest extends OrmTestCase * @dataProvider entitiesWithInvalidIdentifiersProvider * * @param object $entity + * @param array $identifier * * @return void */ - public function testAddToIdentityMapInvalidIdentifiers($entity) + public function testAddToIdentityMapInvalidIdentifiers($entity, array $identifier) { - $this->_unitOfWork->registerManaged( - $entity, - $this->_emMock->getClassMetadata(get_class($entity))->getIdentifierValues($entity), - [] - ); - $this->expectException(ORMInvalidArgumentException::class); - $this->_unitOfWork->addToIdentityMap($entity); + $this->_unitOfWork->registerManaged($entity, $identifier, []); } @@ -456,10 +447,10 @@ class UnitOfWorkTest extends OrmTestCase $secondNullString->id1 = uniqid('id1', true); return [ - 'null string, single field' => [new EntityWithStringIdentifier()], - 'null strings, two fields' => [new EntityWithCompositeStringIdentifier()], - 'first null string, two fields' => [$firstNullString], - 'second null string, two fields' => [$secondNullString], + 'null string, single field' => [new EntityWithStringIdentifier(), ['id' => null]], + 'null strings, two fields' => [new EntityWithCompositeStringIdentifier(), ['id1' => null, 'id2' => null]], + 'first null string, two fields' => [$firstNullString, ['id1' => null, 'id2' => $firstNullString->id2]], + 'second null string, two fields' => [$secondNullString, ['id1' => $secondNullString->id1, 'id2' => null]], ]; } } From 1cb8d790b64f542406a576b878d67abe284e7275 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Thu, 7 Jul 2016 20:29:00 +0200 Subject: [PATCH 09/14] Disallowing `null` as part of the entity identifier --- lib/Doctrine/ORM/UnitOfWork.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/Doctrine/ORM/UnitOfWork.php b/lib/Doctrine/ORM/UnitOfWork.php index c54d97a0b..23bee1401 100644 --- a/lib/Doctrine/ORM/UnitOfWork.php +++ b/lib/Doctrine/ORM/UnitOfWork.php @@ -1398,12 +1398,13 @@ class UnitOfWork implements PropertyChangedListener public function addToIdentityMap($entity) { $classMetadata = $this->em->getClassMetadata(get_class($entity)); - $idHash = implode(' ', $this->entityIdentifiers[spl_object_hash($entity)]); + $identifier = $this->entityIdentifiers[spl_object_hash($entity)]; - if ($idHash === '') { + if (in_array(null, $identifier, true)) { throw ORMInvalidArgumentException::entityWithoutIdentity($classMetadata->name, $entity); } + $idHash = implode(' ', $identifier); $className = $classMetadata->rootEntityName; if (isset($this->identityMap[$className][$idHash])) { From 7544934158eabe248986551b3d25eabacecbcc9c Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Thu, 7 Jul 2016 20:39:52 +0200 Subject: [PATCH 10/14] Removing note that is not valid anymore --- tests/Doctrine/Tests/ORM/UnitOfWorkTest.php | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/Doctrine/Tests/ORM/UnitOfWorkTest.php b/tests/Doctrine/Tests/ORM/UnitOfWorkTest.php index 4ecbdc3e0..6ccaa51e4 100644 --- a/tests/Doctrine/Tests/ORM/UnitOfWorkTest.php +++ b/tests/Doctrine/Tests/ORM/UnitOfWorkTest.php @@ -378,7 +378,6 @@ class UnitOfWorkTest extends OrmTestCase $this->_unitOfWork->persist($entity); $this->_unitOfWork->addToIdentityMap($entity); - // note: cloning to avoid lookup by spl_object_hash() self::assertSame($entity, $this->_unitOfWork->getByIdHash($idHash, get_class($entity))); } From 0d82128b2e59c9142f1297bae13ed616405996ee Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Thu, 7 Jul 2016 20:57:02 +0200 Subject: [PATCH 11/14] Registering a managed entity with an empty identifier is to be disallowed --- tests/Doctrine/Tests/ORM/UnitOfWorkTest.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/tests/Doctrine/Tests/ORM/UnitOfWorkTest.php b/tests/Doctrine/Tests/ORM/UnitOfWorkTest.php index 6ccaa51e4..6a2c882e8 100644 --- a/tests/Doctrine/Tests/ORM/UnitOfWorkTest.php +++ b/tests/Doctrine/Tests/ORM/UnitOfWorkTest.php @@ -419,6 +419,13 @@ class UnitOfWorkTest extends OrmTestCase ]; } + public function testRegisteringAManagedInstanceRequiresANonEmptyIdentifier() + { + $this->expectException(ORMInvalidArgumentException::class); + + $this->_unitOfWork->registerManaged(new EntityWithBooleanIdentifier(), [], []); + } + /** * @dataProvider entitiesWithInvalidIdentifiersProvider * From dbcdc1d42a53dd3fdec33c976cd5e73d1d76de8f Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Thu, 7 Jul 2016 20:57:49 +0200 Subject: [PATCH 12/14] Empty identifiers must be disallowed --- lib/Doctrine/ORM/UnitOfWork.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Doctrine/ORM/UnitOfWork.php b/lib/Doctrine/ORM/UnitOfWork.php index 23bee1401..7ac24cc60 100644 --- a/lib/Doctrine/ORM/UnitOfWork.php +++ b/lib/Doctrine/ORM/UnitOfWork.php @@ -1400,7 +1400,7 @@ class UnitOfWork implements PropertyChangedListener $classMetadata = $this->em->getClassMetadata(get_class($entity)); $identifier = $this->entityIdentifiers[spl_object_hash($entity)]; - if (in_array(null, $identifier, true)) { + if (empty($identifier) || in_array(null, $identifier, true)) { throw ORMInvalidArgumentException::entityWithoutIdentity($classMetadata->name, $entity); } From 5d12593e70752af2ca23baafed83dec3b0d17690 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Thu, 7 Jul 2016 21:29:10 +0200 Subject: [PATCH 13/14] Rewrote `ManyToOne` SLC tests to not rely on multi-level auto-generated identifiers Background: Test relied on an `A->B->C` association: * `A#id` being `B` * `B#id` being `C` * `C#id` being an auto-generated identifier (post-insert) This cannot work, because it breaks the UnitOfWork's identity map. Specifically, no entries for `A` and `B` can exist in the identity map until `C` entries are persisted (post-insert). That means that the identifier generator for `A` and `B` should not be an "assigned" generator, but should instead be a post-insert generator waiting for other entities to be persisted. We cannot fix this in ORM 2.x, but we'll need to invent something for 3.x in order to fix that (directed graph, or caching the order of operations in the metadata graph). --- tests/Doctrine/Tests/Models/Cache/Action.php | 9 ++------- .../Doctrine/Tests/Models/Cache/ComplexAction.php | 4 ++-- tests/Doctrine/Tests/Models/Cache/Token.php | 6 +++--- .../Functional/SecondLevelCacheManyToOneTest.php | 14 +++++++------- 4 files changed, 14 insertions(+), 19 deletions(-) diff --git a/tests/Doctrine/Tests/Models/Cache/Action.php b/tests/Doctrine/Tests/Models/Cache/Action.php index 25609abed..d23ab494b 100644 --- a/tests/Doctrine/Tests/Models/Cache/Action.php +++ b/tests/Doctrine/Tests/Models/Cache/Action.php @@ -14,13 +14,8 @@ class Action /** * @Id - * @GeneratedValue - * @Column(type="integer") - */ - public $id; - - /** - * @Column + * @Column(type="string") + * @GeneratedValue(strategy="NONE") */ public $name; diff --git a/tests/Doctrine/Tests/Models/Cache/ComplexAction.php b/tests/Doctrine/Tests/Models/Cache/ComplexAction.php index 46d0414d3..5f5faf6dd 100644 --- a/tests/Doctrine/Tests/Models/Cache/ComplexAction.php +++ b/tests/Doctrine/Tests/Models/Cache/ComplexAction.php @@ -20,14 +20,14 @@ class ComplexAction /** * @Id * @OneToOne(targetEntity="Action", cascade={"persist", "remove"}) - * @JoinColumn(name="action1_id", referencedColumnName="id") + * @JoinColumn(name="action1_name", referencedColumnName="name") */ public $action1; /** * @Id * @OneToOne(targetEntity="Action", cascade={"persist", "remove"}) - * @JoinColumn(name="action2_id", referencedColumnName="id") + * @JoinColumn(name="action2_name", referencedColumnName="name") */ public $action2; diff --git a/tests/Doctrine/Tests/Models/Cache/Token.php b/tests/Doctrine/Tests/Models/Cache/Token.php index f6c712e36..ba3fdb182 100644 --- a/tests/Doctrine/Tests/Models/Cache/Token.php +++ b/tests/Doctrine/Tests/Models/Cache/Token.php @@ -36,7 +36,7 @@ class Token /** * @ManyToOne(targetEntity="Action", cascade={"persist", "remove"}, inversedBy="tokens") - * @JoinColumn(name="action_id", referencedColumnName="id") + * @JoinColumn(name="action_name", referencedColumnName="name") * @var array */ public $action; @@ -44,8 +44,8 @@ class Token /** * @ManyToOne(targetEntity="ComplexAction", cascade={"persist", "remove"}, inversedBy="tokens") * @JoinColumns({ - * @JoinColumn(name="complex_action1_id", referencedColumnName="action1_id"), - * @JoinColumn(name="complex_action2_id", referencedColumnName="action2_id") + * @JoinColumn(name="complex_action1_name", referencedColumnName="action1_name"), + * @JoinColumn(name="complex_action2_name", referencedColumnName="action2_name") * }) * @var ComplexAction */ diff --git a/tests/Doctrine/Tests/ORM/Functional/SecondLevelCacheManyToOneTest.php b/tests/Doctrine/Tests/ORM/Functional/SecondLevelCacheManyToOneTest.php index 00fa40973..57215f8e0 100644 --- a/tests/Doctrine/Tests/ORM/Functional/SecondLevelCacheManyToOneTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/SecondLevelCacheManyToOneTest.php @@ -193,7 +193,7 @@ class SecondLevelCacheManyToOneTest extends SecondLevelCacheAbstractTest $this->_em->clear(); $this->assertTrue($this->cache->containsEntity(Token::CLASSNAME, $token->token)); - $this->assertFalse($this->cache->containsEntity(Token::CLASSNAME, $action->id)); + $this->assertFalse($this->cache->containsEntity(Token::CLASSNAME, $action->name)); $queryCount = $this->getCurrentQueryCount(); $entity = $this->_em->find(Token::CLASSNAME, $token->token); @@ -204,7 +204,7 @@ class SecondLevelCacheManyToOneTest extends SecondLevelCacheAbstractTest $this->assertInstanceOf(Action::CLASSNAME, $entity->getAction()); $this->assertEquals('exec', $entity->getAction()->name); - $this->assertEquals($queryCount + 1, $this->getCurrentQueryCount()); + $this->assertEquals($queryCount, $this->getCurrentQueryCount()); } public function testPutAndLoadNonCacheableCompositeManyToOne() @@ -231,9 +231,9 @@ class SecondLevelCacheManyToOneTest extends SecondLevelCacheAbstractTest $this->_em->clear(); $this->assertTrue($this->cache->containsEntity(Token::CLASSNAME, $token->token)); - $this->assertFalse($this->cache->containsEntity(Action::CLASSNAME, $action1->id)); - $this->assertFalse($this->cache->containsEntity(Action::CLASSNAME, $action2->id)); - $this->assertFalse($this->cache->containsEntity(Action::CLASSNAME, $action3->id)); + $this->assertFalse($this->cache->containsEntity(Action::CLASSNAME, $action1->name)); + $this->assertFalse($this->cache->containsEntity(Action::CLASSNAME, $action2->name)); + $this->assertFalse($this->cache->containsEntity(Action::CLASSNAME, $action3->name)); $queryCount = $this->getCurrentQueryCount(); /** @@ -255,8 +255,8 @@ class SecondLevelCacheManyToOneTest extends SecondLevelCacheAbstractTest $this->assertEquals($queryCount + 1, $this->getCurrentQueryCount()); $this->assertEquals('login', $entity->getComplexAction()->getAction1()->name); - $this->assertEquals($queryCount + 2, $this->getCurrentQueryCount()); + $this->assertEquals($queryCount + 1, $this->getCurrentQueryCount()); $this->assertEquals('rememberme', $entity->getComplexAction()->getAction2()->name); - $this->assertEquals($queryCount + 3, $this->getCurrentQueryCount()); + $this->assertEquals($queryCount + 1, $this->getCurrentQueryCount()); } } \ No newline at end of file From d330da898fcce3696f760a3086d38c9bae56110b Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Thu, 7 Jul 2016 22:24:37 +0200 Subject: [PATCH 14/14] Correcting order of deletes: `cache_token` relies on `cache_complex_action` --- tests/Doctrine/Tests/OrmFunctionalTestCase.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Doctrine/Tests/OrmFunctionalTestCase.php b/tests/Doctrine/Tests/OrmFunctionalTestCase.php index d18b94965..6e17a92ad 100644 --- a/tests/Doctrine/Tests/OrmFunctionalTestCase.php +++ b/tests/Doctrine/Tests/OrmFunctionalTestCase.php @@ -460,8 +460,8 @@ abstract class OrmFunctionalTestCase extends OrmTestCase $conn->executeUpdate('DELETE FROM cache_state'); $conn->executeUpdate('DELETE FROM cache_country'); $conn->executeUpdate('DELETE FROM cache_login'); - $conn->executeUpdate('DELETE FROM cache_complex_action'); $conn->executeUpdate('DELETE FROM cache_token'); + $conn->executeUpdate('DELETE FROM cache_complex_action'); $conn->executeUpdate('DELETE FROM cache_action'); $conn->executeUpdate('DELETE FROM cache_client'); }