1
0
mirror of synced 2024-12-05 03:06:05 +03:00

Added tests for many-to-one non cache-able relations

This commit is contained in:
Asmir Mustafic 2015-02-12 18:53:21 +01:00
parent 60164931b8
commit b9577bf2f3
4 changed files with 119 additions and 0 deletions

View File

@ -0,0 +1,68 @@
<?php
namespace Doctrine\Tests\Models\Cache;
use Doctrine\Common\Collections\ArrayCollection;
/**
* @Entity
* @Table("cache_action")
*/
class Action
{
const CLASSNAME = __CLASS__;
/**
* @Id
* @GeneratedValue
* @Column(type="integer")
*/
protected $id;
/**
* @Column
*/
private $name;
/**
* @OneToMany(targetEntity="Token", cascade={"persist", "remove"}, mappedBy="action")
*/
private $tokens;
public function __construct($name)
{
$this->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;
}
}

View File

@ -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;

View File

@ -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());
}
}

View File

@ -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'])) {