@@ -265,6 +265,63 @@ public function testCreateRow()
265265 $ tester ->drop ();
266266 }
267267
268+ public function testTypeCasting ()
269+ {
270+ $ mapper = $ this ->createMapper (arrays: true );
271+
272+ $ tester = $ mapper ->createSpace ('tester ' );
273+ $ tester ->addProperty ('id ' , 'unsigned ' );
274+ $ tester ->addProperty ('data ' , 'unsigned ' );
275+
276+ $ tester ->addIndex (['id ' ]);
277+
278+ $ testRow = $ mapper ->create ('tester ' , [
279+ 'id ' => "1 " ,
280+ 'data ' => "1 " ,
281+ ]);
282+
283+ $ testRow2 = $ mapper ->create ('tester ' , [
284+ 'id ' => "2 " ,
285+ 'data ' => true ,
286+ ]);
287+
288+ $ testRow3 = $ mapper ->create ('tester ' , [
289+ 'id ' => "3 " ,
290+ 'data ' => false ,
291+ ]);
292+
293+ // casting on create
294+ $ this ->assertSame ($ testRow ['id ' ], 1 );
295+ $ this ->assertNotSame ($ testRow ['id ' ], "1 " );
296+
297+ $ this ->assertSame ($ testRow ['data ' ], 1 );
298+ $ this ->assertNotSame ($ testRow ['data ' ], "1 " );
299+
300+ $ this ->assertSame ($ testRow2 ['data ' ], 1 );
301+ $ this ->assertNotSame ($ testRow ['data ' ], true );
302+
303+ $ this ->assertSame ($ testRow3 ['data ' ], 0 );
304+ $ this ->assertNotSame ($ testRow ['data ' ], false );
305+
306+ //casting on update
307+ $ mapper ->update ('tester ' , $ testRow , ['data ' => false ]);
308+ $ mapper ->update ('tester ' , $ testRow2 , ['data ' => "5 " ]);
309+ $ mapper ->update ('tester ' , $ testRow3 , ['data ' => true ]);
310+
311+ $ testRow = $ mapper ->findOne ('tester ' , ['id ' => 1 ]);
312+ $ testRow2 = $ mapper ->findOne ('tester ' , ['id ' => 2 ]);
313+ $ testRow3 = $ mapper ->findOne ('tester ' , ['id ' => 3 ]);
314+
315+ $ this ->assertSame ($ testRow ['data ' ], 0 );
316+ $ this ->assertNotSame ($ testRow ['data ' ], false );
317+
318+ $ this ->assertSame ($ testRow2 ['data ' ], 5 );
319+ $ this ->assertNotSame ($ testRow2 ['data ' ], "5 " );
320+
321+ $ this ->assertSame ($ testRow3 ['data ' ], 1 );
322+ $ this ->assertNotSame ($ testRow3 ['data ' ], true );
323+ }
324+
268325 public function testIndexCasting ()
269326 {
270327 $ mapper = $ this ->createMapper (arrays: true );
0 commit comments