/**
  * @covers Veles\Model\QueryBuilder::update
  * @covers Veles\Model\QueryBuilder::sanitize
  */
 public function testUpdate()
 {
     $group = UsrGroup::GUEST;
     $hash = md5('lalala');
     $user = new User();
     $user->id = 1;
     $user->email = '*****@*****.**';
     $user->hash = $hash;
     $user->group = $group;
     $user->last_login = '******';
     $adapter = $this->getMockBuilder('\\Veles\\DataBase\\Adapters\\PdoAdapter')->setMethods(['escape'])->getMock();
     $adapter->expects($this->exactly(3))->method('escape')->willReturn('\'escaped-string\'');
     Db::setAdapter($adapter);
     $expected = "\n\t\t\tUPDATE\n\t\t\t\t\"users\"\n\t\t\tSET\n\t\t\t\t\"email\" = 'escaped-string', \"hash\" = 'escaped-string', \"group\" = 16, \"last_login\" = 'escaped-string'\n\t\t\tWHERE\n\t\t\t\tid = 1\n\t\t";
     $actual = $this->object->update($user);
     $msg = 'QueryBuilder::update() returns wrong result!';
     $this->assertSame($expected, $actual, $msg);
 }
Esempio n. 2
0
 /**
  * Update data in database
  *
  * @return bool
  */
 protected function update()
 {
     $sql = $this->builder->update($this);
     return Db::query($sql);
 }