-
Notifications
You must be signed in to change notification settings - Fork 2.5k
/
DDC1436Test.php
89 lines (76 loc) · 2.04 KB
/
DDC1436Test.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
<?php
namespace Doctrine\Tests\ORM\Functional\Ticket;
use Doctrine\ORM\UnitOfWork;
/**
* @group DDC-1436
*/
class DDC1436Test extends \Doctrine\Tests\OrmFunctionalTestCase
{
protected function setUp()
{
parent::setUp();
try {
$this->_schemaTool->createSchema(array(
$this->_em->getClassMetadata(__NAMESPACE__ . '\DDC1436Page'),
));
} catch (\Exception $ignored) {
}
}
public function testIdentityMap()
{
// fixtures
$parent = null;
for ($i = 0; $i < 3; $i++) {
$page = new DDC1436Page();
$page->setParent($parent);
$this->_em->persist($page);
$parent = $page;
}
$this->_em->flush();
$this->_em->clear();
$id = $parent->getId();
// step 1
$page = $this->_em
->createQuery('SELECT p, parent FROM ' . __NAMESPACE__ . '\DDC1436Page p LEFT JOIN p.parent parent WHERE p.id = :id')
->setParameter('id', $id)
->getOneOrNullResult();
$this->assertInstanceOf(__NAMESPACE__ . '\DDC1436Page', $page);
// step 2
$page = $this->_em->find(__NAMESPACE__ . '\DDC1436Page', $id);
$this->assertInstanceOf(__NAMESPACE__ . '\DDC1436Page', $page);
$this->assertInstanceOf(__NAMESPACE__ . '\DDC1436Page', $page->getParent());
$this->assertInstanceOf(__NAMESPACE__ . '\DDC1436Page', $page->getParent()->getParent());
}
}
/**
* @Entity
*/
class DDC1436Page
{
/**
* @Id
* @GeneratedValue
* @Column(type="integer", name="id")
*/
protected $id;
/**
* @ManyToOne(targetEntity="DDC1436Page")
* @JoinColumn(name="pid", referencedColumnName="id")
*/
protected $parent;
public function getId()
{
return $this->id;
}
/**
* @return DDC1436Page
*/
public function getParent()
{
return $this->parent;
}
public function setParent($parent)
{
$this->parent = $parent;
}
}