@@ -275,6 +275,65 @@ public function testUpdateObjectWithDataException(): void
275275 $ this ->model ->update ($ id , $ data );
276276 }
277277
278+ public function testUpdateArrayWithDataExceptionNoAllowedFields (): void
279+ {
280+ $ this ->createModel (EventModel::class);
281+
282+ $ data = [
283+ 'name ' => 'Foo ' ,
284+ 'email ' => 'foo@example.com ' ,
285+ 'country ' => 'US ' ,
286+ 'deleted ' => 0 ,
287+ ];
288+
289+ $ id = $ this ->model ->insert ($ data );
290+
291+ $ this ->expectException (DataException::class);
292+ $ this ->expectExceptionMessage ('There is no data to update. ' );
293+ $ this ->model ->update ($ id , ['thisKeyIsNotAllowed ' => 'Bar ' ]);
294+ }
295+
296+ public function testUpdateWithEntityNoAllowedFields (): void
297+ {
298+ $ this ->createModel (UserModel::class);
299+
300+ $ entity = new class extends Entity
301+ {
302+ protected $ id ;
303+ protected $ name ;
304+ protected $ email ;
305+ protected $ country ;
306+ protected $ deleted ;
307+ protected $ created_at ;
308+ protected $ updated_at ;
309+
310+ protected $ _options = [
311+ 'datamap ' => [],
312+ 'dates ' => [
313+ 'created_at ' ,
314+ 'updated_at ' ,
315+ 'deleted_at ' ,
316+ ],
317+ 'casts ' => [],
318+ ];
319+ };
320+
321+ $ entity ->id = 1 ;
322+ $ entity ->name = 'Jones Martin ' ;
323+ $ entity ->country = 'India ' ;
324+ $ entity ->deleted = 0 ;
325+
326+ $ id = $ this ->model ->insert ($ entity );
327+
328+ $ entity ->syncOriginal ();
329+
330+ $ entity ->fill (['thisKeyIsNotAllowed ' => 'Bar ' ]);
331+
332+ $ this ->expectException (DataException::class);
333+ $ this ->expectExceptionMessage ('There is no data to update. ' );
334+ $ this ->model ->update ($ id , $ entity );
335+ }
336+
278337 public function testUseAutoIncrementSetToFalseUpdate (): void
279338 {
280339 $ key = 'key ' ;
@@ -301,9 +360,9 @@ public function testUpdateWithSetAndEscape(): void
301360 $ this ->assertTrue ($ this ->model ->set ('country ' , '2+2 ' , false )->set ('email ' , '1+1 ' )->update (1 , $ userData ));
302361
303362 $ this ->seeInDatabase ('user ' , [
304- 'name ' => 'Scott ' ,
363+ 'name ' => 'Scott ' ,
305364 'country ' => '4 ' ,
306- 'email ' => '1+1 ' ,
365+ 'email ' => '1+1 ' ,
307366 ]);
308367 }
309368}
0 commit comments