|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Doctrine\Tests\ORM\Functional\Ticket; |
|
4
|
|
|
|
|
5
|
|
|
use Doctrine\ORM\EntityNotFoundException; |
|
6
|
|
|
use Doctrine\Tests\OrmFunctionalTestCase; |
|
7
|
|
|
|
|
8
|
|
|
class GH7692Test extends OrmFunctionalTestCase |
|
9
|
|
|
{ |
|
10
|
|
|
/** |
|
11
|
|
|
* {@inheritDoc} |
|
12
|
|
|
*/ |
|
13
|
|
|
protected function setUp(): void |
|
14
|
|
|
{ |
|
15
|
|
|
parent::setUp(); |
|
16
|
|
|
|
|
17
|
|
|
$this->setUpEntitySchema([ |
|
18
|
|
|
GH7692AddressBook::class, |
|
19
|
|
|
GH7692Project::class, |
|
20
|
|
|
GH7692Contact::class, |
|
21
|
|
|
]); |
|
22
|
|
|
} |
|
23
|
|
|
|
|
24
|
|
|
public function testWithoutEagerLoading(): void |
|
25
|
|
|
{ |
|
26
|
|
|
$this->expectException(EntityNotFoundException::class); |
|
27
|
|
|
$this->expectExceptionMessage("Entity of type 'Doctrine\Tests\ORM\Functional\Ticket\GH7692Contact' for IDs category(999), number(999) was not found"); |
|
28
|
|
|
|
|
29
|
|
|
// Create a row that references missing rows |
|
30
|
|
|
$this->_em->getConnection()->insert('address_book', [ |
|
31
|
|
|
// This composite foreign key doesn't exist |
|
32
|
|
|
'contact_category' => 999, |
|
33
|
|
|
'contact_number' => 999, |
|
34
|
|
|
]); |
|
35
|
|
|
|
|
36
|
|
|
$books = $this->_em->createQuery('SELECT a FROM Doctrine\Tests\ORM\Functional\Ticket\GH7692AddressBook a')->getResult(); |
|
37
|
|
|
$this->assertCount(1, $books); |
|
38
|
|
|
$books[0]->contact->name; // access the property on the proxy to trigger the exception |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
public function testWithEagerLoading(): void |
|
42
|
|
|
{ |
|
43
|
|
|
$this->expectException(EntityNotFoundException::class); |
|
44
|
|
|
$this->expectExceptionMessage("Entity of type 'Doctrine\Tests\ORM\Functional\Ticket\GH7692Contact' for IDs category(999), number(999) was not found"); |
|
45
|
|
|
|
|
46
|
|
|
// Create a row that references missing rows |
|
47
|
|
|
$this->_em->getConnection()->insert('project', [ |
|
48
|
|
|
// This composite foreign key doesn't exist |
|
49
|
|
|
'contact_category' => 999, |
|
50
|
|
|
'contact_number' => 999, |
|
51
|
|
|
]); |
|
52
|
|
|
|
|
53
|
|
|
$this->_em->createQuery('SELECT p FROM Doctrine\Tests\ORM\Functional\Ticket\GH7692Project p')->getResult(); |
|
54
|
|
|
} |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
/** |
|
58
|
|
|
* @Entity |
|
59
|
|
|
* @Table(name="address_book") |
|
60
|
|
|
*/ |
|
61
|
|
|
class GH7692AddressBook |
|
62
|
|
|
{ |
|
63
|
|
|
/** |
|
64
|
|
|
* @Id |
|
65
|
|
|
* @Column(type="integer") |
|
66
|
|
|
* @GeneratedValue |
|
67
|
|
|
*/ |
|
68
|
|
|
public $id; |
|
69
|
|
|
|
|
70
|
|
|
/** |
|
71
|
|
|
* WITHOUT EAGER |
|
72
|
|
|
* |
|
73
|
|
|
* @ManyToOne(targetEntity="Doctrine\Tests\ORM\Functional\Ticket\GH7692Contact") |
|
74
|
|
|
* @JoinColumns({ |
|
75
|
|
|
* @JoinColumn(name="contact_category", referencedColumnName="category"), |
|
76
|
|
|
* @JoinColumn(name="contact_number", referencedColumnName="number") |
|
77
|
|
|
* }) |
|
78
|
|
|
*/ |
|
79
|
|
|
public $contact; |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
/** |
|
83
|
|
|
* @Entity |
|
84
|
|
|
* @Table(name="project") |
|
85
|
|
|
*/ |
|
86
|
|
|
class GH7692Project |
|
87
|
|
|
{ |
|
88
|
|
|
/** |
|
89
|
|
|
* @Id |
|
90
|
|
|
* @Column(type="integer") |
|
91
|
|
|
* @GeneratedValue |
|
92
|
|
|
*/ |
|
93
|
|
|
public $id; |
|
94
|
|
|
|
|
95
|
|
|
/** |
|
96
|
|
|
* WITH EAGER |
|
97
|
|
|
* |
|
98
|
|
|
* @ManyToOne(targetEntity="Doctrine\Tests\ORM\Functional\Ticket\GH7692Contact", fetch="EAGER") |
|
99
|
|
|
* @JoinColumns({ |
|
100
|
|
|
* @JoinColumn(name="contact_category", referencedColumnName="category"), |
|
101
|
|
|
* @JoinColumn(name="contact_number", referencedColumnName="number") |
|
102
|
|
|
* }) |
|
103
|
|
|
*/ |
|
104
|
|
|
public $contact; |
|
105
|
|
|
} |
|
106
|
|
|
|
|
107
|
|
|
/** |
|
108
|
|
|
* @Entity |
|
109
|
|
|
*/ |
|
110
|
|
|
class GH7692Contact |
|
111
|
|
|
{ |
|
112
|
|
|
/** |
|
113
|
|
|
* @Id |
|
114
|
|
|
* @Column(type="integer") |
|
115
|
|
|
*/ |
|
116
|
|
|
public $category; |
|
117
|
|
|
|
|
118
|
|
|
/** |
|
119
|
|
|
* @Id |
|
120
|
|
|
* @Column(type="integer") |
|
121
|
|
|
*/ |
|
122
|
|
|
public $number; |
|
123
|
|
|
|
|
124
|
|
|
/** |
|
125
|
|
|
* @Column(type="string") |
|
126
|
|
|
*/ |
|
127
|
|
|
public $name; |
|
128
|
|
|
} |
|
129
|
|
|
|