1212use DateTime ;
1313use Framework \Date \Date ;
1414use Framework \HTTP \URL ;
15+ use Framework \MVC \Entity ;
1516use PHPUnit \Framework \TestCase ;
1617use stdClass ;
1718
@@ -166,9 +167,10 @@ public function testToModel() : void
166167 'date ' => '2021-09-15 15:47:08 ' ,
167168 'url ' => 'https://foo.com/ ' ,
168169 'mixed ' => null ,
170+ /* Properties not set:
169171 'id' => null,
170172 'data' => null,
171- 'createdAt ' => null ,
173+ 'createdAt' => null,*/
172174 'updatedAt ' => null ,
173175 ], $ this ->entity ->toModel ());
174176 }
@@ -190,7 +192,37 @@ public function testToString() : void
190192 $ values = \json_decode ($ json , true );
191193 self ::assertArrayHasKey ('array ' , $ values );
192194 self ::assertIsArray ($ values ['array ' ]);
193- self ::assertArrayHasKey ('id ' , $ values );
194- self ::assertNull ($ values ['id ' ]);
195+ self ::assertArrayNotHasKey ('id ' , $ values );
196+ }
197+
198+ public function testGetObjectVars () : void
199+ {
200+ $ data = [
201+ 'id2 ' => 1 ,
202+ 'id5 ' => null ,
203+ ];
204+ $ user = new class ($ data ) extends Entity {
205+ protected int $ id ; // not set
206+ protected int $ id2 ; // set with 1
207+ protected ?int $ id3 ; // nullable not set
208+ protected ?int $ id4 = null ; // nullable set with default value (null)
209+ protected ?int $ id5 ; // nullable set with null
210+ protected ?int $ id6 = 5 ; // nullable set with default value (5)
211+ // @phpstan-ignore-next-line
212+ protected $ id7 ; // property without type is null
213+ protected string | int $ id8 ; // not set
214+
215+ public function getObjectVars () : array
216+ {
217+ return parent ::getObjectVars ();
218+ }
219+ };
220+ self ::assertSame ([
221+ 'id2 ' => 1 ,
222+ 'id4 ' => null ,
223+ 'id5 ' => null ,
224+ 'id6 ' => 5 ,
225+ 'id7 ' => null ,
226+ ], $ user ->getObjectVars ());
195227 }
196228}
0 commit comments