@@ -28,7 +28,7 @@ protected function setUp()
28
28
$ this ->normalizer = new DateTimeNormalizer ();
29
29
}
30
30
31
- public function testSupportNormalization ()
31
+ public function testSupportsNormalization ()
32
32
{
33
33
$ this ->assertTrue ($ this ->normalizer ->supportsNormalization (new \DateTime ()));
34
34
$ this ->assertTrue ($ this ->normalizer ->supportsNormalization (new \DateTimeImmutable ()));
@@ -41,12 +41,12 @@ public function testNormalize()
41
41
$ this ->assertEquals ('2016-01-01T00:00:00+00:00 ' , $ this ->normalizer ->normalize (new \DateTimeImmutable ('2016/01/01 ' , new \DateTimeZone ('UTC ' ))));
42
42
}
43
43
44
- public function testContextFormat ()
44
+ public function testNormalizeUsingFormatPassedInContext ()
45
45
{
46
46
$ this ->assertEquals ('2016 ' , $ this ->normalizer ->normalize (new \DateTime ('2016/01/01 ' ), null , array (DateTimeNormalizer::FORMAT_KEY => 'Y ' )));
47
47
}
48
48
49
- public function testConstructorFormat ()
49
+ public function testNormalizeUsingFormatPassedInConstructor ()
50
50
{
51
51
$ this ->assertEquals ('16 ' , (new DateTimeNormalizer ('y ' ))->normalize (new \DateTime ('2016/01/01 ' , new \DateTimeZone ('UTC ' ))));
52
52
}
@@ -55,12 +55,12 @@ public function testConstructorFormat()
55
55
* @expectedException \Symfony\Component\Serializer\Exception\InvalidArgumentException
56
56
* @expectedExceptionMessage The object must implement the "\DateTimeInterface".
57
57
*/
58
- public function testInvalidDataThrowException ()
58
+ public function testNormalizeInvalidObjectThrowsException ()
59
59
{
60
60
$ this ->normalizer ->normalize (new \stdClass ());
61
61
}
62
62
63
- public function testSupportDenormalization ()
63
+ public function testSupportsDenormalization ()
64
64
{
65
65
$ this ->assertTrue ($ this ->normalizer ->supportsDenormalization ('2016-01-01T00:00:00+00:00 ' , \DateTimeInterface::class));
66
66
$ this ->assertTrue ($ this ->normalizer ->supportsDenormalization ('2016-01-01T00:00:00+00:00 ' , \DateTime::class));
@@ -75,11 +75,19 @@ public function testDenormalize()
75
75
$ this ->assertEquals (new \DateTime ('2016/01/01 ' , new \DateTimeZone ('UTC ' )), $ this ->normalizer ->denormalize ('2016-01-01T00:00:00+00:00 ' , \DateTime::class));
76
76
}
77
77
78
+ public function testDenormalizeUsingFormatPassedInContext ()
79
+ {
80
+ $ this ->assertEquals (new \DateTimeImmutable ('2016/01/01 ' , new \DateTimeZone ('UTC ' )), $ this ->normalizer ->denormalize ('2016.01.01 ' , \DateTimeInterface::class, null , array (DateTimeNormalizer::FORMAT_KEY => 'Y.m.d| ' )));
81
+ $ this ->assertEquals (new \DateTimeImmutable ('2016/01/01 ' , new \DateTimeZone ('UTC ' )), $ this ->normalizer ->denormalize ('2016.01.01 ' , \DateTimeImmutable::class, null , array (DateTimeNormalizer::FORMAT_KEY => 'Y.m.d| ' )));
82
+ $ this ->assertEquals (new \DateTime ('2016/01/01 ' , new \DateTimeZone ('UTC ' )), $ this ->normalizer ->denormalize ('2016.01.01 ' , \DateTime::class, null , array (DateTimeNormalizer::FORMAT_KEY => 'Y.m.d| ' )));
83
+ }
84
+
78
85
/**
79
86
* @expectedException \Symfony\Component\Serializer\Exception\UnexpectedValueException
80
87
*/
81
- public function testInvalidDateThrowException ()
88
+ public function testDenormalizeInvalidDataThrowsException ()
82
89
{
83
90
$ this ->normalizer ->denormalize ('invalid date ' , \DateTimeInterface::class);
91
+ $ this ->normalizer ->denormalize ('2016-01-01T00:00:00+00:00 ' , \DateTimeInterface::class, null , array (DateTimeNormalizer::FORMAT_KEY => 'Y-m-d| ' ));
84
92
}
85
93
}
0 commit comments