示例#1
0
 public function testHydrate()
 {
     $test = new TestModel(['id' => 1, 'first_name' => 'john', 'last_name' => 'smith', 'age' => 29, 'secret' => 'foobar'], true);
     // test construct / hydration
     $this->assertEquals(1, $test->id);
     $this->assertEquals('john', $test->first_name);
     $this->assertEquals('smith', $test->last_name);
     $this->assertEquals(29, $test->age);
     $this->assertEquals('foobar', $test->secret);
     $this->assertFalse($test->isNew());
     // test revert
     $test->age = 34;
     $this->assertEquals(34, $test->age);
     $this->assertEquals(29, $test->revert()->age);
     // test save
     $test->age = 34;
     $this->assertEquals(34, $test->age);
     $test->save();
     $this->assertEquals(34, $test->revert()->age);
     // test sync
     $this->assertEquals(['id' => 1, 'first_name' => 'john', 'last_name' => 'smith', 'age' => 27, 'secret' => 'foobar2'], $test->sync()->toArray());
     // test not fillable column
     $test->id = 20;
     $this->assertEquals(1, $test->id);
     // test delete
     $this->assertEquals(['id' => null, 'first_name' => null, 'last_name' => null, 'age' => null, 'secret' => null], $test->delete()->toArray());
 }