コード例 #1
0
ファイル: ModelTest.php プロジェクト: blendsdk/blendengine
 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);
 }
コード例 #2
0
ファイル: Factory.php プロジェクト: blendsdk/blendengine
 /**
  * Updates an existing Model (record) in the database and updates
  * the Model with the data return from the database. If the current
  * state of the Model is already changed by another operation then this
  * method with throw a
  * @param Model $model
  * @throws InvalidConfigException
  */
 protected function updateModel(Model $model)
 {
     $stmtResult = new StatementResult();
     list($condition, $conditionParameters) = $this->createAndCondition($model->getInitial());
     $result = $this->database->update($this->relation, $model->getUpdates(), $condition, $conditionParameters, $stmtResult);
     if ($stmtResult->getAffectedRecords() === 1) {
         $this->syncModel($model, $result[0]);
     } else {
         throw new \LogicException("The update operation did not return exactly one record! " . "The Model must have been changed or deleted by another operation!");
     }
 }