1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Doctrine\Tests\ORM\Functional\Ticket; |
6
|
|
|
|
7
|
|
|
use Doctrine\Common\Collections\ArrayCollection; |
8
|
|
|
use Doctrine\Tests\OrmFunctionalTestCase; |
9
|
|
|
use function array_values; |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* @group gh7864 |
13
|
|
|
*/ |
14
|
|
|
class GH7864Test extends OrmFunctionalTestCase |
15
|
|
|
{ |
16
|
|
|
protected function setUp() : void |
17
|
|
|
{ |
18
|
|
|
parent::setup(); |
19
|
|
|
|
20
|
|
|
$this->setUpEntitySchema( |
21
|
|
|
[ |
22
|
|
|
GH7864User::class, |
23
|
|
|
GH7864Tweet::class, |
24
|
|
|
] |
25
|
|
|
); |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
public function testExtraLazyRemoveElement() |
29
|
|
|
{ |
30
|
|
|
$user = new GH7864User(); |
31
|
|
|
$user->name = 'test'; |
32
|
|
|
|
33
|
|
|
$tweet1 = new GH7864Tweet(); |
34
|
|
|
$tweet1->content = 'Hello World!'; |
35
|
|
|
$user->addTweet($tweet1); |
36
|
|
|
|
37
|
|
|
$tweet2 = new GH7864Tweet(); |
38
|
|
|
$tweet2->content = 'Goodbye, and thanks for all the fish'; |
39
|
|
|
$user->addTweet($tweet2); |
40
|
|
|
|
41
|
|
|
$this->_em->persist($user); |
42
|
|
|
$this->_em->persist($tweet1); |
43
|
|
|
$this->_em->persist($tweet2); |
44
|
|
|
$this->_em->flush(); |
45
|
|
|
$this->_em->clear(); |
46
|
|
|
|
47
|
|
|
$user = $this->_em->find(GH7864User::class, $user->id); |
48
|
|
|
$tweet = $this->_em->find(GH7864Tweet::class, $tweet1->id); |
49
|
|
|
|
50
|
|
|
$user->tweets->removeElement($tweet); |
51
|
|
|
|
52
|
|
|
$tweets = $user->tweets->map(static function (GH7864Tweet $tweet) { |
53
|
|
|
return $tweet->content; |
54
|
|
|
}); |
55
|
|
|
|
56
|
|
|
$this->assertEquals(['Goodbye, and thanks for all the fish'], array_values($tweets->toArray())); |
57
|
|
|
} |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* @Entity |
62
|
|
|
*/ |
63
|
|
|
class GH7864User |
64
|
|
|
{ |
65
|
|
|
/** @Id @Column(type="integer") @GeneratedValue */ |
66
|
|
|
public $id; |
67
|
|
|
|
68
|
|
|
/** @Column(type="string") */ |
69
|
|
|
public $name; |
70
|
|
|
|
71
|
|
|
/** @OneToMany(targetEntity="GH7864Tweet", mappedBy="user", fetch="EXTRA_LAZY") */ |
72
|
|
|
public $tweets; |
73
|
|
|
|
74
|
|
|
public function __construct() |
75
|
|
|
{ |
76
|
|
|
$this->tweets = new ArrayCollection(); |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
public function addTweet(GH7864Tweet $tweet) |
80
|
|
|
{ |
81
|
|
|
$tweet->user = $this; |
82
|
|
|
$this->tweets->add($tweet); |
83
|
|
|
} |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* @Entity |
88
|
|
|
*/ |
89
|
|
|
class GH7864Tweet |
90
|
|
|
{ |
91
|
|
|
/** @Id @Column(type="integer") @GeneratedValue */ |
92
|
|
|
public $id; |
93
|
|
|
|
94
|
|
|
/** @Column(type="string") */ |
95
|
|
|
public $content; |
96
|
|
|
|
97
|
|
|
/** @ManyToOne(targetEntity="GH7864User", inversedBy="tweets") */ |
98
|
|
|
public $user; |
99
|
|
|
} |
100
|
|
|
|