@@ -42,4 +42,44 @@ public function testCasts()
42
42
$ this ->assertEquals (Address::class, get_class ($ oaddr ));
43
43
$ this ->assertEquals ($ addr , $ oaddr ->toJson ());
44
44
}
45
+
46
+ public function testNullCase ()
47
+ {
48
+ (new FirstModel ([
49
+ 'name ' => 'jane ' ,
50
+ 'castable_address ' => null ,
51
+ 'address ' => null ,
52
+ ]))->save ();
53
+ $ m = FirstModel::query ()->first ();
54
+ $ this ->assertTrue (null === $ m ->getAttributes ()['castable_address ' ]);
55
+ $ this ->assertTrue (null === $ m ->castable_address );
56
+ $ this ->assertTrue (null === $ m ->getAttributes ()['address ' ]);
57
+ $ this ->assertTrue (null === $ m ->address );
58
+ }
59
+
60
+ public function testNotSet ()
61
+ {
62
+ (new FirstModel ([
63
+ 'name ' => 'jane ' ,
64
+ ]))->save ();
65
+ $ m = FirstModel::query ()->first ();
66
+ $ this ->assertTrue (null === $ m ->getAttributes ()['castable_address ' ]);
67
+ $ this ->assertTrue (null === $ m ->castable_address );
68
+ $ this ->assertTrue (null === $ m ->getAttributes ()['address ' ]);
69
+ $ this ->assertTrue (null === $ m ->address );
70
+ }
71
+
72
+ public function testEmptyString ()
73
+ {
74
+ FirstModel::query ()->insert ([
75
+ 'name ' => 'jane ' ,
76
+ 'castable_address ' => '' ,
77
+ 'address ' => '' ,
78
+ ]);
79
+ $ m = FirstModel::query ()->first ();
80
+ $ this ->assertTrue ('' === $ m ->getAttributes ()['castable_address ' ]);
81
+ $ this ->assertTrue ('' === $ m ->castable_address );
82
+ $ this ->assertTrue ('' === $ m ->getAttributes ()['address ' ]);
83
+ $ this ->assertTrue ('' === $ m ->address );
84
+ }
45
85
}
0 commit comments