@@ -84,4 +84,40 @@ public function testReturnsNullForUnknownCast(): void
8484 {
8585 self ::assertNull ((new CastTypeResolver ())->resolve ('mycustomhandler ' ));
8686 }
87+
88+ #[DataProvider('providePreservesNullCases ' )]
89+ public function testPreservesNull (string $ cast , bool $ expected ): void
90+ {
91+ self ::assertSame ($ expected , (new CastTypeResolver ())->preservesNull ($ cast ));
92+ }
93+
94+ /**
95+ * @return iterable<string, array{string, bool}>
96+ */
97+ public static function providePreservesNullCases (): iterable
98+ {
99+ yield 'datetime ' => ['datetime ' , true ];
100+
101+ yield 'json ' => ['json ' , true ];
102+
103+ yield 'json[array] ' => ['json[array] ' , true ];
104+
105+ yield 'json-array ' => ['json-array ' , true ];
106+
107+ yield 'nullable int ' => ['?int ' , true ];
108+
109+ yield 'int ' => ['int ' , false ];
110+
111+ yield 'string ' => ['string ' , false ];
112+
113+ yield 'csv ' => ['csv ' , false ];
114+
115+ yield 'object ' => ['object ' , false ];
116+
117+ yield 'timestamp ' => ['timestamp ' , false ];
118+
119+ yield 'uri ' => ['uri ' , false ];
120+
121+ yield 'enum with class ' => ['enum[CodeIgniter\Test\TestLogger] ' , false ];
122+ }
87123}
0 commit comments