1
0
mirror of synced 2025-02-03 22:09:26 +03:00

96 lines
2.7 KiB
PHP
Raw Normal View History

2017-02-10 17:12:51 +01:00
<?php
namespace Doctrine\Tests\Functional\Ticket;
use Doctrine\Tests\OrmFunctionalTestCase;
final class GH6217Test extends OrmFunctionalTestCase
{
public function setUp()
{
$this->enableSecondLevelCache();
parent::setUp();
$this->_schemaTool->createSchema(
[
$this->_em->getClassMetadata(GH6217LazyEntity::class),
$this->_em->getClassMetadata(GH6217EagerEntity::class),
$this->_em->getClassMetadata(GH6217FetchedEntity::class),
2017-02-10 17:12:51 +01:00
]
);
}
/**
* @group 6217
*/
public function testRetrievingCacheShouldNotThrowUndefinedIndexException()
{
$user = new GH6217LazyEntity();
$category = new GH6217EagerEntity();
$userProfile = new GH6217FetchedEntity($user, $category);
2017-02-10 17:12:51 +01:00
$this->_em->persist($category);
$this->_em->persist($user);
$this->_em->persist($userProfile);
$this->_em->flush();
$this->_em->clear();
$repository = $this->_em->getRepository(GH6217FetchedEntity::class);
$filters = ['category' => $category->id];
2017-02-10 17:12:51 +01:00
$this->assertCount(1, $repository->findBy($filters));
$queryCount = $this->getCurrentQueryCount();
$this->_em->clear();
/* @var $found GH6217FetchedEntity[] */
$found = $repository->findBy($filters);
$this->assertCount(1, $found);
$this->assertInstanceOf(GH6217FetchedEntity::class, $found[0]);
$this->assertSame($user->id, $found[0]->user->id);
$this->assertSame($category->id, $found[0]->category->id);
2017-02-10 17:12:51 +01:00
$this->assertEquals($queryCount, $this->getCurrentQueryCount());
}
}
/** @Entity @Cache(usage="NONSTRICT_READ_WRITE") */
class GH6217LazyEntity
2017-02-10 17:12:51 +01:00
{
/** @Id @Column(type="string") @GeneratedValue(strategy="NONE") */
2017-02-10 17:12:51 +01:00
public $id;
public function __construct()
2017-02-10 17:12:51 +01:00
{
$this->id = uniqid(self::class, true);
2017-02-10 17:12:51 +01:00
}
}
/** @Entity @Cache(usage="NONSTRICT_READ_WRITE") */
class GH6217EagerEntity
2017-02-10 17:12:51 +01:00
{
/** @Id @Column(type="string") @GeneratedValue(strategy="NONE") */
2017-02-10 17:12:51 +01:00
public $id;
public function __construct()
2017-02-10 17:12:51 +01:00
{
$this->id = uniqid(self::class, true);
2017-02-10 17:12:51 +01:00
}
}
/** @Entity @Cache(usage="NONSTRICT_READ_WRITE") */
class GH6217FetchedEntity
2017-02-10 17:12:51 +01:00
{
/** @Id @Cache("NONSTRICT_READ_WRITE") @ManyToOne(targetEntity=GH6217LazyEntity::class) */
2017-02-10 17:12:51 +01:00
public $user;
/** @Id @Cache("NONSTRICT_READ_WRITE") @ManyToOne(targetEntity=GH6217EagerEntity::class, fetch="EAGER") */
2017-02-10 17:12:51 +01:00
public $category;
public function __construct(GH6217LazyEntity $user, GH6217EagerEntity $category)
2017-02-10 17:12:51 +01:00
{
$this->user = $user;
$this->category = $category;
}
}