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

Add failing test

This commit is contained in:
Michaël Gallego 2015-02-11 09:59:41 +01:00 committed by Asmir Mustafic
parent a13143b1ac
commit ed6fa0deb4
4 changed files with 149 additions and 0 deletions

View File

@ -0,0 +1,49 @@
<?php
namespace Doctrine\Tests\Models\Cache;
/**
* @Entity
* @Table("cache_client")
*/
class Client
{
const CLASSNAME = __CLASS__;
/**
* @Id
* @GeneratedValue
* @Column(type="integer")
*/
protected $id;
/**
* @Column(unique=true)
*/
private $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;
}
}

View File

@ -0,0 +1,66 @@
<?php
namespace Doctrine\Tests\Models\Cache;
/**
* @Entity
* @Cache("READ_ONLY")
* @Table("cache_token")
*/
class Token
{
const CLASSNAME = __CLASS__;
/**
* @Id
* @Column(type="string")
*/
protected $token;
/**
* @Column(type="date")
*/
protected $expiresAt;
/**
* @OneToOne(targetEntity="Client")
*/
protected $client;
public function __construct($token, Client $client = null)
{
$this->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;
}
}

View File

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

View File

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