Skip to content

Instantly share code, notes, and snippets.

@doctrinebot
Created December 13, 2015 18:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save doctrinebot/366b6e5648140b32bc27 to your computer and use it in GitHub Desktop.
Save doctrinebot/366b6e5648140b32bc27 to your computer and use it in GitHub Desktop.
Attachments to Doctrine Jira Issue DDC-446 - https://github.com/doctrine/doctrine2/issues/4947
<?php
namespace Doctrine\Tests\ORM\Functional\Ticket;
use Doctrine\Common\Cache\ArrayCache,
Doctrine\Tests\Models\CMS\CmsUser,
Doctrine\Tests\Models\CMS\CmsArticle;
require_once __DIR__ . '/../../../TestInit.php';
/**
* Functional Query tests.
*
* @author Guilherme Blanco
*/
class DDC446Test extends \Doctrine\Tests\OrmFunctionalTestCase
{
protected function setUp()
{
$this->useModelSet('cms');
parent::setUp();
}
public function testTicket()
{
$user = new CmsUser;
$user->name = 'Roman';
$user->username = 'romanb';
$user->status = 'dev';
$this->_em->persist($user);
$this->_em->flush();
unset($user);
$this->_em->clear();
$cache = new ArrayCache();
$query = $this->_em->createQuery("select u from Doctrine\Tests\Models\CMS\CmsUser u WHERE u.username = ?1");
$query->setResultCacheDriver($cache)->setResultCacheId('ddc446test_cache_id');
$query->setParameter(1, 'romanb');
$r = $query->getSingleResult();
$this->assertTrue($cache->contains('ddc446test_cache_id'));
$this->_em->clear();
// Now we'll retrieve object from cache
$query = $this->_em->createQuery("select u from Doctrine\Tests\Models\CMS\CmsUser u WHERE u.username = ?1");
$query->setResultCacheDriver($cache)->setResultCacheId('ddc446test_cache_id');
$query->setParameter(1, 'romanb');
$user = $query->getSingleResult();
// Attempt to create a related object
$article = new CmsArticle();
$article->topic = 'How ResultCache should work smoothly';
$article->text = 'Once upon a time, there was an ORM tool called Doctrine...';
$article->setAuthor($user);
$this->_em->persist($article);
$this->_em->flush(); // Should not fail here
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment