Ejemplo n.º 1
0
 /**
  * Fill model instance with data from mysqli_result
  *
  * @param TipyModel $instance
  * @param mysqli_result
  * @return TipyModel
  */
 protected static function instanceFromResult($instance, $result)
 {
     foreach ($instance->reflections as $field => $attr) {
         if (array_key_exists($field, $result) && $result[$field] !== null) {
             $instance->data[$attr] = $instance->typeCast($field, $result[$field], $instance);
         } else {
             $instance->data[$attr] = null;
         }
     }
     return $instance;
 }
Ejemplo n.º 2
0
 public function testTransactions()
 {
     $this->createUsersWithFriends(10);
     $this->assertEqual(User::count(), 10);
     TipyModel::transaction(function () {
         $this->createUsersWithFriends(10);
         $user = User::findFirst();
         $user->lockForUpdate();
         $this->assertEqual(User::count(), 20);
         $this->assertEqual(Friend::count(), 90);
         TipyModel::rollback();
     });
     $this->assertEqual(User::count(), 10);
     $this->assertEqual(Friend::count(), 45);
     TipyModel::transaction(function () {
         $this->createUsersWithFriends(10);
         $this->assertEqual(User::count(), 20);
         $this->assertEqual(Friend::count(), 90);
     });
     $this->assertEqual(User::count(), 20);
     $this->assertEqual(Friend::count(), 90);
 }
Ejemplo n.º 3
0
 public function testNull()
 {
     TipyModel::transaction(function () {
         $profile = Profile::create(['userId' => 1, 'sign' => null]);
         $this->assertNull($profile->sign);
         $profile->sign = 'sign';
         $profile->save();
         $this->assertNotNull($profile->sign);
         $profile->sign = null;
         $profile->save();
         $this->assertNull($profile->sign);
         TipyModel::rollback();
     });
 }