From ed6fa0deb47873336ecb62fc663850769079e667 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20Gallego?= Date: Wed, 11 Feb 2015 09:59:41 +0100 Subject: [PATCH 1/9] Add failing test --- tests/Doctrine/Tests/Models/Cache/Client.php | 49 ++++++++++++++ tests/Doctrine/Tests/Models/Cache/Token.php | 66 +++++++++++++++++++ .../SecondLevelCacheOneToOneTest.php | 30 +++++++++ .../Doctrine/Tests/OrmFunctionalTestCase.php | 4 ++ 4 files changed, 149 insertions(+) create mode 100644 tests/Doctrine/Tests/Models/Cache/Client.php create mode 100644 tests/Doctrine/Tests/Models/Cache/Token.php diff --git a/tests/Doctrine/Tests/Models/Cache/Client.php b/tests/Doctrine/Tests/Models/Cache/Client.php new file mode 100644 index 000000000..ac73954db --- /dev/null +++ b/tests/Doctrine/Tests/Models/Cache/Client.php @@ -0,0 +1,49 @@ +name = $name; + } + + public function getId() + { + return $this->id; + } + + public function setId($id) + { + $this->id = $id; + } + + public function getName() + { + return $this->name; + } + + public function setName($nae) + { + $this->name = $nae; + } +} diff --git a/tests/Doctrine/Tests/Models/Cache/Token.php b/tests/Doctrine/Tests/Models/Cache/Token.php new file mode 100644 index 000000000..c71f1bf79 --- /dev/null +++ b/tests/Doctrine/Tests/Models/Cache/Token.php @@ -0,0 +1,66 @@ +token = $token; + $this->client = $client; + $this->expiresAt = new \DateTime(date('Y-m-d H:i:s', strtotime("+7 day"))); + } + + public function getToken() + { + return $this->token; + } + + public function getExpiresAt() + { + return $this->expiresAt; + } + + public function getClient() + { + return $this->client; + } + + public function setToken($token) + { + $this->token = $token; + } + + public function setExpiresAt(DateTime $expiresAt) + { + $this->expiresAt = $expiresAt; + } + + public function setClient(Client $client) + { + $this->client = $client; + } +} diff --git a/tests/Doctrine/Tests/ORM/Functional/SecondLevelCacheOneToOneTest.php b/tests/Doctrine/Tests/ORM/Functional/SecondLevelCacheOneToOneTest.php index 1f982261c..e5012e859 100644 --- a/tests/Doctrine/Tests/ORM/Functional/SecondLevelCacheOneToOneTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/SecondLevelCacheOneToOneTest.php @@ -2,6 +2,8 @@ namespace Doctrine\Tests\ORM\Functional; +use Doctrine\Tests\Models\Cache\Client; +use Doctrine\Tests\Models\Cache\Token; use Doctrine\Tests\Models\Cache\Traveler; use Doctrine\Tests\Models\Cache\TravelerProfile; use Doctrine\Tests\Models\Cache\TravelerProfileInfo; @@ -187,4 +189,32 @@ class SecondLevelCacheOneToOneTest extends SecondLevelCacheAbstractTest $this->assertEquals($queryCount, $this->getCurrentQueryCount()); } + public function testPutAndLoadNonCacheableOneToOne() + { + $this->assertNull($this->cache->getEntityCacheRegion(Client::CLASSNAME)); + $this->assertInstanceOf('Doctrine\ORM\Cache\Region', $this->cache->getEntityCacheRegion(Token::CLASSNAME)); + + $client = new Client('FabioBatSilva'); + $token = new Token('token-hash', $client); + + $this->_em->persist($client); + $this->_em->persist($token); + $this->_em->flush(); + $this->_em->clear(); + + $queryCount = $this->getCurrentQueryCount(); + + $this->assertTrue($this->cache->containsEntity(Token::CLASSNAME, $token->getToken())); + $this->assertFalse($this->cache->containsEntity(Client::CLASSNAME, $client->getId())); + + $entity = $this->_em->find(Token::CLASSNAME, $token->getToken()); + + $this->assertInstanceOf(Token::CLASSNAME, $entity); + $this->assertInstanceOf(Client::CLASSNAME, $entity->getClient()); + $this->assertEquals('token-hash', $entity->getToken()); + $this->assertEquals($queryCount, $this->getCurrentQueryCount()); + + $this->assertEquals('FabioBatSilva', $entity->getClient()->getName()); + $this->assertEquals($queryCount + 1, $this->getCurrentQueryCount()); + } } \ No newline at end of file diff --git a/tests/Doctrine/Tests/OrmFunctionalTestCase.php b/tests/Doctrine/Tests/OrmFunctionalTestCase.php index 7aaeae81a..bb05c352f 100644 --- a/tests/Doctrine/Tests/OrmFunctionalTestCase.php +++ b/tests/Doctrine/Tests/OrmFunctionalTestCase.php @@ -180,6 +180,8 @@ abstract class OrmFunctionalTestCase extends OrmTestCase 'Doctrine\Tests\Models\Cache\Beach', 'Doctrine\Tests\Models\Cache\Bar', 'Doctrine\Tests\Models\Cache\Flight', + 'Doctrine\Tests\Models\Cache\Token', + 'Doctrine\Tests\Models\Cache\Client', 'Doctrine\Tests\Models\Cache\AttractionInfo', 'Doctrine\Tests\Models\Cache\AttractionContactInfo', 'Doctrine\Tests\Models\Cache\AttractionLocationInfo' @@ -414,6 +416,8 @@ abstract class OrmFunctionalTestCase extends OrmTestCase $conn->executeUpdate('DELETE FROM cache_city'); $conn->executeUpdate('DELETE FROM cache_state'); $conn->executeUpdate('DELETE FROM cache_country'); + $conn->executeUpdate('DELETE FROM cache_token'); + $conn->executeUpdate('DELETE FROM cache_client'); } if (isset($this->_usedModelSets['ddc3346'])) { From 58e20c70c6bd49ed0801d7c40120c3b33d6b2422 Mon Sep 17 00:00:00 2001 From: Asmir Mustafic Date: Wed, 11 Feb 2015 15:56:19 +0100 Subject: [PATCH 2/9] Store column values of not cache-able associations --- lib/Doctrine/ORM/Cache/DefaultEntityHydrator.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/lib/Doctrine/ORM/Cache/DefaultEntityHydrator.php b/lib/Doctrine/ORM/Cache/DefaultEntityHydrator.php index 1190b38fd..a71d5dd89 100644 --- a/lib/Doctrine/ORM/Cache/DefaultEntityHydrator.php +++ b/lib/Doctrine/ORM/Cache/DefaultEntityHydrator.php @@ -73,8 +73,15 @@ class DefaultEntityHydrator implements EntityHydrator } if ( ! isset($assoc['cache']) || ! ($assoc['type'] & ClassMetadata::TO_ONE)) { + $associatedEntity = $data[$name]; unset($data[$name]); + if ($this->uow->isInIdentityMap($associatedEntity)) { + $targetEntityMetadata = $this->em->getClassMetadata($assoc['targetEntity']); + foreach ($this->uow->getEntityIdentifier($associatedEntity) as $fieldName => $fieldValue) { + $data[$assoc['targetToSourceKeyColumns'][$targetEntityMetadata->getColumnName($fieldName)]] = $fieldValue; + } + } continue; } From a2461d6d5f2fd19a4e8dde6adee0822331764571 Mon Sep 17 00:00:00 2001 From: Asmir Mustafic Date: Wed, 11 Feb 2015 17:04:24 +0100 Subject: [PATCH 3/9] Use identifier flattener to retrevie entity identifiers --- .../ORM/Cache/DefaultEntityHydrator.php | 20 +++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/lib/Doctrine/ORM/Cache/DefaultEntityHydrator.php b/lib/Doctrine/ORM/Cache/DefaultEntityHydrator.php index a71d5dd89..887d67012 100644 --- a/lib/Doctrine/ORM/Cache/DefaultEntityHydrator.php +++ b/lib/Doctrine/ORM/Cache/DefaultEntityHydrator.php @@ -25,6 +25,7 @@ use Doctrine\Common\Util\ClassUtils; use Doctrine\ORM\Query; use Doctrine\ORM\Mapping\ClassMetadata; use Doctrine\ORM\EntityManagerInterface; +use Doctrine\ORM\Utility\IdentifierFlattener; /** * Default hydrator cache for entities @@ -44,6 +45,13 @@ class DefaultEntityHydrator implements EntityHydrator */ private $uow; + /** + * The IdentifierFlattener used for manipulating identifiers + * + * @var \Doctrine\ORM\Utility\IdentifierFlattener + */ + private $identifierFlattener; + /** * @var array */ @@ -56,6 +64,7 @@ class DefaultEntityHydrator implements EntityHydrator { $this->em = $em; $this->uow = $em->getUnitOfWork(); + $this->identifierFlattener = new IdentifierFlattener($em->getUnitOfWork(), $em->getMetadataFactory()); } /** @@ -73,14 +82,13 @@ class DefaultEntityHydrator implements EntityHydrator } if ( ! isset($assoc['cache']) || ! ($assoc['type'] & ClassMetadata::TO_ONE)) { - $associatedEntity = $data[$name]; + $targetClassMetadata = $this->em->getClassMetadata($assoc['targetEntity']); + + $associationIds = $this->identifierFlattener->flattenIdentifier($targetClassMetadata, $targetClassMetadata->getIdentifierValues($data[$name])); unset($data[$name]); - if ($this->uow->isInIdentityMap($associatedEntity)) { - $targetEntityMetadata = $this->em->getClassMetadata($assoc['targetEntity']); - foreach ($this->uow->getEntityIdentifier($associatedEntity) as $fieldName => $fieldValue) { - $data[$assoc['targetToSourceKeyColumns'][$targetEntityMetadata->getColumnName($fieldName)]] = $fieldValue; - } + foreach ($associationIds as $fieldName => $fieldValue) { + $data[$assoc['targetToSourceKeyColumns'][$targetClassMetadata->getColumnName($fieldName)]] = $fieldValue; } continue; } From 60164931b8849d5e1cf85435434d37a215fdbd34 Mon Sep 17 00:00:00 2001 From: Asmir Mustafic Date: Thu, 12 Feb 2015 00:27:25 +0100 Subject: [PATCH 4/9] Handled one-to-many non cache-able relations --- .../ORM/Cache/DefaultEntityHydrator.php | 9 ++- tests/Doctrine/Tests/Models/Cache/Login.php | 63 +++++++++++++++++++ tests/Doctrine/Tests/Models/Cache/Token.php | 25 ++++++++ .../SecondLevelCacheOneToManyTest.php | 32 ++++++++++ .../Doctrine/Tests/OrmFunctionalTestCase.php | 2 + 5 files changed, 129 insertions(+), 2 deletions(-) create mode 100644 tests/Doctrine/Tests/Models/Cache/Login.php diff --git a/lib/Doctrine/ORM/Cache/DefaultEntityHydrator.php b/lib/Doctrine/ORM/Cache/DefaultEntityHydrator.php index 887d67012..6b850dec8 100644 --- a/lib/Doctrine/ORM/Cache/DefaultEntityHydrator.php +++ b/lib/Doctrine/ORM/Cache/DefaultEntityHydrator.php @@ -81,15 +81,20 @@ class DefaultEntityHydrator implements EntityHydrator continue; } - if ( ! isset($assoc['cache']) || ! ($assoc['type'] & ClassMetadata::TO_ONE)) { - $targetClassMetadata = $this->em->getClassMetadata($assoc['targetEntity']); + if (! ($assoc['type'] & ClassMetadata::TO_ONE)) { + unset($data[$name]); + continue; + } + if ( ! isset($assoc['cache'])) { + $targetClassMetadata = $this->em->getClassMetadata($assoc['targetEntity']); $associationIds = $this->identifierFlattener->flattenIdentifier($targetClassMetadata, $targetClassMetadata->getIdentifierValues($data[$name])); unset($data[$name]); foreach ($associationIds as $fieldName => $fieldValue) { $data[$assoc['targetToSourceKeyColumns'][$targetClassMetadata->getColumnName($fieldName)]] = $fieldValue; } + continue; } diff --git a/tests/Doctrine/Tests/Models/Cache/Login.php b/tests/Doctrine/Tests/Models/Cache/Login.php new file mode 100644 index 000000000..e2776c8da --- /dev/null +++ b/tests/Doctrine/Tests/Models/Cache/Login.php @@ -0,0 +1,63 @@ +name = $name; + } + + /** + * @param Token $token + */ + public function setToken(Token $token) + { + $this->token = $token; + } + + public function getId() + { + return $this->id; + } + + public function setId($id) + { + $this->id = $id; + } + + public function getName() + { + return $this->name; + } + + public function setName($nae) + { + $this->name = $nae; + } +} diff --git a/tests/Doctrine/Tests/Models/Cache/Token.php b/tests/Doctrine/Tests/Models/Cache/Token.php index c71f1bf79..7d070b091 100644 --- a/tests/Doctrine/Tests/Models/Cache/Token.php +++ b/tests/Doctrine/Tests/Models/Cache/Token.php @@ -1,6 +1,7 @@ token = $token; + $this->logins = new ArrayCollection(); $this->client = $client; $this->expiresAt = new \DateTime(date('Y-m-d H:i:s', strtotime("+7 day"))); } + /** + * @return array + */ + public function getLogins() + { + return $this->logins; + } + + /** + * @param Login $login + */ + public function addLogin(Login $login) + { + $this->logins[] = $login; + $login->setToken($this); + } + public function getToken() { return $this->token; diff --git a/tests/Doctrine/Tests/ORM/Functional/SecondLevelCacheOneToManyTest.php b/tests/Doctrine/Tests/ORM/Functional/SecondLevelCacheOneToManyTest.php index 4b978b1d6..9ed1ea458 100644 --- a/tests/Doctrine/Tests/ORM/Functional/SecondLevelCacheOneToManyTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/SecondLevelCacheOneToManyTest.php @@ -3,7 +3,9 @@ namespace Doctrine\Tests\ORM\Functional; use Doctrine\Tests\Models\Cache\City; +use Doctrine\Tests\Models\Cache\Login; use Doctrine\Tests\Models\Cache\State; +use Doctrine\Tests\Models\Cache\Token; use Doctrine\Tests\Models\Cache\Travel; use Doctrine\Tests\Models\Cache\Traveler; @@ -381,4 +383,34 @@ class SecondLevelCacheOneToManyTest extends SecondLevelCacheAbstractTest $this->assertEquals(4, $result->getTravels()->count()); } + + public function testPutAndLoadNonCacheableOneToMany() + { + $this->assertNull($this->cache->getEntityCacheRegion(Login::CLASSNAME)); + $this->assertInstanceOf('Doctrine\ORM\Cache\Region', $this->cache->getEntityCacheRegion(Token::CLASSNAME)); + + $l1 = new Login('session1'); + $l2 = new Login('session2'); + $token = new Token('token-hash'); + + $this->_em->persist($token); + $this->_em->flush(); + $token->addLogin($l1); + $token->addLogin($l2); + $this->_em->flush(); + $this->_em->clear(); + + $queryCount = $this->getCurrentQueryCount(); + + $this->assertTrue($this->cache->containsEntity(Token::CLASSNAME, $token->getToken())); + + $entity = $this->_em->find(Token::CLASSNAME, $token->getToken()); + + $this->assertInstanceOf(Token::CLASSNAME, $entity); + $this->assertEquals('token-hash', $entity->getToken()); + $this->assertEquals($queryCount, $this->getCurrentQueryCount()); + + $this->assertCount(2, $entity->getLogins()); + $this->assertEquals($queryCount + 1 , $this->getCurrentQueryCount()); + } } diff --git a/tests/Doctrine/Tests/OrmFunctionalTestCase.php b/tests/Doctrine/Tests/OrmFunctionalTestCase.php index bb05c352f..e1e7e9bfc 100644 --- a/tests/Doctrine/Tests/OrmFunctionalTestCase.php +++ b/tests/Doctrine/Tests/OrmFunctionalTestCase.php @@ -181,6 +181,7 @@ abstract class OrmFunctionalTestCase extends OrmTestCase 'Doctrine\Tests\Models\Cache\Bar', 'Doctrine\Tests\Models\Cache\Flight', 'Doctrine\Tests\Models\Cache\Token', + 'Doctrine\Tests\Models\Cache\Login', 'Doctrine\Tests\Models\Cache\Client', 'Doctrine\Tests\Models\Cache\AttractionInfo', 'Doctrine\Tests\Models\Cache\AttractionContactInfo', @@ -417,6 +418,7 @@ abstract class OrmFunctionalTestCase extends OrmTestCase $conn->executeUpdate('DELETE FROM cache_state'); $conn->executeUpdate('DELETE FROM cache_country'); $conn->executeUpdate('DELETE FROM cache_token'); + $conn->executeUpdate('DELETE FROM cache_login'); $conn->executeUpdate('DELETE FROM cache_client'); } From b9577bf2f374ddeecb6cb7355badd82b5417e0ac Mon Sep 17 00:00:00 2001 From: Asmir Mustafic Date: Thu, 12 Feb 2015 18:53:21 +0100 Subject: [PATCH 5/9] Added tests for many-to-one non cache-able relations --- tests/Doctrine/Tests/Models/Cache/Action.php | 68 +++++++++++++++++++ tests/Doctrine/Tests/Models/Cache/Token.php | 17 +++++ .../SecondLevelCacheManyToOneTest.php | 32 +++++++++ .../Doctrine/Tests/OrmFunctionalTestCase.php | 2 + 4 files changed, 119 insertions(+) create mode 100644 tests/Doctrine/Tests/Models/Cache/Action.php diff --git a/tests/Doctrine/Tests/Models/Cache/Action.php b/tests/Doctrine/Tests/Models/Cache/Action.php new file mode 100644 index 000000000..0002f9b5e --- /dev/null +++ b/tests/Doctrine/Tests/Models/Cache/Action.php @@ -0,0 +1,68 @@ +name = $name; + $this->tokens = new ArrayCollection(); + } + + public function addToken(Token $token) + { + $this->tokens[] = $token; + $token->setAction($this); + } + + public function getTokens() + { + return $this->tokens; + } + + public function getId() + { + return $this->id; + } + + public function setId($id) + { + $this->id = $id; + } + + public function getName() + { + return $this->name; + } + + public function setName($nae) + { + $this->name = $nae; + } +} diff --git a/tests/Doctrine/Tests/Models/Cache/Token.php b/tests/Doctrine/Tests/Models/Cache/Token.php index 7d070b091..39d04e3cc 100644 --- a/tests/Doctrine/Tests/Models/Cache/Token.php +++ b/tests/Doctrine/Tests/Models/Cache/Token.php @@ -34,6 +34,13 @@ class Token */ protected $logins; + /** + * @ManyToOne(targetEntity="Action", cascade={"persist", "remove"}, inversedBy="tokens") + * @JoinColumn(name="action_id", referencedColumnName="id") + * @var array + */ + protected $action; + public function __construct($token, Client $client = null) { $this->token = $token; @@ -59,6 +66,16 @@ class Token $login->setToken($this); } + public function getAction() + { + return $this->action; + } + + public function setAction(Action $action) + { + $this->action = $action; + } + public function getToken() { return $this->token; diff --git a/tests/Doctrine/Tests/ORM/Functional/SecondLevelCacheManyToOneTest.php b/tests/Doctrine/Tests/ORM/Functional/SecondLevelCacheManyToOneTest.php index 9135b508a..4eef64e56 100644 --- a/tests/Doctrine/Tests/ORM/Functional/SecondLevelCacheManyToOneTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/SecondLevelCacheManyToOneTest.php @@ -5,6 +5,8 @@ namespace Doctrine\Tests\ORM\Functional; use Doctrine\Tests\Models\Cache\Country; use Doctrine\Tests\Models\Cache\State; use Doctrine\ORM\Mapping\ClassMetadata; +use Doctrine\Tests\Models\Cache\Token; +use Doctrine\Tests\Models\Cache\Action; /** * @group DDC-2183 @@ -140,4 +142,34 @@ class SecondLevelCacheManyToOneTest extends SecondLevelCacheAbstractTest $this->assertEquals($queryCount + 2, $this->getCurrentQueryCount()); } + + public function testPutAndLoadNonCacheableManyToOne() + { + $this->assertNull($this->cache->getEntityCacheRegion(Action::CLASSNAME)); + $this->assertInstanceOf('Doctrine\ORM\Cache\Region', $this->cache->getEntityCacheRegion(Token::CLASSNAME)); + + $token = new Token('token-hash'); + $action = new Action('exec'); + $action->addToken($token); + + $this->_em->persist($token); + + $this->_em->flush(); + $this->_em->clear(); + + $this->assertTrue($this->cache->containsEntity(Token::CLASSNAME, $token->getToken())); + $this->assertFalse($this->cache->containsEntity(Token::CLASSNAME, $action->getId())); + + $queryCount = $this->getCurrentQueryCount(); + $entity = $this->_em->find(Token::CLASSNAME, $token->getToken()); + + $this->assertInstanceOf(Token::CLASSNAME, $entity); + $this->assertEquals('token-hash', $entity->getToken()); + + $this->assertInstanceOf(Action::CLASSNAME, $entity->getAction()); + $this->assertEquals('exec', $entity->getAction()->getName()); + + $this->assertEquals($queryCount + 1, $this->getCurrentQueryCount()); + + } } \ No newline at end of file diff --git a/tests/Doctrine/Tests/OrmFunctionalTestCase.php b/tests/Doctrine/Tests/OrmFunctionalTestCase.php index e1e7e9bfc..b65ec2692 100644 --- a/tests/Doctrine/Tests/OrmFunctionalTestCase.php +++ b/tests/Doctrine/Tests/OrmFunctionalTestCase.php @@ -183,6 +183,7 @@ abstract class OrmFunctionalTestCase extends OrmTestCase 'Doctrine\Tests\Models\Cache\Token', 'Doctrine\Tests\Models\Cache\Login', 'Doctrine\Tests\Models\Cache\Client', + 'Doctrine\Tests\Models\Cache\Action', 'Doctrine\Tests\Models\Cache\AttractionInfo', 'Doctrine\Tests\Models\Cache\AttractionContactInfo', 'Doctrine\Tests\Models\Cache\AttractionLocationInfo' @@ -420,6 +421,7 @@ abstract class OrmFunctionalTestCase extends OrmTestCase $conn->executeUpdate('DELETE FROM cache_token'); $conn->executeUpdate('DELETE FROM cache_login'); $conn->executeUpdate('DELETE FROM cache_client'); + $conn->executeUpdate('DELETE FROM cache_action'); } if (isset($this->_usedModelSets['ddc3346'])) { From 24dd0c6a551fea1a237f0b34befadc442a41c0a4 Mon Sep 17 00:00:00 2001 From: Asmir Mustafic Date: Thu, 12 Feb 2015 18:56:58 +0100 Subject: [PATCH 6/9] Fixed delete order on tearDown method --- tests/Doctrine/Tests/OrmFunctionalTestCase.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/Doctrine/Tests/OrmFunctionalTestCase.php b/tests/Doctrine/Tests/OrmFunctionalTestCase.php index b65ec2692..183f72231 100644 --- a/tests/Doctrine/Tests/OrmFunctionalTestCase.php +++ b/tests/Doctrine/Tests/OrmFunctionalTestCase.php @@ -418,10 +418,10 @@ abstract class OrmFunctionalTestCase extends OrmTestCase $conn->executeUpdate('DELETE FROM cache_city'); $conn->executeUpdate('DELETE FROM cache_state'); $conn->executeUpdate('DELETE FROM cache_country'); - $conn->executeUpdate('DELETE FROM cache_token'); $conn->executeUpdate('DELETE FROM cache_login'); - $conn->executeUpdate('DELETE FROM cache_client'); + $conn->executeUpdate('DELETE FROM cache_token'); $conn->executeUpdate('DELETE FROM cache_action'); + $conn->executeUpdate('DELETE FROM cache_client'); } if (isset($this->_usedModelSets['ddc3346'])) { From d72ad9cc50208153160edfa9b3bd7a23fbec0cee Mon Sep 17 00:00:00 2001 From: Asmir Mustafic Date: Fri, 20 Feb 2015 10:00:36 +0100 Subject: [PATCH 7/9] Handling composite keys on non cache-able entities --- lib/Doctrine/ORM/Cache/DefaultEntityHydrator.php | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/lib/Doctrine/ORM/Cache/DefaultEntityHydrator.php b/lib/Doctrine/ORM/Cache/DefaultEntityHydrator.php index 6b850dec8..200af9c0d 100644 --- a/lib/Doctrine/ORM/Cache/DefaultEntityHydrator.php +++ b/lib/Doctrine/ORM/Cache/DefaultEntityHydrator.php @@ -92,7 +92,19 @@ class DefaultEntityHydrator implements EntityHydrator unset($data[$name]); foreach ($associationIds as $fieldName => $fieldValue) { - $data[$assoc['targetToSourceKeyColumns'][$targetClassMetadata->getColumnName($fieldName)]] = $fieldValue; + + if (isset($targetClassMetadata->associationMappings[$fieldName])){ + $targetAssoc = $targetClassMetadata->associationMappings[$fieldName]; + + foreach($assoc['targetToSourceKeyColumns'] as $referencedColumn => $localColumn) { + + if (isset($targetAssoc['sourceToTargetKeyColumns'][$referencedColumn])) { + $data[$localColumn] = $fieldValue; + } + } + }else{ + $data[$assoc['targetToSourceKeyColumns'][$targetClassMetadata->columnNames[$fieldName]]] = $fieldValue; + } } continue; From 4d43f5ca522003650038930836b7899a5268db07 Mon Sep 17 00:00:00 2001 From: Asmir Mustafic Date: Fri, 20 Feb 2015 10:12:40 +0100 Subject: [PATCH 8/9] Tested composite keys on non cache-able entities --- .../Tests/Models/Cache/ComplexAction.php | 77 +++++++++++++++++++ tests/Doctrine/Tests/Models/Cache/Token.php | 35 ++++++--- .../SecondLevelCacheManyToOneTest.php | 53 +++++++++++++ .../SecondLevelCacheOneToManyTest.php | 11 ++- .../Doctrine/Tests/OrmFunctionalTestCase.php | 2 + 5 files changed, 161 insertions(+), 17 deletions(-) create mode 100644 tests/Doctrine/Tests/Models/Cache/ComplexAction.php diff --git a/tests/Doctrine/Tests/Models/Cache/ComplexAction.php b/tests/Doctrine/Tests/Models/Cache/ComplexAction.php new file mode 100644 index 000000000..a42eba747 --- /dev/null +++ b/tests/Doctrine/Tests/Models/Cache/ComplexAction.php @@ -0,0 +1,77 @@ +name = $name; + $this->action1 = $action1; + $this->action2 = $action2; + $this->tokens = new ArrayCollection(); + } + + public function getAction1() + { + return $this->action1; + } + + public function getAction2() + { + return $this->action2; + } + + public function addToken(Token $token) + { + $this->tokens[] = $token; + $token->setComplexAction($this); + } + + public function getTokens() + { + return $this->tokens; + } + + public function getId() + { + return $this->id; + } + + public function getName() + { + return $this->name; + } +} diff --git a/tests/Doctrine/Tests/Models/Cache/Token.php b/tests/Doctrine/Tests/Models/Cache/Token.php index 39d04e3cc..09787e58f 100644 --- a/tests/Doctrine/Tests/Models/Cache/Token.php +++ b/tests/Doctrine/Tests/Models/Cache/Token.php @@ -41,14 +41,37 @@ class Token */ protected $action; + /** + * @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") + * }) + * @var ComplexAction + */ + protected $complexAction; + public function __construct($token, Client $client = null) { - $this->token = $token; $this->logins = new ArrayCollection(); + $this->token = $token; $this->client = $client; $this->expiresAt = new \DateTime(date('Y-m-d H:i:s', strtotime("+7 day"))); } + /** + * @return ComplexAction + */ + public function getComplexAction() + { + return $this->complexAction; + } + + public function setComplexAction(ComplexAction $complexAction) + { + $this->complexAction = $complexAction; + } + /** * @return array */ @@ -95,14 +118,4 @@ class Token { $this->token = $token; } - - public function setExpiresAt(DateTime $expiresAt) - { - $this->expiresAt = $expiresAt; - } - - public function setClient(Client $client) - { - $this->client = $client; - } } diff --git a/tests/Doctrine/Tests/ORM/Functional/SecondLevelCacheManyToOneTest.php b/tests/Doctrine/Tests/ORM/Functional/SecondLevelCacheManyToOneTest.php index 4eef64e56..d1e122970 100644 --- a/tests/Doctrine/Tests/ORM/Functional/SecondLevelCacheManyToOneTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/SecondLevelCacheManyToOneTest.php @@ -2,6 +2,7 @@ namespace Doctrine\Tests\ORM\Functional; +use Doctrine\Tests\Models\Cache\ComplexAction; use Doctrine\Tests\Models\Cache\Country; use Doctrine\Tests\Models\Cache\State; use Doctrine\ORM\Mapping\ClassMetadata; @@ -170,6 +171,58 @@ class SecondLevelCacheManyToOneTest extends SecondLevelCacheAbstractTest $this->assertEquals('exec', $entity->getAction()->getName()); $this->assertEquals($queryCount + 1, $this->getCurrentQueryCount()); + } + public function testPutAndLoadNonCacheableCompositeManyToOne() + { + $this->assertNull($this->cache->getEntityCacheRegion(Action::CLASSNAME)); + $this->assertNull($this->cache->getEntityCacheRegion(ComplexAction::CLASSNAME)); + $this->assertInstanceOf('Doctrine\ORM\Cache\Region', $this->cache->getEntityCacheRegion(Token::CLASSNAME)); + + $token = new Token('token-hash'); + + $action1 = new Action('login'); + $action2 = new Action('logout'); + $action3 = new Action('rememberme'); + + $complexAction = new ComplexAction($action1, $action3, 'login,rememberme'); + + $complexAction->addToken($token); + + $token->setAction($action2); + + $this->_em->persist($token); + + $this->_em->flush(); + $this->_em->clear(); + + $this->assertTrue($this->cache->containsEntity(Token::CLASSNAME, $token->getToken())); + $this->assertFalse($this->cache->containsEntity(Action::CLASSNAME, $action1->getId())); + $this->assertFalse($this->cache->containsEntity(Action::CLASSNAME, $action2->getId())); + $this->assertFalse($this->cache->containsEntity(Action::CLASSNAME, $action3->getId())); + + $queryCount = $this->getCurrentQueryCount(); + /** + * @var $entity Token + */ + $entity = $this->_em->find(Token::CLASSNAME, $token->getToken()); + + $this->assertInstanceOf(Token::CLASSNAME, $entity); + $this->assertEquals('token-hash', $entity->getToken()); + + $this->assertEquals($queryCount, $this->getCurrentQueryCount()); + + $this->assertInstanceOf(Action::CLASSNAME, $entity->getAction()); + $this->assertInstanceOf(ComplexAction::CLASSNAME, $entity->getComplexAction()); + $this->assertEquals($queryCount, $this->getCurrentQueryCount()); + + $this->assertInstanceOf(Action::CLASSNAME, $entity->getComplexAction()->getAction1()); + $this->assertInstanceOf(Action::CLASSNAME, $entity->getComplexAction()->getAction2()); + $this->assertEquals($queryCount + 1, $this->getCurrentQueryCount()); + + $this->assertEquals('login', $entity->getComplexAction()->getAction1()->getName()); + $this->assertEquals($queryCount + 2, $this->getCurrentQueryCount()); + $this->assertEquals('rememberme', $entity->getComplexAction()->getAction2()->getName()); + $this->assertEquals($queryCount + 3, $this->getCurrentQueryCount()); } } \ No newline at end of file diff --git a/tests/Doctrine/Tests/ORM/Functional/SecondLevelCacheOneToManyTest.php b/tests/Doctrine/Tests/ORM/Functional/SecondLevelCacheOneToManyTest.php index 9ed1ea458..c028584d6 100644 --- a/tests/Doctrine/Tests/ORM/Functional/SecondLevelCacheOneToManyTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/SecondLevelCacheOneToManyTest.php @@ -392,18 +392,17 @@ class SecondLevelCacheOneToManyTest extends SecondLevelCacheAbstractTest $l1 = new Login('session1'); $l2 = new Login('session2'); $token = new Token('token-hash'); + $token->addLogin($l1); + $token->addLogin($l2); $this->_em->persist($token); $this->_em->flush(); - $token->addLogin($l1); - $token->addLogin($l2); - $this->_em->flush(); $this->_em->clear(); - $queryCount = $this->getCurrentQueryCount(); - $this->assertTrue($this->cache->containsEntity(Token::CLASSNAME, $token->getToken())); + $queryCount = $this->getCurrentQueryCount(); + $entity = $this->_em->find(Token::CLASSNAME, $token->getToken()); $this->assertInstanceOf(Token::CLASSNAME, $entity); @@ -411,6 +410,6 @@ class SecondLevelCacheOneToManyTest extends SecondLevelCacheAbstractTest $this->assertEquals($queryCount, $this->getCurrentQueryCount()); $this->assertCount(2, $entity->getLogins()); - $this->assertEquals($queryCount + 1 , $this->getCurrentQueryCount()); + $this->assertEquals($queryCount + 1, $this->getCurrentQueryCount()); } } diff --git a/tests/Doctrine/Tests/OrmFunctionalTestCase.php b/tests/Doctrine/Tests/OrmFunctionalTestCase.php index 183f72231..b8cf89795 100644 --- a/tests/Doctrine/Tests/OrmFunctionalTestCase.php +++ b/tests/Doctrine/Tests/OrmFunctionalTestCase.php @@ -184,6 +184,7 @@ abstract class OrmFunctionalTestCase extends OrmTestCase 'Doctrine\Tests\Models\Cache\Login', 'Doctrine\Tests\Models\Cache\Client', 'Doctrine\Tests\Models\Cache\Action', + 'Doctrine\Tests\Models\Cache\ComplexAction', 'Doctrine\Tests\Models\Cache\AttractionInfo', 'Doctrine\Tests\Models\Cache\AttractionContactInfo', 'Doctrine\Tests\Models\Cache\AttractionLocationInfo' @@ -419,6 +420,7 @@ 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_action'); $conn->executeUpdate('DELETE FROM cache_client'); From d33ee5e7ff62b6fdf8657fdb5ff8dbcb1aad7888 Mon Sep 17 00:00:00 2001 From: Asmir Mustafic Date: Tue, 24 Feb 2015 08:49:50 +0100 Subject: [PATCH 9/9] Removed unnecessary API from test cases --- tests/Doctrine/Tests/Models/Cache/Action.php | 33 +------ tests/Doctrine/Tests/Models/Cache/Client.php | 24 +---- .../Tests/Models/Cache/ComplexAction.php | 41 ++++----- tests/Doctrine/Tests/Models/Cache/Login.php | 32 ++----- tests/Doctrine/Tests/Models/Cache/Token.php | 88 +++++++------------ .../SecondLevelCacheManyToOneTest.php | 28 +++--- .../SecondLevelCacheOneToManyTest.php | 8 +- .../SecondLevelCacheOneToOneTest.php | 10 +-- 8 files changed, 82 insertions(+), 182 deletions(-) diff --git a/tests/Doctrine/Tests/Models/Cache/Action.php b/tests/Doctrine/Tests/Models/Cache/Action.php index 0002f9b5e..25609abed 100644 --- a/tests/Doctrine/Tests/Models/Cache/Action.php +++ b/tests/Doctrine/Tests/Models/Cache/Action.php @@ -17,17 +17,17 @@ class Action * @GeneratedValue * @Column(type="integer") */ - protected $id; + public $id; /** * @Column */ - private $name; + public $name; /** * @OneToMany(targetEntity="Token", cascade={"persist", "remove"}, mappedBy="action") */ - private $tokens; + public $tokens; public function __construct($name) { @@ -38,31 +38,6 @@ class Action public function addToken(Token $token) { $this->tokens[] = $token; - $token->setAction($this); - } - - public function getTokens() - { - return $this->tokens; - } - - public function getId() - { - return $this->id; - } - - public function setId($id) - { - $this->id = $id; - } - - public function getName() - { - return $this->name; - } - - public function setName($nae) - { - $this->name = $nae; + $token->action = $this; } } diff --git a/tests/Doctrine/Tests/Models/Cache/Client.php b/tests/Doctrine/Tests/Models/Cache/Client.php index ac73954db..70544256b 100644 --- a/tests/Doctrine/Tests/Models/Cache/Client.php +++ b/tests/Doctrine/Tests/Models/Cache/Client.php @@ -15,35 +15,15 @@ class Client * @GeneratedValue * @Column(type="integer") */ - protected $id; + public $id; /** * @Column(unique=true) */ - private $name; + public $name; public function __construct($name) { $this->name = $name; } - - public function getId() - { - return $this->id; - } - - public function setId($id) - { - $this->id = $id; - } - - public function getName() - { - return $this->name; - } - - public function setName($nae) - { - $this->name = $nae; - } } diff --git a/tests/Doctrine/Tests/Models/Cache/ComplexAction.php b/tests/Doctrine/Tests/Models/Cache/ComplexAction.php index a42eba747..46d0414d3 100644 --- a/tests/Doctrine/Tests/Models/Cache/ComplexAction.php +++ b/tests/Doctrine/Tests/Models/Cache/ComplexAction.php @@ -15,26 +15,26 @@ class ComplexAction /** * @Column */ - private $name; + public $name; /** * @Id * @OneToOne(targetEntity="Action", cascade={"persist", "remove"}) * @JoinColumn(name="action1_id", referencedColumnName="id") */ - private $action1; + public $action1; /** * @Id * @OneToOne(targetEntity="Action", cascade={"persist", "remove"}) * @JoinColumn(name="action2_id", referencedColumnName="id") */ - private $action2; + public $action2; /** * @OneToMany(targetEntity="Token", cascade={"persist", "remove"}, mappedBy="complexAction") */ - private $tokens; + public $tokens; public function __construct(Action $action1, Action $action2, $name) { @@ -44,34 +44,25 @@ class ComplexAction $this->tokens = new ArrayCollection(); } + public function addToken(Token $token) + { + $this->tokens[] = $token; + $token->complexAction = $this; + } + + /** + * @return Action + */ public function getAction1() { return $this->action1; } + /** + * @return Action + */ public function getAction2() { return $this->action2; } - - public function addToken(Token $token) - { - $this->tokens[] = $token; - $token->setComplexAction($this); - } - - public function getTokens() - { - return $this->tokens; - } - - public function getId() - { - return $this->id; - } - - public function getName() - { - return $this->name; - } } diff --git a/tests/Doctrine/Tests/Models/Cache/Login.php b/tests/Doctrine/Tests/Models/Cache/Login.php index e2776c8da..8de766d38 100644 --- a/tests/Doctrine/Tests/Models/Cache/Login.php +++ b/tests/Doctrine/Tests/Models/Cache/Login.php @@ -15,18 +15,18 @@ class Login * @GeneratedValue * @Column(type="integer") */ - protected $id; + public $id; /** * @Column */ - private $name; + public $name; /** * @ManyToOne(targetEntity="Token", cascade={"persist", "remove"}, inversedBy="logins") * @JoinColumn(name="token_id", referencedColumnName="token") */ - private $token; + public $token; public function __construct($name) { @@ -34,30 +34,10 @@ class Login } /** - * @param Token $token + * @return Token */ - public function setToken(Token $token) + public function getToken() { - $this->token = $token; - } - - public function getId() - { - return $this->id; - } - - public function setId($id) - { - $this->id = $id; - } - - public function getName() - { - return $this->name; - } - - public function setName($nae) - { - $this->name = $nae; + return $this->token; } } diff --git a/tests/Doctrine/Tests/Models/Cache/Token.php b/tests/Doctrine/Tests/Models/Cache/Token.php index 09787e58f..f6c712e36 100644 --- a/tests/Doctrine/Tests/Models/Cache/Token.php +++ b/tests/Doctrine/Tests/Models/Cache/Token.php @@ -16,30 +16,30 @@ class Token * @Id * @Column(type="string") */ - protected $token; + public $token; /** * @Column(type="date") */ - protected $expiresAt; + public $expiresAt; /** * @OneToOne(targetEntity="Client") */ - protected $client; + public $client; /** * @OneToMany(targetEntity="Login", cascade={"persist", "remove"}, mappedBy="token") * @var array */ - protected $logins; + public $logins; /** * @ManyToOne(targetEntity="Action", cascade={"persist", "remove"}, inversedBy="tokens") * @JoinColumn(name="action_id", referencedColumnName="id") * @var array */ - protected $action; + public $action; /** * @ManyToOne(targetEntity="ComplexAction", cascade={"persist", "remove"}, inversedBy="tokens") @@ -49,7 +49,7 @@ class Token * }) * @var ComplexAction */ - protected $complexAction; + public $complexAction; public function __construct($token, Client $client = null) { @@ -59,6 +59,31 @@ class Token $this->expiresAt = new \DateTime(date('Y-m-d H:i:s', strtotime("+7 day"))); } + /** + * @param Login $login + */ + public function addLogin(Login $login) + { + $this->logins[] = $login; + $login->token = $this; + } + + /** + * @return Client + */ + public function getClient() + { + return $this->client; + } + + /** + * @return Action + */ + public function getAction() + { + return $this->action; + } + /** * @return ComplexAction */ @@ -67,55 +92,4 @@ class Token return $this->complexAction; } - public function setComplexAction(ComplexAction $complexAction) - { - $this->complexAction = $complexAction; - } - - /** - * @return array - */ - public function getLogins() - { - return $this->logins; - } - - /** - * @param Login $login - */ - public function addLogin(Login $login) - { - $this->logins[] = $login; - $login->setToken($this); - } - - public function getAction() - { - return $this->action; - } - - public function setAction(Action $action) - { - $this->action = $action; - } - - public function getToken() - { - return $this->token; - } - - public function getExpiresAt() - { - return $this->expiresAt; - } - - public function getClient() - { - return $this->client; - } - - public function setToken($token) - { - $this->token = $token; - } } diff --git a/tests/Doctrine/Tests/ORM/Functional/SecondLevelCacheManyToOneTest.php b/tests/Doctrine/Tests/ORM/Functional/SecondLevelCacheManyToOneTest.php index d1e122970..8c0225e7f 100644 --- a/tests/Doctrine/Tests/ORM/Functional/SecondLevelCacheManyToOneTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/SecondLevelCacheManyToOneTest.php @@ -158,17 +158,17 @@ class SecondLevelCacheManyToOneTest extends SecondLevelCacheAbstractTest $this->_em->flush(); $this->_em->clear(); - $this->assertTrue($this->cache->containsEntity(Token::CLASSNAME, $token->getToken())); - $this->assertFalse($this->cache->containsEntity(Token::CLASSNAME, $action->getId())); + $this->assertTrue($this->cache->containsEntity(Token::CLASSNAME, $token->token)); + $this->assertFalse($this->cache->containsEntity(Token::CLASSNAME, $action->id)); $queryCount = $this->getCurrentQueryCount(); - $entity = $this->_em->find(Token::CLASSNAME, $token->getToken()); + $entity = $this->_em->find(Token::CLASSNAME, $token->token); $this->assertInstanceOf(Token::CLASSNAME, $entity); - $this->assertEquals('token-hash', $entity->getToken()); + $this->assertEquals('token-hash', $entity->token); $this->assertInstanceOf(Action::CLASSNAME, $entity->getAction()); - $this->assertEquals('exec', $entity->getAction()->getName()); + $this->assertEquals('exec', $entity->getAction()->name); $this->assertEquals($queryCount + 1, $this->getCurrentQueryCount()); } @@ -189,26 +189,26 @@ class SecondLevelCacheManyToOneTest extends SecondLevelCacheAbstractTest $complexAction->addToken($token); - $token->setAction($action2); + $token->action = $action2; $this->_em->persist($token); $this->_em->flush(); $this->_em->clear(); - $this->assertTrue($this->cache->containsEntity(Token::CLASSNAME, $token->getToken())); - $this->assertFalse($this->cache->containsEntity(Action::CLASSNAME, $action1->getId())); - $this->assertFalse($this->cache->containsEntity(Action::CLASSNAME, $action2->getId())); - $this->assertFalse($this->cache->containsEntity(Action::CLASSNAME, $action3->getId())); + $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)); $queryCount = $this->getCurrentQueryCount(); /** * @var $entity Token */ - $entity = $this->_em->find(Token::CLASSNAME, $token->getToken()); + $entity = $this->_em->find(Token::CLASSNAME, $token->token); $this->assertInstanceOf(Token::CLASSNAME, $entity); - $this->assertEquals('token-hash', $entity->getToken()); + $this->assertEquals('token-hash', $entity->token); $this->assertEquals($queryCount, $this->getCurrentQueryCount()); @@ -220,9 +220,9 @@ class SecondLevelCacheManyToOneTest extends SecondLevelCacheAbstractTest $this->assertInstanceOf(Action::CLASSNAME, $entity->getComplexAction()->getAction2()); $this->assertEquals($queryCount + 1, $this->getCurrentQueryCount()); - $this->assertEquals('login', $entity->getComplexAction()->getAction1()->getName()); + $this->assertEquals('login', $entity->getComplexAction()->getAction1()->name); $this->assertEquals($queryCount + 2, $this->getCurrentQueryCount()); - $this->assertEquals('rememberme', $entity->getComplexAction()->getAction2()->getName()); + $this->assertEquals('rememberme', $entity->getComplexAction()->getAction2()->name); $this->assertEquals($queryCount + 3, $this->getCurrentQueryCount()); } } \ No newline at end of file diff --git a/tests/Doctrine/Tests/ORM/Functional/SecondLevelCacheOneToManyTest.php b/tests/Doctrine/Tests/ORM/Functional/SecondLevelCacheOneToManyTest.php index c028584d6..3e4833dc8 100644 --- a/tests/Doctrine/Tests/ORM/Functional/SecondLevelCacheOneToManyTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/SecondLevelCacheOneToManyTest.php @@ -399,17 +399,17 @@ class SecondLevelCacheOneToManyTest extends SecondLevelCacheAbstractTest $this->_em->flush(); $this->_em->clear(); - $this->assertTrue($this->cache->containsEntity(Token::CLASSNAME, $token->getToken())); + $this->assertTrue($this->cache->containsEntity(Token::CLASSNAME, $token->token)); $queryCount = $this->getCurrentQueryCount(); - $entity = $this->_em->find(Token::CLASSNAME, $token->getToken()); + $entity = $this->_em->find(Token::CLASSNAME, $token->token); $this->assertInstanceOf(Token::CLASSNAME, $entity); - $this->assertEquals('token-hash', $entity->getToken()); + $this->assertEquals('token-hash', $entity->token); $this->assertEquals($queryCount, $this->getCurrentQueryCount()); - $this->assertCount(2, $entity->getLogins()); + $this->assertCount(2, $entity->logins); $this->assertEquals($queryCount + 1, $this->getCurrentQueryCount()); } } diff --git a/tests/Doctrine/Tests/ORM/Functional/SecondLevelCacheOneToOneTest.php b/tests/Doctrine/Tests/ORM/Functional/SecondLevelCacheOneToOneTest.php index e5012e859..8b5ffa6f8 100644 --- a/tests/Doctrine/Tests/ORM/Functional/SecondLevelCacheOneToOneTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/SecondLevelCacheOneToOneTest.php @@ -204,17 +204,17 @@ class SecondLevelCacheOneToOneTest extends SecondLevelCacheAbstractTest $queryCount = $this->getCurrentQueryCount(); - $this->assertTrue($this->cache->containsEntity(Token::CLASSNAME, $token->getToken())); - $this->assertFalse($this->cache->containsEntity(Client::CLASSNAME, $client->getId())); + $this->assertTrue($this->cache->containsEntity(Token::CLASSNAME, $token->token)); + $this->assertFalse($this->cache->containsEntity(Client::CLASSNAME, $client->id)); - $entity = $this->_em->find(Token::CLASSNAME, $token->getToken()); + $entity = $this->_em->find(Token::CLASSNAME, $token->token); $this->assertInstanceOf(Token::CLASSNAME, $entity); $this->assertInstanceOf(Client::CLASSNAME, $entity->getClient()); - $this->assertEquals('token-hash', $entity->getToken()); + $this->assertEquals('token-hash', $entity->token); $this->assertEquals($queryCount, $this->getCurrentQueryCount()); - $this->assertEquals('FabioBatSilva', $entity->getClient()->getName()); + $this->assertEquals('FabioBatSilva', $entity->getClient()->name); $this->assertEquals($queryCount + 1, $this->getCurrentQueryCount()); } } \ No newline at end of file