Rajout de doctrine/orm
[zf2.biz/galerie.git] / vendor / doctrine / orm / tests / Doctrine / Tests / ORM / Functional / Ticket / DDC1181Test.php
1 <?php
2
3 namespace Doctrine\Tests\ORM\Functional\Ticket;
4
5 require_once __DIR__ . '/../../../TestInit.php';
6
7 class DDC1181Test extends \Doctrine\Tests\OrmFunctionalTestCase
8 {
9     public function setUp()
10     {
11         parent::setUp();
12         $this->_schemaTool->createSchema(array(
13             $this->_em->getClassMetadata(__NAMESPACE__ . '\\DDC1181Hotel'),
14             $this->_em->getClassMetadata(__NAMESPACE__ . '\\DDC1181Booking'),
15             $this->_em->getClassMetadata(__NAMESPACE__ . '\\DDC1181Room'),
16         ));
17     }
18
19     /**
20      * @group DDC-1181
21      */
22     public function testIssue()
23     {
24         $hotel = new DDC1181Hotel();
25         $room1 = new DDC1181Room();
26         $room2 = new DDC1181Room();
27
28         $this->_em->persist($hotel);
29         $this->_em->persist($room1);
30         $this->_em->persist($room2);
31         $this->_em->flush();
32
33         $booking1 = new DDC1181Booking;
34         $booking1->hotel = $hotel;
35         $booking1->room = $room1;
36         $booking2 = new DDC1181Booking;
37         $booking2->hotel = $hotel;
38         $booking2->room = $room2;
39         $hotel->bookings[] = $booking1;
40         $hotel->bookings[] = $booking2;
41
42         $this->_em->persist($booking1);
43         $this->_em->persist($booking2);
44         $this->_em->flush();
45
46         $this->_em->remove($hotel);
47         $this->_em->flush();
48     }
49 }
50
51 /**
52  * @Entity
53  */
54 class DDC1181Hotel
55 {
56     /** @Id @Column(type="integer") @GeneratedValue */
57     public $id;
58
59     /**
60      * @oneToMany(targetEntity="DDC1181Booking", mappedBy="hotel", cascade={"remove"})
61      * @var Booking[]
62      */
63     public $bookings;
64
65 }
66
67 /**
68  * @Entity
69  */
70 class DDC1181Booking
71 {
72     /**
73      * @var Hotel
74      *
75      * @Id
76      * @ManyToOne(targetEntity="DDC1181Hotel", inversedBy="bookings")
77      * @JoinColumns({
78      *   @JoinColumn(name="hotel_id", referencedColumnName="id")
79      * })
80      */
81     public $hotel;
82     /**
83      * @var Room
84      *
85      * @Id
86      * @ManyToOne(targetEntity="DDC1181Room")
87      * @JoinColumns({
88      *   @JoinColumn(name="room_id", referencedColumnName="id")
89      * })
90      */
91     public $room;
92 }
93
94 /**
95  * @Entity
96  */
97 class DDC1181Room
98 {
99     /** @Id @Column(type="integer") @GeneratedValue */
100     public $id;
101 }