@@ -19,10 +19,11 @@ public function testEncode(): void
1919 );
2020 }
2121
22- public static function providesDecodeCases (): array
22+ public static function providesValidDecodeCases (): array
2323 {
2424 return [
2525 // UTC
26+ ['2018-04-05T17:31:00Z ' , '2018-04-05t17:31:00Z ' ],
2627 ['2018-04-05T17:31:00Z ' , '2018-04-05T17:31:00Z ' ],
2728 ['1985-04-12T23:20:50.100000Z ' , '1985-04-12T23:20:50.1Z ' ],
2829 ['1985-04-12T23:20:50.100000Z ' , '1985-04-12T23:20:50.10Z ' ],
@@ -41,6 +42,7 @@ public static function providesDecodeCases(): array
4142 ['1985-04-12T23:20:50.123456Z ' , '1985-04-12T23:20:50.123456789Z ' ],
4243
4344 // +01:00
45+ ['2018-04-05T16:31:00Z ' , '2018-04-05t17:31:00+01:00 ' ],
4446 ['2018-04-05T16:31:00Z ' , '2018-04-05T17:31:00+01:00 ' ],
4547 ['1985-04-12T22:20:50.100000Z ' , '1985-04-12T23:20:50.1+01:00 ' ],
4648 ['1985-04-12T22:20:50.100000Z ' , '1985-04-12T23:20:50.10+01:00 ' ],
@@ -57,12 +59,17 @@ public static function providesDecodeCases(): array
5759 ['1985-04-12T22:20:50.123456Z ' , '1985-04-12T23:20:50.1234567+01:00 ' ],
5860 ['1985-04-12T22:20:50.123456Z ' , '1985-04-12T23:20:50.12345678+01:00 ' ],
5961 ['1985-04-12T22:20:50.123456Z ' , '1985-04-12T23:20:50.123456789+01:00 ' ],
60- ['1985-04-12T22:20:50.123456Z ' , '1985-04-12T23:20:50.1234567890+01:00 ' ],
62+
63+ // -05:00
64+ ['2018-04-05T22:31:00Z ' , '2018-04-05t17:31:00-05:00 ' ],
65+ ['2018-04-05T22:31:00Z ' , '2018-04-05T17:31:00-05:00 ' ],
66+ ['1985-04-13T04:20:50.123456Z ' , '1985-04-12T23:20:50.123456-05:00 ' ],
67+ ['1985-04-13T04:20:50.123456Z ' , '1985-04-12T23:20:50.123456789-05:00 ' ],
6168 ];
6269 }
6370
6471 /**
65- * @dataProvider providesDecodeCases
72+ * @dataProvider providesValidDecodeCases
6673 */
6774 public function testDecode (string $ expected , string $ input ): void
6875 {
@@ -88,14 +95,30 @@ public function testDecodeEmpty(): void
8895 );
8996 }
9097
91- public function testDecodeInvalidTime (): void
98+ public static function providesInvalidDecodeCases (): array
99+ {
100+ return [
101+ ['' ],
102+ ['123 ' ],
103+ ['2018asdsdsafd ' ],
104+ ['2018-04-05 ' ],
105+ ['2018-04-05 17:31:00Z ' ],
106+ ['2018-04-05T17:31:00.Z ' ],
107+ ['2018-04-05T17:31:00ZZ ' ],
108+ ];
109+ }
110+
111+ /**
112+ * @dataProvider providesInvalidDecodeCases
113+ */
114+ public function testDecodeInvalidTime (string $ input ): void
92115 {
93116 $ this ->expectException (ValueError::class);
94117
95118 $ this ->expectExceptionMessage (
96119 'CloudEvents \\Utilities \\TimeFormatter::decode(): Argument #1 ($time) is not a valid RFC3339 timestamp '
97120 );
98121
99- TimeFormatter::decode (' 2018asdsdsafd ' );
122+ TimeFormatter::decode ($ input );
100123 }
101124}
0 commit comments