1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Doctrine\Tests\ORM\Functional\Ticket; |
4
|
|
|
|
5
|
|
|
use Doctrine\DBAL\Schema\SchemaException; |
6
|
|
|
use Doctrine\ORM\Mapping\Column; |
7
|
|
|
use Doctrine\ORM\Mapping\Embeddable; |
8
|
|
|
use Doctrine\ORM\Mapping\Entity; |
9
|
|
|
use Doctrine\ORM\Mapping\Id; |
10
|
|
|
use Doctrine\ORM\Mapping\GeneratedValue; |
11
|
|
|
use Doctrine\ORM\Mapping\ManyToOne; |
12
|
|
|
use Doctrine\ORM\Proxy\Proxy; |
13
|
|
|
|
14
|
|
|
class DDC6460Test extends \Doctrine\Tests\OrmFunctionalTestCase |
15
|
|
|
{ |
16
|
|
|
public function setUp() |
17
|
|
|
{ |
18
|
|
|
parent::setUp(); |
19
|
|
|
|
20
|
|
|
try { |
21
|
|
|
$this->setUpEntitySchema( |
22
|
|
|
[ |
23
|
|
|
DDC6460Entity::class, |
24
|
|
|
DDC6460ParentEntity::class, |
25
|
|
|
] |
26
|
|
|
); |
27
|
|
|
} catch (SchemaException $e) { |
28
|
|
|
} |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @group DDC-6460 |
33
|
|
|
*/ |
34
|
|
|
public function testInlineEmbeddable() |
35
|
|
|
{ |
36
|
|
|
$isFieldMapped = $this->_em |
37
|
|
|
->getClassMetadata(DDC6460Entity::class) |
38
|
|
|
->hasField('embedded'); |
39
|
|
|
|
40
|
|
|
$this->assertTrue($isFieldMapped); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* @group DDC-6460 |
45
|
|
|
*/ |
46
|
|
|
public function testInlineEmbeddableProxyInitialization() |
47
|
|
|
{ |
48
|
|
|
$entity = new DDC6460Entity(); |
49
|
|
|
$entity->id = 1; |
50
|
|
|
$entity->embedded = new DDC6460Embeddable(); |
51
|
|
|
$entity->embedded->field = 'test'; |
52
|
|
|
$this->_em->persist($entity); |
53
|
|
|
|
54
|
|
|
$second = new DDC6460ParentEntity(); |
55
|
|
|
$second->id = 1; |
56
|
|
|
$second->lazyLoaded = $entity; |
57
|
|
|
$this->_em->persist($second); |
58
|
|
|
$this->_em->flush(); |
59
|
|
|
|
60
|
|
|
$this->_em->clear(); |
61
|
|
|
|
62
|
|
|
$secondEntityWithLazyParameter = $this->_em->getRepository(DDC6460ParentEntity::class)->findOneById(1); |
63
|
|
|
|
64
|
|
|
$this->assertInstanceOf(Proxy::class, $secondEntityWithLazyParameter->lazyLoaded); |
65
|
|
|
$this->assertInstanceOf(DDC6460Entity::class, $secondEntityWithLazyParameter->lazyLoaded); |
66
|
|
|
$this->assertFalse($secondEntityWithLazyParameter->lazyLoaded->__isInitialized()); |
67
|
|
|
$this->assertEquals($secondEntityWithLazyParameter->lazyLoaded->embedded, $entity->embedded); |
68
|
|
|
$this->assertTrue($secondEntityWithLazyParameter->lazyLoaded->__isInitialized()); |
69
|
|
|
} |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* @Embeddable() |
74
|
|
|
*/ |
75
|
|
|
class DDC6460Embeddable |
76
|
|
|
{ |
77
|
|
|
/** @Column(type="string") */ |
78
|
|
|
public $field; |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* @Entity() |
83
|
|
|
*/ |
84
|
|
|
class DDC6460Entity |
85
|
|
|
{ |
86
|
|
|
/** |
87
|
|
|
* @Id |
88
|
|
|
* @GeneratedValue(strategy = "NONE") |
89
|
|
|
* @Column(type = "integer") |
90
|
|
|
*/ |
91
|
|
|
public $id; |
92
|
|
|
|
93
|
|
|
/** @Embedded(class = "DDC6460Embeddable") */ |
94
|
|
|
public $embedded; |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
/** |
98
|
|
|
* @Entity() |
99
|
|
|
*/ |
100
|
|
|
class DDC6460ParentEntity |
101
|
|
|
{ |
102
|
|
|
/** |
103
|
|
|
* @Id |
104
|
|
|
* @GeneratedValue(strategy = "NONE") |
105
|
|
|
* @Column(type = "integer") |
106
|
|
|
*/ |
107
|
|
|
public $id; |
108
|
|
|
|
109
|
|
|
/** @ManyToOne(targetEntity = "DDC6460Entity", fetch="EXTRA_LAZY", cascade={"persist"}) */ |
110
|
|
|
public $lazyLoaded; |
111
|
|
|
} |
112
|
|
|
|