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