Rajout de doctrine/orm
[zf2.biz/galerie.git] / vendor / doctrine / orm / tests / Doctrine / Tests / ORM / Functional / Ticket / DDC1209Test.php
1 <?php
2
3 namespace Doctrine\Tests\ORM\Functional\Ticket;
4
5 use Doctrine\Common\Collections\ArrayCollection;
6
7 require_once __DIR__ . '/../../../TestInit.php';
8
9 class DDC1209Test extends \Doctrine\Tests\OrmFunctionalTestCase
10 {
11     protected function setUp()
12     {
13         parent::setUp();
14         try {
15             $this->_schemaTool->createSchema(array(
16                 $this->_em->getClassMetadata(__NAMESPACE__ . '\\DDC1209_1'),
17                 $this->_em->getClassMetadata(__NAMESPACE__ . '\\DDC1209_2'),
18                 $this->_em->getClassMetadata(__NAMESPACE__ . '\\DDC1209_3')
19             ));
20         } catch(\Exception $e) {
21         }
22     }
23
24     /**
25      * @group DDC-1209
26      */
27     public function testIdentifierCanHaveCustomType()
28     {
29         $this->_em->persist(new DDC1209_3());
30         $this->_em->flush();
31     }
32
33     /**
34      * @group DDC-1209
35      */
36     public function testCompositeIdentifierCanHaveCustomType()
37     {
38         $future1 = new DDC1209_1();
39         $this->_em->persist($future1);
40
41         $this->_em->flush();
42
43         $future2 = new DDC1209_2($future1);
44         $this->_em->persist($future2);
45
46         $this->_em->flush();
47     }
48 }
49
50 /**
51  * @Entity
52  */
53 class DDC1209_1
54 {
55     /**
56      * @Id @GeneratedValue @Column(type="integer")
57      */
58     private $id;
59
60     public function getId()
61     {
62         return $this->id;
63     }
64 }
65
66 /**
67  * @Entity
68  */
69 class DDC1209_2
70 {
71     /**
72      *  @Id
73      *  @ManyToOne(targetEntity="DDC1209_1")
74      *  @JoinColumn(referencedColumnName="id", nullable=false)
75      */
76     private $future1;
77     /**
78      *  @Id
79      *  @Column(type="datetime", nullable=false)
80      */
81     private $starting_datetime;
82     /**
83      *  @Id
84      *  @Column(type="datetime", nullable=false)
85      */
86     private $during_datetime;
87     /**
88      *  @Id
89      *  @Column(type="datetime", nullable=false)
90      */
91     private $ending_datetime;
92
93     public function __construct(DDC1209_1 $future1)
94     {
95         $this->future1 = $future1;
96         $this->starting_datetime = new DateTime2();
97         $this->during_datetime = new DateTime2();
98         $this->ending_datetime = new DateTime2();
99     }
100 }
101
102 /**
103  * @Entity
104  */
105 class DDC1209_3
106 {
107     /**
108      * @Id
109      * @Column(type="datetime", name="somedate")
110      */
111     private $date;
112
113     public function __construct()
114     {
115         $this->date = new DateTime2();
116     }
117 }
118
119 class DateTime2 extends \DateTime
120 {
121     public function __toString()
122     {
123         return $this->format('Y');
124     }
125 }