@@ -38,7 +38,7 @@ protected function getSerializer()
3838 *
3939 * @return string JSON with image_info data
4040 */
41- protected function getImageInfoJson (array $ additionalData = [])
41+ protected function getImageInfoJson (array $ additionalData = []): string
4242 {
4343 $ data = \json_decode (\file_get_contents (\dirname (__DIR__ ) . '/_data/file-info.json ' ), true );
4444 $ imageInfo = $ data ['image_info ' ];
@@ -49,7 +49,7 @@ protected function getImageInfoJson(array $additionalData = [])
4949 return \json_encode ($ imageInfo );
5050 }
5151
52- public function testDenormalizeImageInfo ()
52+ public function testDenormalizeImageInfo (): void
5353 {
5454 $ serializer = $ this ->getSerializer ();
5555
@@ -83,20 +83,44 @@ public function testDenormalizeImageInfo()
8383 self ::assertEquals ([144 , 144 ], $ object ->getDpi ());
8484 }
8585
86- public function testNotSerializableClass ()
86+ public function testNotSerializableClass (): void
8787 {
8888 $ this ->expectException (SerializerException::class);
89-
90- $ message = \sprintf ('Class \'%s \' must implements the \'%s \' interface ' , \DateTimeInterface::class, SerializableInterface::class);
9189 $ this ->getSerializer ()->deserialize (\json_encode (\date_create ()), \DateTime::class);
92- $ this ->expectExceptionMessageRegExp ($ message );
9390 }
9491
95- public function testUnableToDecode ()
92+ public function testUnableToDecode (): void
9693 {
9794 $ this ->expectException (ConversionException::class);
98-
9995 $ this ->getSerializer ()->deserialize (\date_create ()->format (DATE_ATOM ));
100- $ this ->expectExceptionMessageRegExp ('Unable to decode given value. Error ' );
96+ }
97+
98+ public function provideDateInDifferentFormats (): array
99+ {
100+ return [
101+ 'Y-m-d\TH:i:s.u\Z ' => ['2018-11-26T12:49:09.945335Z ' , null ],
102+ 'Y-m-d\TH:i:s\Z ' => ['2018-11-26T12:49:09Z ' , null ],
103+ 'Y-m-d\TH:i:s ' => ['2018-11-26T12:49:09 ' , null ],
104+ 'Invalid ' => ['26.11.2021 ' , ConversionException::class],
105+ ];
106+ }
107+
108+ /**
109+ * @dataProvider provideDateInDifferentFormats
110+ */
111+ public function testVariousDateFormats (string $ date , string $ exception = null ): void
112+ {
113+ $ serializer = $ this ->getSerializer ();
114+ $ denormalizeDate = (new \ReflectionObject ($ serializer ))->getMethod ('denormalizeDate ' );
115+ $ denormalizeDate ->setAccessible (true );
116+
117+ if ($ exception !== null ) {
118+ $ this ->expectException ($ exception );
119+ }
120+
121+ $ result = $ denormalizeDate ->invokeArgs ($ serializer , [$ date ]);
122+ if ($ exception === null ) {
123+ self ::assertInstanceOf (\DateTimeInterface::class, $ result );
124+ }
101125 }
102126}
0 commit comments