2017-02-10 17:12:51 +01:00
|
|
|
<?php
|
|
|
|
namespace Doctrine\Tests\Functional\Ticket;
|
|
|
|
|
|
|
|
use Doctrine\Tests\OrmFunctionalTestCase;
|
|
|
|
|
2017-08-22 21:38:44 +02:00
|
|
|
/**
|
|
|
|
* @group #6217
|
|
|
|
*/
|
2017-02-10 17:12:51 +01:00
|
|
|
final class GH6217Test extends OrmFunctionalTestCase
|
|
|
|
{
|
2017-08-22 21:38:44 +02:00
|
|
|
public function setUp() : void
|
2017-02-10 17:12:51 +01:00
|
|
|
{
|
|
|
|
$this->enableSecondLevelCache();
|
|
|
|
|
|
|
|
parent::setUp();
|
|
|
|
|
2017-08-22 21:31:01 +02:00
|
|
|
$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
|
|
|
}
|
|
|
|
|
2017-08-22 21:38:44 +02:00
|
|
|
public function testLoadingOfSecondLevelCacheOnEagerAssociations() : void
|
2017-02-10 17:12:51 +01:00
|
|
|
{
|
2017-08-22 21:38:44 +02:00
|
|
|
$lazy = new GH6217LazyEntity();
|
|
|
|
$eager = new GH6217EagerEntity();
|
|
|
|
$fetched = new GH6217FetchedEntity($lazy, $eager);
|
2017-02-10 17:12:51 +01:00
|
|
|
|
2017-08-22 21:38:44 +02:00
|
|
|
$this->_em->persist($eager);
|
|
|
|
$this->_em->persist($lazy);
|
|
|
|
$this->_em->persist($fetched);
|
2017-02-10 17:12:51 +01:00
|
|
|
$this->_em->flush();
|
|
|
|
$this->_em->clear();
|
|
|
|
|
2017-08-22 21:29:27 +02:00
|
|
|
$repository = $this->_em->getRepository(GH6217FetchedEntity::class);
|
2017-08-22 21:38:44 +02:00
|
|
|
$filters = ['eager' => $eager->id];
|
2017-02-10 17:12:51 +01:00
|
|
|
|
|
|
|
$this->assertCount(1, $repository->findBy($filters));
|
|
|
|
$queryCount = $this->getCurrentQueryCount();
|
|
|
|
|
2017-08-22 21:29:27 +02:00
|
|
|
/* @var $found GH6217FetchedEntity[] */
|
2017-08-22 21:27:46 +02:00
|
|
|
$found = $repository->findBy($filters);
|
|
|
|
|
|
|
|
$this->assertCount(1, $found);
|
2017-08-22 21:29:27 +02:00
|
|
|
$this->assertInstanceOf(GH6217FetchedEntity::class, $found[0]);
|
2017-08-22 21:38:44 +02:00
|
|
|
$this->assertSame($lazy->id, $found[0]->lazy->id);
|
|
|
|
$this->assertSame($eager->id, $found[0]->eager->id);
|
|
|
|
$this->assertEquals($queryCount, $this->getCurrentQueryCount(), 'No queries were executed in `findBy`');
|
2017-02-10 17:12:51 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-22 21:12:45 +02:00
|
|
|
/** @Entity @Cache(usage="NONSTRICT_READ_WRITE") */
|
2017-08-22 21:29:27 +02:00
|
|
|
class GH6217LazyEntity
|
2017-02-10 17:12:51 +01:00
|
|
|
{
|
2017-08-22 21:17:14 +02:00
|
|
|
/** @Id @Column(type="string") @GeneratedValue(strategy="NONE") */
|
2017-02-10 17:12:51 +01:00
|
|
|
public $id;
|
|
|
|
|
2017-08-22 21:11:03 +02:00
|
|
|
public function __construct()
|
2017-02-10 17:12:51 +01:00
|
|
|
{
|
2017-08-22 21:11:03 +02:00
|
|
|
$this->id = uniqid(self::class, true);
|
2017-02-10 17:12:51 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-22 21:12:45 +02:00
|
|
|
/** @Entity @Cache(usage="NONSTRICT_READ_WRITE") */
|
2017-08-22 21:29:27 +02:00
|
|
|
class GH6217EagerEntity
|
2017-02-10 17:12:51 +01:00
|
|
|
{
|
2017-08-22 21:17:14 +02:00
|
|
|
/** @Id @Column(type="string") @GeneratedValue(strategy="NONE") */
|
2017-02-10 17:12:51 +01:00
|
|
|
public $id;
|
|
|
|
|
2017-08-22 21:11:03 +02:00
|
|
|
public function __construct()
|
2017-02-10 17:12:51 +01:00
|
|
|
{
|
2017-08-22 21:11:03 +02:00
|
|
|
$this->id = uniqid(self::class, true);
|
2017-02-10 17:12:51 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-22 21:12:45 +02:00
|
|
|
/** @Entity @Cache(usage="NONSTRICT_READ_WRITE") */
|
2017-08-22 21:29:27 +02:00
|
|
|
class GH6217FetchedEntity
|
2017-02-10 17:12:51 +01:00
|
|
|
{
|
2017-08-22 21:29:27 +02:00
|
|
|
/** @Id @Cache("NONSTRICT_READ_WRITE") @ManyToOne(targetEntity=GH6217LazyEntity::class) */
|
2017-08-22 21:38:44 +02:00
|
|
|
public $lazy;
|
2017-02-10 17:12:51 +01:00
|
|
|
|
2017-08-22 21:29:27 +02:00
|
|
|
/** @Id @Cache("NONSTRICT_READ_WRITE") @ManyToOne(targetEntity=GH6217EagerEntity::class, fetch="EAGER") */
|
2017-08-22 21:38:44 +02:00
|
|
|
public $eager;
|
2017-02-10 17:12:51 +01:00
|
|
|
|
2017-08-22 21:38:44 +02:00
|
|
|
public function __construct(GH6217LazyEntity $lazy, GH6217EagerEntity $eager)
|
2017-02-10 17:12:51 +01:00
|
|
|
{
|
2017-08-22 21:38:44 +02:00
|
|
|
$this->lazy = $lazy;
|
|
|
|
$this->eager = $eager;
|
2017-02-10 17:12:51 +01:00
|
|
|
}
|
|
|
|
}
|