Fixing tests for WPDO
This commit is contained in:
parent
2b63ba42ca
commit
2d029548f2
2 changed files with 25 additions and 4 deletions
11
src/WPDO.php
11
src/WPDO.php
|
|
@ -195,20 +195,23 @@ class WPDO {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//$final_fields=implode('`, `', $fields);
|
|
||||||
$final_fields=[];
|
$final_fields=[];
|
||||||
|
|
||||||
foreach($fields as $field) {
|
foreach($fields as $field) {
|
||||||
|
|
||||||
|
$final_fields[]='`'.$field.'`=?';
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$query='update '.$this->table->name.' SET ';
|
$str_fields=implode(' AND ', $final_fields);
|
||||||
|
|
||||||
|
$query='update '.$this->table->name.' SET '.$str_fields.' '.$where_sql;
|
||||||
//echo $query;
|
//echo $query;
|
||||||
|
$final_values=array_merge($values_update, $values);
|
||||||
|
|
||||||
$this->sth=$this->conn->prepare($query);
|
$this->sth=$this->conn->prepare($query);
|
||||||
|
|
||||||
return $this->sth->execute($values);
|
return $this->sth->execute($final_values);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -78,6 +78,24 @@ final class WPDOTest extends TestCase {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @depends testInsert
|
||||||
|
*/
|
||||||
|
|
||||||
|
public function testUpdate() {
|
||||||
|
|
||||||
|
global $pdo;
|
||||||
|
|
||||||
|
$this->assertTrue($pdo->update(['name'], ['first_updated'], 'WHERE name=?', ['first']));
|
||||||
|
|
||||||
|
$this->assertTrue($pdo->select(['name'], 'WHERE name=? AND type=?', ['first_updated', 1]));
|
||||||
|
|
||||||
|
$arr_result=$pdo->sth->fetchAll();
|
||||||
|
|
||||||
|
$this->assertEquals([['name' => 'first_updated', 0 => 'first_updated']], $arr_result);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @depends testCreateTable
|
* @depends testCreateTable
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue