@@ -78,6 +78,82 @@ public function normalizeUsingTimeZonePassedInContextProvider()
7878 yield array ('2016-12-01T09:00:00+09:00 ' , new \DateTimeImmutable ('2016/12/01 ' , new \DateTimeZone ('UTC ' )), new \DateTimeZone ('Japan ' ));
7979 }
8080
81+ /**
82+ * @dataProvider normalizeUsingTimeZonePassedInContextAndExpectedFormatWithMicrosecondsProvider
83+ */
84+ public function testNormalizeUsingTimeZonePassedInContextAndFormattedWithMicroseconds ($ expected , $ expectedFormat , $ input , $ timezone )
85+ {
86+ $ this ->assertSame (
87+ $ expected ,
88+ $ this ->normalizer ->normalize (
89+ $ input ,
90+ null ,
91+ array (
92+ DateTimeNormalizer::TIMEZONE_KEY => $ timezone ,
93+ DateTimeNormalizer::FORMAT_KEY => $ expectedFormat ,
94+ )
95+ )
96+ );
97+ }
98+
99+ public function normalizeUsingTimeZonePassedInContextAndExpectedFormatWithMicrosecondsProvider ()
100+ {
101+ yield array (
102+ '2018-12-01T18:03:06.067634 ' ,
103+ 'Y-m-d\TH:i:s.u ' ,
104+ \DateTime::createFromFormat (
105+ 'Y-m-d\TH:i:s.u ' ,
106+ '2018-12-01T18:03:06.067634 ' ,
107+ new \DateTimeZone ('UTC ' )
108+ ),
109+ null ,
110+ );
111+
112+ yield array (
113+ '2018-12-01T18:03:06.067634 ' ,
114+ 'Y-m-d\TH:i:s.u ' ,
115+ \DateTime::createFromFormat (
116+ 'Y-m-d\TH:i:s.u ' ,
117+ '2018-12-01T18:03:06.067634 ' ,
118+ new \DateTimeZone ('UTC ' )
119+ ),
120+ new \DateTimeZone ('UTC ' ),
121+ );
122+
123+ yield array (
124+ '2018-12-01T19:03:06.067634+01:00 ' ,
125+ 'Y-m-d\TH:i:s.uP ' ,
126+ \DateTimeImmutable::createFromFormat (
127+ 'Y-m-d\TH:i:s.u ' ,
128+ '2018-12-01T18:03:06.067634 ' ,
129+ new \DateTimeZone ('UTC ' )
130+ ),
131+ new \DateTimeZone ('Europe/Rome ' ),
132+ );
133+
134+ yield array (
135+ '2018-12-01T20:03:06.067634+02:00 ' ,
136+ 'Y-m-d\TH:i:s.uP ' ,
137+ \DateTime::createFromFormat (
138+ 'Y-m-d\TH:i:s.u ' ,
139+ '2018-12-01T18:03:06.067634 ' ,
140+ new \DateTimeZone ('UTC ' )
141+ ),
142+ new \DateTimeZone ('Europe/Kiev ' ),
143+ );
144+
145+ yield array (
146+ '2018-12-01T21:03:06.067634 ' ,
147+ 'Y-m-d\TH:i:s.u ' ,
148+ \DateTime::createFromFormat (
149+ 'Y-m-d\TH:i:s.u ' ,
150+ '2018-12-01T18:03:06.067634 ' ,
151+ new \DateTimeZone ('UTC ' )
152+ ),
153+ new \DateTimeZone ('Europe/Moscow ' ),
154+ );
155+ }
156+
81157 /**
82158 * @expectedException \Symfony\Component\Serializer\Exception\InvalidArgumentException
83159 * @expectedExceptionMessage The object must implement the "\DateTimeInterface".
0 commit comments