From b9577bf2f374ddeecb6cb7355badd82b5417e0ac Mon Sep 17 00:00:00 2001 From: Asmir Mustafic Date: Thu, 12 Feb 2015 18:53:21 +0100 Subject: [PATCH] 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'])) {