Example #1
0
 public function testMassAssignmentNormal()
 {
     $this->specify("Models can't properly assign properties", function () {
         $robot = new Robots();
         $success = $robot->save(["type" => "mechanical", "year" => 2018]);
         expect($success)->false();
         expect($robot->type)->equals("mechanical");
         expect($robot->year)->equals(2018);
         $robot = new Robots();
         $robot->assign(["type" => "mechanical", "year" => 2018]);
         expect($robot->type)->equals("mechanical");
         expect($robot->year)->equals(2018);
         // not assigns nonexistent fields
         $robot = new Robots();
         $robot->assign(["field1" => "mechanical", "field2" => 2018]);
         expect(empty($robot->field1))->true();
         expect(empty($robot->field2))->true();
         // white list
         $robot = new Robots();
         $robot->assign(["type" => "mechanical", "year" => 2018], null, ["type"]);
         expect($robot->type)->equals("mechanical");
         expect(empty($robot->year))->true();
         // white list
         $robot = new Robots();
         $robot->assign(["typeFromClient" => "mechanical", "yearFromClient" => 2018], ["typeFromClient" => "type", "yearFromClient" => "year"], ["type"]);
         expect($robot->type)->equals("mechanical");
         expect(empty($robot->year))->true();
     });
 }