@@ -368,6 +368,19 @@ public function testCastArrayByArraySerialize()
368368 $ this ->assertEquals (['foo ' => 'bar ' ], $ entity ->seventh );
369369 }
370370
371+
372+ //--------------------------------------------------------------------
373+
374+ public function testCastNullable ()
375+ {
376+ $ entity = $ this ->getCastNullableEntity ();
377+
378+ $ this ->assertSame (null , $ entity ->string_null );
379+ $ this ->assertSame ('' , $ entity ->string_empty );
380+ $ this ->assertSame (null , $ entity ->integer_null );
381+ $ this ->assertSame (0 , $ entity ->integer_0 );
382+ }
383+
371384 //--------------------------------------------------------------------
372385
373386 public function testCastAsJSON ()
@@ -564,5 +577,31 @@ public function setSeventh($seventh)
564577 }
565578 };
566579 }
580+
581+
582+
583+ protected function getCastNullableEntity ()
584+ {
585+ return new class extends Entity
586+ {
587+
588+ protected $ string_null = null ;
589+ protected $ string_empty = null ;
590+ protected $ integer_null = null ;
591+ protected $ integer_0 = 0 ;
592+ // 'bar' is db column, 'foo' is internal representation
593+ protected $ _options = [
594+ 'casts ' => [
595+ 'string_null ' => '?string ' ,
596+ 'string_empty ' => 'string ' ,
597+ 'integner_null ' => '?integer ' ,
598+ 'integer_0 ' => 'integer '
599+ ],
600+ 'dates ' => [],
601+ 'datamap ' => [],
602+ ];
603+ };
604+ }
605+
567606
568607}
0 commit comments