From 2d029548f2d99095564d74b22117c1684b6a2430 Mon Sep 17 00:00:00 2001 From: absurdo Date: Sat, 28 Oct 2023 12:52:05 +0200 Subject: [PATCH] Fixing tests for WPDO --- src/WPDO.php | 11 +++++++---- tests/WPDOTest.php | 18 ++++++++++++++++++ 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/src/WPDO.php b/src/WPDO.php index 15bb768..16aa407 100644 --- a/src/WPDO.php +++ b/src/WPDO.php @@ -195,20 +195,23 @@ class WPDO { } - //$final_fields=implode('`, `', $fields); $final_fields=[]; 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; + $final_values=array_merge($values_update, $values); + $this->sth=$this->conn->prepare($query); - return $this->sth->execute($values); + return $this->sth->execute($final_values); } diff --git a/tests/WPDOTest.php b/tests/WPDOTest.php index 9d11d26..c1c9b67 100644 --- a/tests/WPDOTest.php +++ b/tests/WPDOTest.php @@ -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 */