public function testSanity() { $m = new Model(); $this->assertTrue($m->isNew()); $m2 = new Model(['firstname' => 'Johny', 'lastname' => 'Bravo', 'age' => 40, 'salary' => 500]); $this->assertFalse($m2->isNew()); $m2->setValue('firstname', 'Peter'); $this->assertFalse($m2->isNew()); $this->assertEquals('Peter', $m2->getValue('firstname')); $this->assertEquals('Bravo', $m2->getValue('lastname')); $updates = array_keys($m2->getUpdates()); $diff = array_diff(['firstname'], $updates); $this->assertCount(0, $diff); $m2->setValue('age', 42); $updates = array_keys($m2->getUpdates()); $diff = array_diff(['firstname', 'age'], $updates); $this->assertCount(0, $diff); $data = array_values($m2->getData()); $diff = array_diff(['Peter', 'Bravo', 42, 500], $data); $this->assertCount(0, $diff); $initial = array_values($m2->getInitial()); $diff = array_diff(['Johny', 'Bravo', 40, 500], $initial); $this->assertCount(0, $diff); }
/** * Synchronizes model data with values returned from the Database * @param Model $model * @param array $record * @return model */ protected function syncModel(Model $model, $record) { $model->sync($this->convertFromRecord($record)); }