@@ -34,7 +34,7 @@ protected function tearDown()
34
34
$ this ->dateTimeWithoutSeconds = null ;
35
35
}
36
36
37
- public static function assertEquals ($ expected , $ actual , $ message = '' , $ delta = 0 , $ maxDepth = 10 , $ canonicalize = FALSE , $ ignoreCase = FALSE )
37
+ public static function assertEquals ($ expected , $ actual , $ message = '' , $ delta = 0 , $ maxDepth = 10 , $ canonicalize = false , $ ignoreCase = false )
38
38
{
39
39
if ($ expected instanceof \DateTime && $ actual instanceof \DateTime) {
40
40
$ expected = $ expected ->format ('c ' );
@@ -44,54 +44,59 @@ public static function assertEquals($expected, $actual, $message = '', $delta =
44
44
parent ::assertEquals ($ expected , $ actual , $ message , $ delta , $ maxDepth , $ canonicalize , $ ignoreCase );
45
45
}
46
46
47
- public function testTransformShortDate ()
48
- {
49
- $ transformer = new DateTimeToLocalizedStringTransformer ('UTC ' , 'UTC ' , \IntlDateFormatter::SHORT );
50
- $ this ->assertEquals ('03.02.10 04:05 ' , $ transformer ->transform ($ this ->dateTime ));
51
- }
52
-
53
- public function testTransformMediumDate ()
54
- {
55
- $ transformer = new DateTimeToLocalizedStringTransformer ('UTC ' , 'UTC ' , \IntlDateFormatter::MEDIUM );
56
-
57
- $ this ->assertEquals ('03.02.2010 04:05 ' , $ transformer ->transform ($ this ->dateTime ));
58
- }
59
-
60
- public function testTransformLongDate ()
61
- {
62
- $ transformer = new DateTimeToLocalizedStringTransformer ('UTC ' , 'UTC ' , \IntlDateFormatter::LONG );
63
-
64
- $ this ->assertEquals ('03. Februar 2010 04:05 ' , $ transformer ->transform ($ this ->dateTime ));
65
- }
66
-
67
- public function testTransformFullDate ()
68
- {
69
- $ transformer = new DateTimeToLocalizedStringTransformer ('UTC ' , 'UTC ' , \IntlDateFormatter::FULL );
70
-
71
- $ this ->assertEquals ('Mittwoch, 03. Februar 2010 04:05 ' , $ transformer ->transform ($ this ->dateTime ));
47
+ public function dataProvider ()
48
+ {
49
+ return array (
50
+ array (\IntlDateFormatter::SHORT , null , null , '03.02.10 04:05 ' , '2010-02-03 04:05:00 UTC ' ),
51
+ array (\IntlDateFormatter::MEDIUM , null , null , '03.02.2010 04:05 ' , '2010-02-03 04:05:00 UTC ' ),
52
+ array (\IntlDateFormatter::LONG , null , null , '03. Februar 2010 04:05 ' , '2010-02-03 04:05:00 UTC ' ),
53
+ array (\IntlDateFormatter::FULL , null , null , 'Mittwoch, 03. Februar 2010 04:05 ' , '2010-02-03 04:05:00 UTC ' ),
54
+ array (\IntlDateFormatter::SHORT , \IntlDateFormatter::NONE , null , '03.02.10 ' , '2010-02-03 00:00:00 UTC ' ),
55
+ array (\IntlDateFormatter::MEDIUM , \IntlDateFormatter::NONE , null , '03.02.2010 ' , '2010-02-03 00:00:00 UTC ' ),
56
+ array (\IntlDateFormatter::LONG , \IntlDateFormatter::NONE , null , '03. Februar 2010 ' , '2010-02-03 00:00:00 UTC ' ),
57
+ array (\IntlDateFormatter::FULL , \IntlDateFormatter::NONE , null , 'Mittwoch, 03. Februar 2010 ' , '2010-02-03 00:00:00 UTC ' ),
58
+ array (null , \IntlDateFormatter::SHORT , null , '03.02.2010 04:05 ' , '2010-02-03 04:05:00 UTC ' ),
59
+ array (null , \IntlDateFormatter::MEDIUM , null , '03.02.2010 04:05:06 ' , '2010-02-03 04:05:06 UTC ' ),
60
+ array (null , \IntlDateFormatter::LONG , null ,
61
+ '03.02.2010 04:05:06 GMT ' . ($ this ->isLowerThanIcuVersion ('4.8 ' ) ? '+00:00 ' : '' ),
62
+ '2010-02-03 04:05:06 UTC ' ),
63
+ // see below for extra test case for time format FULL
64
+ array (\IntlDateFormatter::NONE , \IntlDateFormatter::SHORT , null , '04:05 ' , '1970-01-01 04:05:00 UTC ' ),
65
+ array (\IntlDateFormatter::NONE , \IntlDateFormatter::MEDIUM , null , '04:05:06 ' , '1970-01-01 04:05:06 UTC ' ),
66
+ array (\IntlDateFormatter::NONE , \IntlDateFormatter::LONG , null ,
67
+ '04:05:06 GMT ' . ($ this ->isLowerThanIcuVersion ('4.8 ' ) ? '+00:00 ' : '' ),
68
+ '1970-01-01 04:05:06 UTC ' ),
69
+ array (null , null , 'yyyy-MM-dd HH:mm:00 ' , '2010-02-03 04:05:00 ' , '2010-02-03 04:05:00 UTC ' ),
70
+ array (null , null , 'yyyy-MM-dd HH:mm ' , '2010-02-03 04:05 ' , '2010-02-03 04:05:00 UTC ' ),
71
+ array (null , null , 'yyyy-MM-dd HH ' , '2010-02-03 04 ' , '2010-02-03 04:00:00 UTC ' ),
72
+ array (null , null , 'yyyy-MM-dd ' , '2010-02-03 ' , '2010-02-03 00:00:00 UTC ' ),
73
+ array (null , null , 'yyyy-MM ' , '2010-02 ' , '2010-02-01 00:00:00 UTC ' ),
74
+ array (null , null , 'yyyy ' , '2010 ' , '2010-01-01 00:00:00 UTC ' ),
75
+ array (null , null , 'dd-MM-yyyy ' , '03-02-2010 ' , '2010-02-03 00:00:00 UTC ' ),
76
+ array (null , null , 'HH:mm:ss ' , '04:05:06 ' , '1970-01-01 04:05:06 UTC ' ),
77
+ array (null , null , 'HH:mm:00 ' , '04:05:00 ' , '1970-01-01 04:05:00 UTC ' ),
78
+ array (null , null , 'HH:mm ' , '04:05 ' , '1970-01-01 04:05:00 UTC ' ),
79
+ array (null , null , 'HH ' , '04 ' , '1970-01-01 04:00:00 UTC ' ),
80
+ );
72
81
}
73
82
74
- public function testTransformShortTime ()
75
- {
76
- $ transformer = new DateTimeToLocalizedStringTransformer ('UTC ' , 'UTC ' , null , \IntlDateFormatter::SHORT );
77
-
78
- $ this ->assertEquals ('03.02.2010 04:05 ' , $ transformer ->transform ($ this ->dateTime ));
79
- }
80
-
81
- public function testTransformMediumTime ()
82
- {
83
- $ transformer = new DateTimeToLocalizedStringTransformer ('UTC ' , 'UTC ' , null , \IntlDateFormatter::MEDIUM );
84
-
85
- $ this ->assertEquals ('03.02.2010 04:05:06 ' , $ transformer ->transform ($ this ->dateTime ));
86
- }
87
-
88
- public function testTransformLongTime ()
83
+ /**
84
+ * @dataProvider dataProvider
85
+ */
86
+ public function testTransform ($ dateFormat , $ timeFormat , $ pattern , $ output , $ input )
89
87
{
90
- $ transformer = new DateTimeToLocalizedStringTransformer ('UTC ' , 'UTC ' , null , \IntlDateFormatter::LONG );
88
+ $ transformer = new DateTimeToLocalizedStringTransformer (
89
+ 'UTC ' ,
90
+ 'UTC ' ,
91
+ $ dateFormat ,
92
+ $ timeFormat ,
93
+ \IntlDateFormatter::GREGORIAN ,
94
+ $ pattern
95
+ );
91
96
92
- $ expected = $ this -> isLowerThanIcuVersion ( ' 4.8 ' ) ? ' 03.02.2010 04:05:06 GMT+00:00 ' : ' 03.02.2010 04:05:06 GMT ' ;
97
+ $ input = new \ DateTime ( $ input ) ;
93
98
94
- $ this ->assertEquals ($ expected , $ transformer ->transform ($ this -> dateTime ));
99
+ $ this ->assertEquals ($ output , $ transformer ->transform ($ input ));
95
100
}
96
101
97
102
public function testTransformFullTime ()
@@ -143,7 +148,7 @@ public function testTransform_differentPatterns()
143
148
}
144
149
145
150
/**
146
- * @expectedException Symfony\Component\Form\Exception\UnexpectedTypeException
151
+ * @expectedException \ Symfony\Component\Form\Exception\UnexpectedTypeException
147
152
*/
148
153
public function testTransformRequiresValidDateTime ()
149
154
{
@@ -162,53 +167,23 @@ public function testTransformWrapsIntlErrors()
162
167
//$transformer->transform(1.5);
163
168
}
164
169
165
- public function testReverseTransformShortDate ()
166
- {
167
- $ transformer = new DateTimeToLocalizedStringTransformer ('UTC ' , 'UTC ' , \IntlDateFormatter::SHORT );
168
-
169
- $ this ->assertDateTimeEquals ($ this ->dateTimeWithoutSeconds , $ transformer ->reverseTransform ('03.02.10 04:05 ' ));
170
- }
171
-
172
- public function testReverseTransformMediumDate ()
173
- {
174
- $ transformer = new DateTimeToLocalizedStringTransformer ('UTC ' , 'UTC ' , \IntlDateFormatter::MEDIUM );
175
-
176
- $ this ->assertDateTimeEquals ($ this ->dateTimeWithoutSeconds , $ transformer ->reverseTransform ('03.02.2010 04:05 ' ));
177
- }
178
-
179
- public function testReverseTransformLongDate ()
180
- {
181
- $ transformer = new DateTimeToLocalizedStringTransformer ('UTC ' , 'UTC ' , \IntlDateFormatter::LONG );
182
-
183
- $ this ->assertDateTimeEquals ($ this ->dateTimeWithoutSeconds , $ transformer ->reverseTransform ('03. Februar 2010 04:05 ' ));
184
- }
185
-
186
- public function testReverseTransformFullDate ()
187
- {
188
- $ transformer = new DateTimeToLocalizedStringTransformer ('UTC ' , 'UTC ' , \IntlDateFormatter::FULL );
189
-
190
- $ this ->assertDateTimeEquals ($ this ->dateTimeWithoutSeconds , $ transformer ->reverseTransform ('Mittwoch, 03. Februar 2010 04:05 ' ));
191
- }
192
-
193
- public function testReverseTransformShortTime ()
194
- {
195
- $ transformer = new DateTimeToLocalizedStringTransformer ('UTC' , 'UTC ' , null , \IntlDateFormatter::SHORT );
196
-
197
- $ this ->assertDateTimeEquals ($ this ->dateTimeWithoutSeconds , $ transformer ->reverseTransform ('03.02.2010 04:05 ' ));
198
- }
199
-
200
- public function testReverseTransformMediumTime ()
170
+ /**
171
+ * @dataProvider dataProvider
172
+ */
173
+ public function testReverseTransform ($ dateFormat , $ timeFormat , $ pattern , $ input , $ output )
201
174
{
202
- $ transformer = new DateTimeToLocalizedStringTransformer ('UTC ' , 'UTC ' , null , \IntlDateFormatter::MEDIUM );
203
-
204
- $ this ->assertDateTimeEquals ($ this ->dateTime , $ transformer ->reverseTransform ('03.02.2010 04:05:06 ' ));
205
- }
175
+ $ transformer = new DateTimeToLocalizedStringTransformer (
176
+ 'UTC ' ,
177
+ 'UTC ' ,
178
+ $ dateFormat ,
179
+ $ timeFormat ,
180
+ \IntlDateFormatter::GREGORIAN ,
181
+ $ pattern
182
+ );
206
183
207
- public function testReverseTransformLongTime ()
208
- {
209
- $ transformer = new DateTimeToLocalizedStringTransformer ('UTC ' , 'UTC ' , null , \IntlDateFormatter::LONG );
184
+ $ output = new \DateTime ($ output );
210
185
211
- $ this ->assertDateTimeEquals ( $ this -> dateTime , $ transformer ->reverseTransform (' 03.02.2010 04:05:06 GMT+00:00 ' ));
186
+ $ this ->assertEquals ( $ output , $ transformer ->reverseTransform ($ input ));
212
187
}
213
188
214
189
public function testReverseTransformFullTime ()
@@ -256,7 +231,7 @@ public function testReverseTransform_empty()
256
231
}
257
232
258
233
/**
259
- * @expectedException Symfony\Component\Form\Exception\UnexpectedTypeException
234
+ * @expectedException \ Symfony\Component\Form\Exception\UnexpectedTypeException
260
235
*/
261
236
public function testReverseTransformRequiresString ()
262
237
{
@@ -265,7 +240,7 @@ public function testReverseTransformRequiresString()
265
240
}
266
241
267
242
/**
268
- * @expectedException Symfony\Component\Form\Exception\TransformationFailedException
243
+ * @expectedException \ Symfony\Component\Form\Exception\TransformationFailedException
269
244
*/
270
245
public function testReverseTransformWrapsIntlErrors ()
271
246
{
@@ -274,23 +249,23 @@ public function testReverseTransformWrapsIntlErrors()
274
249
}
275
250
276
251
/**
277
- * @expectedException Symfony\Component\Form\Exception\UnexpectedTypeException
252
+ * @expectedException \ Symfony\Component\Form\Exception\UnexpectedTypeException
278
253
*/
279
254
public function testValidateDateFormatOption ()
280
255
{
281
256
new DateTimeToLocalizedStringTransformer (null , null , 'foobar ' );
282
257
}
283
258
284
259
/**
285
- * @expectedException Symfony\Component\Form\Exception\UnexpectedTypeException
260
+ * @expectedException \ Symfony\Component\Form\Exception\UnexpectedTypeException
286
261
*/
287
262
public function testValidateTimeFormatOption ()
288
263
{
289
264
new DateTimeToLocalizedStringTransformer (null , null , null , 'foobar ' );
290
265
}
291
266
292
267
/**
293
- * @expectedException Symfony\Component\Form\Exception\TransformationFailedException
268
+ * @expectedException \ Symfony\Component\Form\Exception\TransformationFailedException
294
269
*/
295
270
public function testReverseTransformWithNonExistingDate ()
296
271
{
0 commit comments