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