22
33namespace Tempest \Framework \Testing ;
44
5+ use Tempest \Database \PrimaryKey ;
56use Tempest \Reflection \PropertyReflector ;
67
78use function Tempest \Mapper \map ;
@@ -75,14 +76,14 @@ public function make()
7576 continue ;
7677 }
7778
78- if ($ property ->isNullable ()) {
79+ $ value = $ this ->generateValue ($ property );
80+
81+ if ($ value === null && $ property ->isNullable ()) {
7982 $ property ->setValue ($ model , null );
8083
8184 continue ;
8285 }
8386
84- $ value = $ this ->generateValue ($ property );
85-
8687 if ($ value === null ) {
8788 continue ;
8889 }
@@ -109,7 +110,23 @@ public function save()
109110
110111 private function generateValue (PropertyReflector $ property ): mixed
111112 {
112- return match ($ property ->getType ()->getName ()) {
113+ $ type = $ property ->getType ();
114+
115+ if ($ type ->matches (PrimaryKey::class)) {
116+ return null ;
117+ }
118+
119+ if ($ type ->isEnum ()) {
120+ $ cases = arr ($ type ->getName ()::cases ());
121+
122+ return $ cases ->random ();
123+ }
124+
125+ if ($ type ->isClass ()) {
126+ return new self ($ type ->getName ())->make ();
127+ }
128+
129+ return match ($ type ->getName ()) {
113130 'string ' => arr (['Lorem ' , 'Ipsum ' , 'Dolor ' , 'Sit ' , 'Amet ' ])->random (),
114131 'int ' => random_int (1 , 100 ),
115132 'float ' => random_int (100 , 1000 ) / 10 ,
0 commit comments