1
|
|
|
<?php |
2
|
|
|
namespace Doctrine\Tests\ORM\Functional\Ticket; |
3
|
|
|
|
4
|
|
|
use Doctrine\Common\Collections\ArrayCollection; |
5
|
|
|
use Doctrine\Tests\OrmFunctionalTestCase; |
6
|
|
|
|
7
|
|
|
final class GH6589Test extends OrmFunctionalTestCase |
8
|
|
|
{ |
9
|
|
|
protected function setUp() |
10
|
|
|
{ |
11
|
|
|
parent::setUp(); |
12
|
|
|
|
13
|
|
|
$this->_schemaTool->createSchema( |
14
|
|
|
[ |
15
|
|
|
$this->_em->getClassMetadata(GH6589Room::class), |
16
|
|
|
$this->_em->getClassMetadata(GH6589RoomType::class), |
17
|
|
|
] |
18
|
|
|
); |
19
|
|
|
|
20
|
|
|
$roomType1 = new GH6589RoomType(1); |
21
|
|
|
$roomType2 = new GH6589RoomType(2); |
22
|
|
|
$room = new GH6589Room(1, $roomType1); |
23
|
|
|
$this->_em->persist($roomType1); |
24
|
|
|
$this->_em->persist($roomType2); |
25
|
|
|
$this->_em->persist($room); |
26
|
|
|
$this->_em->flush(); |
27
|
|
|
$this->_em->clear(); |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
public function testMoveTo() |
31
|
|
|
{ |
32
|
|
|
/** @var GH6589RoomType $roomType2 */ |
33
|
|
|
$roomType2 = $this->_em->find(GH6589RoomType::class, 2); |
34
|
|
|
|
35
|
|
|
/** @var GH6589Room $room */ |
36
|
|
|
$room = $this->_em->find(GH6589Room::class, 1); |
37
|
|
|
$room->moveTo($roomType2); |
38
|
|
|
|
39
|
|
|
self::assertEquals(2, $room->roomType->id); |
40
|
|
|
} |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* @Entity |
45
|
|
|
*/ |
46
|
|
|
class GH6589Room |
47
|
|
|
{ |
48
|
|
|
/** |
49
|
|
|
* @var integer |
50
|
|
|
* |
51
|
|
|
* @Id |
52
|
|
|
* @Column(type="integer") |
53
|
|
|
*/ |
54
|
|
|
public $id; |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* @var GH6589RoomType |
58
|
|
|
* |
59
|
|
|
* @ManyToOne(targetEntity=GH6589RoomType::class, inversedBy="rooms") |
60
|
|
|
*/ |
61
|
|
|
public $roomType; |
62
|
|
|
|
63
|
|
|
public function __construct($id, GH6589RoomType $roomType) |
64
|
|
|
{ |
65
|
|
|
$this->id = $id; |
66
|
|
|
$this->roomType = $roomType; |
67
|
|
|
$this->roomType->addRoom($this); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
public function moveTo(GH6589RoomType $roomType) |
71
|
|
|
{ |
72
|
|
|
$oldRoomType = $this->roomType; |
73
|
|
|
$this->roomType = $roomType; |
74
|
|
|
$roomType->addRoom($this); |
75
|
|
|
$oldRoomType->removeRoom($this); |
76
|
|
|
} |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* @Entity |
81
|
|
|
*/ |
82
|
|
|
class GH6589RoomType |
83
|
|
|
{ |
84
|
|
|
/** |
85
|
|
|
* @var integer |
86
|
|
|
* |
87
|
|
|
* @Id |
88
|
|
|
* @Column(type="integer") |
89
|
|
|
*/ |
90
|
|
|
public $id; |
91
|
|
|
|
92
|
|
|
/** |
93
|
|
|
* @var GH6589Room[] |
94
|
|
|
* |
95
|
|
|
* @OneToMany(targetEntity=GH6589Room::class, mappedBy="roomType") |
96
|
|
|
*/ |
97
|
|
|
public $rooms; |
98
|
|
|
|
99
|
|
|
public function __construct($id) |
100
|
|
|
{ |
101
|
|
|
$this->id = $id; |
102
|
|
|
$this->rooms = new ArrayCollection(); |
|
|
|
|
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
public function addRoom(GH6589Room $room) |
106
|
|
|
{ |
107
|
|
|
$this->rooms->add($room); |
|
|
|
|
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
public function removeRoom(GH6589Room $room) |
111
|
|
|
{ |
112
|
|
|
$this->rooms->removeElement($room); |
|
|
|
|
113
|
|
|
} |
114
|
|
|
} |
115
|
|
|
|
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..