1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Doctrine\Tests\Functional\Ticket; |
6
|
|
|
|
7
|
|
|
use Doctrine\Tests\OrmFunctionalTestCase; |
8
|
|
|
use function array_keys; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* @group GH-7661 |
12
|
|
|
*/ |
13
|
|
|
class GH7661Test extends OrmFunctionalTestCase |
14
|
|
|
{ |
15
|
|
|
/** |
16
|
|
|
* {@inheritDoc} |
17
|
|
|
*/ |
18
|
|
|
protected function setUp() : void |
19
|
|
|
{ |
20
|
|
|
parent::setUp(); |
21
|
|
|
|
22
|
|
|
$this->setUpEntitySchema([ |
23
|
|
|
GH7661User::class, |
24
|
|
|
GH7661Event::class, |
25
|
|
|
GH7661Participant::class, |
26
|
|
|
]); |
27
|
|
|
|
28
|
|
|
$u1 = new GH7661User(); |
29
|
|
|
$u2 = new GH7661User(); |
30
|
|
|
$e = new GH7661Event(); |
31
|
|
|
$this->_em->persist($u1); |
32
|
|
|
$this->_em->persist($u2); |
33
|
|
|
$this->_em->persist($e); |
34
|
|
|
$this->_em->persist(new GH7661Participant($u1, $e)); |
35
|
|
|
$this->_em->persist(new GH7661Participant($u2, $e)); |
36
|
|
|
$this->_em->flush(); |
37
|
|
|
$this->_em->clear(); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
public function testIndexByAssociation() : void |
41
|
|
|
{ |
42
|
|
|
$e = $this->_em->find(GH7661Event::class, 1); |
43
|
|
|
$keys = $e->participants->getKeys(); |
44
|
|
|
self::assertEquals([1, 2], $keys); |
45
|
|
|
|
46
|
|
|
$participants = $this->_em->createQuery('SELECT p FROM ' . GH7661Participant::class . ' p INDEX BY p.user')->getResult(); |
47
|
|
|
$keys = array_keys($participants); |
48
|
|
|
self::assertEquals([1, 2], $keys); |
49
|
|
|
} |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* @Entity |
54
|
|
|
*/ |
55
|
|
|
class GH7661User |
56
|
|
|
{ |
57
|
|
|
/** |
58
|
|
|
* @Id |
59
|
|
|
* @Column(type="integer") |
60
|
|
|
* @GeneratedValue |
61
|
|
|
*/ |
62
|
|
|
public $id; |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* @Entity |
67
|
|
|
*/ |
68
|
|
|
class GH7661Event |
69
|
|
|
{ |
70
|
|
|
/** |
71
|
|
|
* @Id |
72
|
|
|
* @Column(type="integer") |
73
|
|
|
* @GeneratedValue |
74
|
|
|
*/ |
75
|
|
|
public $id; |
76
|
|
|
/** @OneToMany(targetEntity=GH7661Participant::class, mappedBy="event", indexBy="user_id") */ |
77
|
|
|
public $participants; |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* @Entity |
82
|
|
|
*/ |
83
|
|
|
class GH7661Participant |
84
|
|
|
{ |
85
|
|
|
/** |
86
|
|
|
* @Id |
87
|
|
|
* @Column(type="integer") |
88
|
|
|
* @GeneratedValue |
89
|
|
|
*/ |
90
|
|
|
public $id; |
91
|
|
|
/** @ManyToOne(targetEntity=GH7661User::class) */ |
92
|
|
|
public $user; |
93
|
|
|
/** @ManyToOne(targetEntity=GH7661Event::class) */ |
94
|
|
|
public $event; |
95
|
|
|
|
96
|
|
|
public function __construct(GH7661User $user, GH7661Event $event) |
97
|
|
|
{ |
98
|
|
|
$this->user = $user; |
99
|
|
|
$this->event = $event; |
100
|
|
|
} |
101
|
|
|
} |
102
|
|
|
|