From fedd4847908fd1523befe85306c7b8970e7e4307 Mon Sep 17 00:00:00 2001 From: Dimitri BOUTEILLE Date: Sun, 13 Oct 2024 16:34:09 +0200 Subject: [PATCH 01/15] Fix transaction execute commit after success --- src/Orm/Database.php | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/Orm/Database.php b/src/Orm/Database.php index 451c97df..c14a8e87 100644 --- a/src/Orm/Database.php +++ b/src/Orm/Database.php @@ -220,7 +220,8 @@ public function affectingStatement($query, $bindings = []): int public function unprepared($query): bool { return $this->run($query, [], function (string $query) { - return $this->db->query($query); + $result = $this->db->query($query); + return $this->lastRequestHasError() ? $result : true; }); } @@ -250,10 +251,16 @@ public function transaction(\Closure $callback, $attempts = 1) { $this->beginTransaction(); try { + + // We'll simply execute the given callback within a try / catch block and if we + // catch any exception we can rollback this transaction so that none of this + // gets actually persisted to a database or stored in a permanent fashion. $data = $callback(); $this->commit(); return $data; } catch (\Exception $e) { + + // If we catch an exception we'll rollback this transaction $this->rollBack(); throw $e; } From 9457ac0a98cbe49d4c919762bd25f375530bc759 Mon Sep 17 00:00:00 2001 From: Dimitri BOUTEILLE Date: Sun, 13 Oct 2024 21:52:09 +0200 Subject: [PATCH 02/15] Add DatabaseTransactionTest --- .../WordPress/Orm/DatabaseTransactionTest.php | 78 +++++++++++++++++++ 1 file changed, 78 insertions(+) create mode 100644 tests/WordPress/Orm/DatabaseTransactionTest.php diff --git a/tests/WordPress/Orm/DatabaseTransactionTest.php b/tests/WordPress/Orm/DatabaseTransactionTest.php new file mode 100644 index 00000000..7d0dff5e --- /dev/null +++ b/tests/WordPress/Orm/DatabaseTransactionTest.php @@ -0,0 +1,78 @@ + + */ + +namespace Dbout\WpOrm\Tests\WordPress\Orm; + +use Dbout\WpOrm\Orm\AbstractModel; +use Dbout\WpOrm\Orm\Database; +use Dbout\WpOrm\Tests\WordPress\TestCase; + +class DatabaseTransactionTest extends TestCase +{ + private static string $tableName = ''; + private static AbstractModel $model; + + + /** + * @return void + */ + public static function setUpBeforeClass(): void + { + global $wpdb; + + $tableName = $wpdb->prefix . 'document'; + self::$tableName = $tableName; + $sql = "CREATE TABLE $tableName ( + id INT NOT NULL AUTO_INCREMENT, + name varchar(100) NOT NULL, + url varchar(55) DEFAULT '' NOT NULL + PRIMARY KEY (id) + );"; + + require_once ABSPATH . 'wp-admin/includes/upgrade.php'; + dbDelta($sql); + + self::$model = new class () extends AbstractModel { + protected $primaryKey = 'id'; + public $timestamps = false; + protected $table = 'document'; + }; + + define('SAVEQUERIES', true); + } + + /** + * @return void + */ + public function setUp(): void + { + self::$model::truncate(); + } + + /** + * @throws \Throwable + * @return void + * @covers Database::transaction + */ + public function testTransactionSuccess(): void + { + Database::getInstance()->transaction(function () { + Database::getInstance()->insert(self::$tableName, [ + 'name' => 'Invoice #15', + 'url' => 'invoice-15', + ]); + Database::getInstance()->insert(self::$tableName, [ + 'name' => 'Invoice #10', + 'url' => 'invoice-10', + ]); + }); + + global $wpdb; + var_dump($wpdb->queries); + } +} From 2f049c12026fe10c7fd4eb22f314e4f6b8ee1bb1 Mon Sep 17 00:00:00 2001 From: Dimitri BOUTEILLE Date: Sun, 13 Oct 2024 22:07:29 +0200 Subject: [PATCH 03/15] WIP DatabaseTransactionTest --- .../WordPress/Orm/DatabaseTransactionTest.php | 39 +++++++++---------- 1 file changed, 18 insertions(+), 21 deletions(-) diff --git a/tests/WordPress/Orm/DatabaseTransactionTest.php b/tests/WordPress/Orm/DatabaseTransactionTest.php index 7d0dff5e..89c98f0a 100644 --- a/tests/WordPress/Orm/DatabaseTransactionTest.php +++ b/tests/WordPress/Orm/DatabaseTransactionTest.php @@ -14,9 +14,9 @@ class DatabaseTransactionTest extends TestCase { - private static string $tableName = ''; - private static AbstractModel $model; - + private string $tableName = ''; + private AbstractModel $model; + private Database $db; /** * @return void @@ -26,23 +26,16 @@ public static function setUpBeforeClass(): void global $wpdb; $tableName = $wpdb->prefix . 'document'; - self::$tableName = $tableName; $sql = "CREATE TABLE $tableName ( id INT NOT NULL AUTO_INCREMENT, name varchar(100) NOT NULL, - url varchar(55) DEFAULT '' NOT NULL + url varchar(55) DEFAULT '' NOT NULL, PRIMARY KEY (id) );"; require_once ABSPATH . 'wp-admin/includes/upgrade.php'; dbDelta($sql); - self::$model = new class () extends AbstractModel { - protected $primaryKey = 'id'; - public $timestamps = false; - protected $table = 'document'; - }; - define('SAVEQUERIES', true); } @@ -51,7 +44,16 @@ public static function setUpBeforeClass(): void */ public function setUp(): void { - self::$model::truncate(); + $this->model = new class () extends AbstractModel { + protected $primaryKey = 'id'; + public $timestamps = false; + protected $table = 'document'; + }; + + global $wpdb; + $this->tableName = $wpdb->prefix . 'document'; + $this->model::truncate(); + $this->db = new Database(); } /** @@ -61,15 +63,10 @@ public function setUp(): void */ public function testTransactionSuccess(): void { - Database::getInstance()->transaction(function () { - Database::getInstance()->insert(self::$tableName, [ - 'name' => 'Invoice #15', - 'url' => 'invoice-15', - ]); - Database::getInstance()->insert(self::$tableName, [ - 'name' => 'Invoice #10', - 'url' => 'invoice-10', - ]); + $this->db->transaction(function () { + $query = sprintf('INSERT INTO %s (name, URL) VALUES(? ?);', $this->tableName); + $this->db->insert($query, ['Invoice #15', 'invoice-15']); + $this->db->insert($query, ['Invoice #16', 'invoice-16']); }); global $wpdb; From 55ff127077ab24fb48fcf3c766e53c33ece3c64b Mon Sep 17 00:00:00 2001 From: Dimitri BOUTEILLE Date: Sun, 13 Oct 2024 22:09:21 +0200 Subject: [PATCH 04/15] WIP DatabaseTransactionTest --- tests/WordPress/Orm/DatabaseTransactionTest.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/WordPress/Orm/DatabaseTransactionTest.php b/tests/WordPress/Orm/DatabaseTransactionTest.php index 89c98f0a..58186a77 100644 --- a/tests/WordPress/Orm/DatabaseTransactionTest.php +++ b/tests/WordPress/Orm/DatabaseTransactionTest.php @@ -60,11 +60,12 @@ public function setUp(): void * @throws \Throwable * @return void * @covers Database::transaction + * @covers Database::insert */ public function testTransactionSuccess(): void { $this->db->transaction(function () { - $query = sprintf('INSERT INTO %s (name, URL) VALUES(? ?);', $this->tableName); + $query = sprintf('INSERT INTO %s (name, url) VALUES(?, ?);', $this->tableName); $this->db->insert($query, ['Invoice #15', 'invoice-15']); $this->db->insert($query, ['Invoice #16', 'invoice-16']); }); From 1f95f2f90b8a1da1271bc0fa59dc6834405eb1e8 Mon Sep 17 00:00:00 2001 From: Dimitri BOUTEILLE Date: Sun, 13 Oct 2024 22:14:55 +0200 Subject: [PATCH 05/15] WIP DatabaseTransactionTest --- .../WordPress/Orm/DatabaseTransactionTest.php | 23 +++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/tests/WordPress/Orm/DatabaseTransactionTest.php b/tests/WordPress/Orm/DatabaseTransactionTest.php index 58186a77..acff3e02 100644 --- a/tests/WordPress/Orm/DatabaseTransactionTest.php +++ b/tests/WordPress/Orm/DatabaseTransactionTest.php @@ -35,8 +35,6 @@ public static function setUpBeforeClass(): void require_once ABSPATH . 'wp-admin/includes/upgrade.php'; dbDelta($sql); - - define('SAVEQUERIES', true); } /** @@ -53,7 +51,8 @@ public function setUp(): void global $wpdb; $this->tableName = $wpdb->prefix . 'document'; $this->model::truncate(); - $this->db = new Database(); + $this->db = Database::getInstance(); + define('SAVEQUERIES', true); } /** @@ -70,7 +69,23 @@ public function testTransactionSuccess(): void $this->db->insert($query, ['Invoice #16', 'invoice-16']); }); + $this->assertTransactionStartEndCommit(); + $items = $this->model::all(); + var_dump($items->toArray()); + $this->assertCount(2, $items->toArray()); + } + + /** + * @return void + */ + private function assertTransactionStartEndCommit(): void + { global $wpdb; - var_dump($wpdb->queries); + $query = $wpdb->queries; + + $firstQuery = reset($query)[0] ?? ''; + $lastQuery = end($query)[0] ?? ''; + $this->assertEquals('START TRANSACTION;', $firstQuery); + $this->assertEquals('COMMIT;', $lastQuery); } } From ac4ae7414a2d389fa9068b1a31e964ce3abb2e25 Mon Sep 17 00:00:00 2001 From: Dimitri BOUTEILLE Date: Sun, 13 Oct 2024 22:27:18 +0200 Subject: [PATCH 06/15] WIP DatabaseTransactionTest --- .../WordPress/Orm/DatabaseTransactionTest.php | 65 +++++++++++++++++-- 1 file changed, 58 insertions(+), 7 deletions(-) diff --git a/tests/WordPress/Orm/DatabaseTransactionTest.php b/tests/WordPress/Orm/DatabaseTransactionTest.php index acff3e02..7e166b59 100644 --- a/tests/WordPress/Orm/DatabaseTransactionTest.php +++ b/tests/WordPress/Orm/DatabaseTransactionTest.php @@ -11,6 +11,7 @@ use Dbout\WpOrm\Orm\AbstractModel; use Dbout\WpOrm\Orm\Database; use Dbout\WpOrm\Tests\WordPress\TestCase; +use Illuminate\Database\QueryException; class DatabaseTransactionTest extends TestCase { @@ -42,6 +43,7 @@ public static function setUpBeforeClass(): void */ public function setUp(): void { + define('SAVEQUERIES', false); $this->model = new class () extends AbstractModel { protected $primaryKey = 'id'; public $timestamps = false; @@ -52,7 +54,6 @@ public function setUp(): void $this->tableName = $wpdb->prefix . 'document'; $this->model::truncate(); $this->db = Database::getInstance(); - define('SAVEQUERIES', true); } /** @@ -60,25 +61,62 @@ public function setUp(): void * @return void * @covers Database::transaction * @covers Database::insert + * @covers Database::commit */ - public function testTransactionSuccess(): void + public function testTransactionCommit(): void { + $this->activeLogQueries(); $this->db->transaction(function () { $query = sprintf('INSERT INTO %s (name, url) VALUES(?, ?);', $this->tableName); $this->db->insert($query, ['Invoice #15', 'invoice-15']); $this->db->insert($query, ['Invoice #16', 'invoice-16']); }); - $this->assertTransactionStartEndCommit(); + $this->assertTransaction('commit'); + $this->assertCount(2, $this->model::all()->toArray()); + } + + /** + * @return void + * @covers Database::transaction + * @covers Database::delete + * @covers Database::insert + * @covers Database::rollBack + * @throws \Throwable + */ + public function testTransactionRollback(): void + { + $query = sprintf('INSERT INTO %s (name, url) VALUES(?, ?);', $this->tableName); + $this->db->insert($query, ['Deposit #1', 'deposit-1']); + $this->db->insert($query, ['Deposit #2', 'deposit-2']); + + $this->activeLogQueries(); + try { + $this->db->transaction(function () use ($query) { + $this->db->insert($query, ['Deposit #99', 'deposit-99']); + $this->db->delete(sprintf('DELETE FROM %s;', $this->tableName)); + + /** + * Throw exception because fake_column is invalid column name. + */ + $this->db->delete(sprintf('DELETE FROM %s WHERE fake_column = %d;', $this->tableName, $query)); + }); + } catch (\Exception $exception) { + // Off exception + $this->assertInstanceOf(QueryException::class, $exception); + } + + $this->assertTransaction('rollback'); + $items = $this->model::all(); - var_dump($items->toArray()); - $this->assertCount(2, $items->toArray()); + $this->assertCount(2, $items->toArray(), 'There must be only 2 items because the transaction was rollback.'); } /** + * @param string $mode * @return void */ - private function assertTransactionStartEndCommit(): void + private function assertTransaction(string $mode): void { global $wpdb; $query = $wpdb->queries; @@ -86,6 +124,19 @@ private function assertTransactionStartEndCommit(): void $firstQuery = reset($query)[0] ?? ''; $lastQuery = end($query)[0] ?? ''; $this->assertEquals('START TRANSACTION;', $firstQuery); - $this->assertEquals('COMMIT;', $lastQuery); + + if ($mode === 'commit') { + $this->assertEquals('COMMIT;', $lastQuery); + } elseif ($mode === 'rollback') { + $this->assertEquals('ROLLBACK;', $lastQuery); + } + } + + /** + * @return void + */ + private function activeLogQueries(): void + { + define('SAVEQUERIES', true); } } From 6db3f2bbdae1b998219ce3734716441dace907a8 Mon Sep 17 00:00:00 2001 From: Dimitri BOUTEILLE Date: Sun, 13 Oct 2024 22:28:29 +0200 Subject: [PATCH 07/15] WIP DatabaseTransactionTest --- tests/WordPress/Orm/DatabaseTransactionTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/WordPress/Orm/DatabaseTransactionTest.php b/tests/WordPress/Orm/DatabaseTransactionTest.php index 7e166b59..6f9f7693 100644 --- a/tests/WordPress/Orm/DatabaseTransactionTest.php +++ b/tests/WordPress/Orm/DatabaseTransactionTest.php @@ -77,12 +77,12 @@ public function testTransactionCommit(): void } /** + * @throws \Throwable * @return void * @covers Database::transaction * @covers Database::delete * @covers Database::insert * @covers Database::rollBack - * @throws \Throwable */ public function testTransactionRollback(): void { From 80470fc5659ce76692010077ed18489f4d48510f Mon Sep 17 00:00:00 2001 From: Dimitri BOUTEILLE Date: Sun, 13 Oct 2024 22:32:53 +0200 Subject: [PATCH 08/15] WIP DatabaseTransactionTest --- tests/WordPress/Orm/DatabaseTransactionTest.php | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/tests/WordPress/Orm/DatabaseTransactionTest.php b/tests/WordPress/Orm/DatabaseTransactionTest.php index 6f9f7693..1bdda959 100644 --- a/tests/WordPress/Orm/DatabaseTransactionTest.php +++ b/tests/WordPress/Orm/DatabaseTransactionTest.php @@ -43,7 +43,6 @@ public static function setUpBeforeClass(): void */ public function setUp(): void { - define('SAVEQUERIES', false); $this->model = new class () extends AbstractModel { protected $primaryKey = 'id'; public $timestamps = false; @@ -54,6 +53,7 @@ public function setUp(): void $this->tableName = $wpdb->prefix . 'document'; $this->model::truncate(); $this->db = Database::getInstance(); + define('SAVEQUERIES', true); } /** @@ -65,7 +65,7 @@ public function setUp(): void */ public function testTransactionCommit(): void { - $this->activeLogQueries(); + $this->resetLogQueries(); $this->db->transaction(function () { $query = sprintf('INSERT INTO %s (name, url) VALUES(?, ?);', $this->tableName); $this->db->insert($query, ['Invoice #15', 'invoice-15']); @@ -90,7 +90,7 @@ public function testTransactionRollback(): void $this->db->insert($query, ['Deposit #1', 'deposit-1']); $this->db->insert($query, ['Deposit #2', 'deposit-2']); - $this->activeLogQueries(); + $this->resetLogQueries(); try { $this->db->transaction(function () use ($query) { $this->db->insert($query, ['Deposit #99', 'deposit-99']); @@ -135,8 +135,9 @@ private function assertTransaction(string $mode): void /** * @return void */ - private function activeLogQueries(): void + private function resetLogQueries(): void { - define('SAVEQUERIES', true); + global $wpdb; + $wpdb->queries = []; } } From 91b240a6f27219c7020ec8d3cd4b6c77930c96bd Mon Sep 17 00:00:00 2001 From: Dimitri BOUTEILLE Date: Sun, 13 Oct 2024 22:34:40 +0200 Subject: [PATCH 09/15] WIP DatabaseTransactionTest --- tests/WordPress/Orm/DatabaseTransactionTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/WordPress/Orm/DatabaseTransactionTest.php b/tests/WordPress/Orm/DatabaseTransactionTest.php index 1bdda959..d4b56e30 100644 --- a/tests/WordPress/Orm/DatabaseTransactionTest.php +++ b/tests/WordPress/Orm/DatabaseTransactionTest.php @@ -36,6 +36,7 @@ public static function setUpBeforeClass(): void require_once ABSPATH . 'wp-admin/includes/upgrade.php'; dbDelta($sql); + define('SAVEQUERIES', true); } /** @@ -53,7 +54,6 @@ public function setUp(): void $this->tableName = $wpdb->prefix . 'document'; $this->model::truncate(); $this->db = Database::getInstance(); - define('SAVEQUERIES', true); } /** From ab24469d0487e4e749fc989cedceb1fb023595bb Mon Sep 17 00:00:00 2001 From: Dimitri BOUTEILLE Date: Sun, 13 Oct 2024 22:36:47 +0200 Subject: [PATCH 10/15] WIP DatabaseTransactionTest --- tests/WordPress/Orm/DatabaseTransactionTest.php | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/WordPress/Orm/DatabaseTransactionTest.php b/tests/WordPress/Orm/DatabaseTransactionTest.php index d4b56e30..ace38ab6 100644 --- a/tests/WordPress/Orm/DatabaseTransactionTest.php +++ b/tests/WordPress/Orm/DatabaseTransactionTest.php @@ -110,6 +110,7 @@ public function testTransactionRollback(): void $items = $this->model::all(); $this->assertCount(2, $items->toArray(), 'There must be only 2 items because the transaction was rollback.'); + $this->assertEquals(['deposit-1', 'deposit-2'], $items->pluck('url')); } /** From d1d4eb6fd3bae570cd2edc11a9c227167b6b3722 Mon Sep 17 00:00:00 2001 From: Dimitri BOUTEILLE Date: Sun, 13 Oct 2024 22:42:19 +0200 Subject: [PATCH 11/15] WIP DatabaseTransactionTest --- .../WordPress/Orm/DatabaseTransactionTest.php | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/tests/WordPress/Orm/DatabaseTransactionTest.php b/tests/WordPress/Orm/DatabaseTransactionTest.php index ace38ab6..3af1f894 100644 --- a/tests/WordPress/Orm/DatabaseTransactionTest.php +++ b/tests/WordPress/Orm/DatabaseTransactionTest.php @@ -101,16 +101,28 @@ public function testTransactionRollback(): void */ $this->db->delete(sprintf('DELETE FROM %s WHERE fake_column = %d;', $this->tableName, $query)); }); - } catch (\Exception $exception) { + } catch (\Exception) { // Off exception - $this->assertInstanceOf(QueryException::class, $exception); } $this->assertTransaction('rollback'); $items = $this->model::all(); $this->assertCount(2, $items->toArray(), 'There must be only 2 items because the transaction was rollback.'); - $this->assertEquals(['deposit-1', 'deposit-2'], $items->pluck('url')); + $this->assertEquals(['deposit-1', 'deposit-2'], $items->pluck('url')->toArray()); + } + + /** + * @return void + * @throws \Throwable + * @covers Database::transaction + */ + public function testTransactionThrowsQueryException(): void + { + $this->expectException(QueryException::class); + $this->db->transaction(function () { + $this->db->delete('DELETE FROM fake_table;'); + }); } /** @@ -125,6 +137,7 @@ private function assertTransaction(string $mode): void $firstQuery = reset($query)[0] ?? ''; $lastQuery = end($query)[0] ?? ''; $this->assertEquals('START TRANSACTION;', $firstQuery); + $this->assertEquals(0, $this->db->transactionCount); if ($mode === 'commit') { $this->assertEquals('COMMIT;', $lastQuery); From 9b3d4b4b61175912466b5e8c7136857b1d5215fd Mon Sep 17 00:00:00 2001 From: Dimitri BOUTEILLE Date: Sun, 13 Oct 2024 22:45:02 +0200 Subject: [PATCH 12/15] WIP DatabaseTransactionTest --- tests/WordPress/Orm/DatabaseTransactionTest.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tests/WordPress/Orm/DatabaseTransactionTest.php b/tests/WordPress/Orm/DatabaseTransactionTest.php index 3af1f894..948a22a5 100644 --- a/tests/WordPress/Orm/DatabaseTransactionTest.php +++ b/tests/WordPress/Orm/DatabaseTransactionTest.php @@ -113,16 +113,19 @@ public function testTransactionRollback(): void } /** - * @return void * @throws \Throwable + * @return void * @covers Database::transaction */ public function testTransactionThrowsQueryException(): void { $this->expectException(QueryException::class); + $this->resetLogQueries(); $this->db->transaction(function () { $this->db->delete('DELETE FROM fake_table;'); }); + + $this->assertTransaction('rollback'); } /** From 7ce1d6ba302c68116c40a2c91c59e8ef6ad9fe02 Mon Sep 17 00:00:00 2001 From: Dimitri BOUTEILLE Date: Sun, 13 Oct 2024 22:51:24 +0200 Subject: [PATCH 13/15] WIP DatabaseTransactionTest --- .../WordPress/Orm/DatabaseTransactionTest.php | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/tests/WordPress/Orm/DatabaseTransactionTest.php b/tests/WordPress/Orm/DatabaseTransactionTest.php index 948a22a5..a84cb486 100644 --- a/tests/WordPress/Orm/DatabaseTransactionTest.php +++ b/tests/WordPress/Orm/DatabaseTransactionTest.php @@ -128,6 +128,42 @@ public function testTransactionThrowsQueryException(): void $this->assertTransaction('rollback'); } + /** + * @throws \Throwable + * @return void + * @covers Database::beginTransaction + */ + public function testBeginTransaction(): void + { + $this->db->beginTransaction(); + $this->assertLastQueryEquals('START TRANSACTION;'); + $this->assertEquals(1, $this->db->transactionCount); + } + + /** + * @throws \Throwable + * @return void + * @covers Database::rollBack + */ + public function testRollback(): void + { + $this->db->rollBack(); + $this->assertLastQueryEquals('ROLLBACK;'); + $this->assertEquals(0, $this->db->transactionCount); + } + + /** + * @throws \Throwable + * @return void + * @covers Database::commit + */ + public function testCommit(): void + { + $this->db->commit(); + $this->assertLastQueryEquals('COMMIT;'); + $this->assertEquals(0, $this->db->transactionCount); + } + /** * @param string $mode * @return void From 2298bec6acce5c1f44860ccb68bc866da66da3bf Mon Sep 17 00:00:00 2001 From: Dimitri BOUTEILLE Date: Sun, 13 Oct 2024 22:54:06 +0200 Subject: [PATCH 14/15] WIP DatabaseTransactionTest --- tests/WordPress/Orm/DatabaseTransactionTest.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tests/WordPress/Orm/DatabaseTransactionTest.php b/tests/WordPress/Orm/DatabaseTransactionTest.php index a84cb486..dec33c0f 100644 --- a/tests/WordPress/Orm/DatabaseTransactionTest.php +++ b/tests/WordPress/Orm/DatabaseTransactionTest.php @@ -147,6 +147,8 @@ public function testBeginTransaction(): void */ public function testRollback(): void { + $this->db->beginTransaction(); + $this->assertEquals(1, $this->db->transactionCount); $this->db->rollBack(); $this->assertLastQueryEquals('ROLLBACK;'); $this->assertEquals(0, $this->db->transactionCount); @@ -159,6 +161,8 @@ public function testRollback(): void */ public function testCommit(): void { + $this->db->beginTransaction(); + $this->assertEquals(1, $this->db->transactionCount); $this->db->commit(); $this->assertLastQueryEquals('COMMIT;'); $this->assertEquals(0, $this->db->transactionCount); From f91c4303c053eaac09e9d2e6e2ca15e4477f5545 Mon Sep 17 00:00:00 2001 From: Dimitri BOUTEILLE Date: Sun, 13 Oct 2024 22:56:48 +0200 Subject: [PATCH 15/15] WIP DatabaseTransactionTest --- tests/WordPress/Orm/DatabaseTransactionTest.php | 5 ----- 1 file changed, 5 deletions(-) diff --git a/tests/WordPress/Orm/DatabaseTransactionTest.php b/tests/WordPress/Orm/DatabaseTransactionTest.php index dec33c0f..d71ca429 100644 --- a/tests/WordPress/Orm/DatabaseTransactionTest.php +++ b/tests/WordPress/Orm/DatabaseTransactionTest.php @@ -137,7 +137,6 @@ public function testBeginTransaction(): void { $this->db->beginTransaction(); $this->assertLastQueryEquals('START TRANSACTION;'); - $this->assertEquals(1, $this->db->transactionCount); } /** @@ -148,10 +147,8 @@ public function testBeginTransaction(): void public function testRollback(): void { $this->db->beginTransaction(); - $this->assertEquals(1, $this->db->transactionCount); $this->db->rollBack(); $this->assertLastQueryEquals('ROLLBACK;'); - $this->assertEquals(0, $this->db->transactionCount); } /** @@ -162,10 +159,8 @@ public function testRollback(): void public function testCommit(): void { $this->db->beginTransaction(); - $this->assertEquals(1, $this->db->transactionCount); $this->db->commit(); $this->assertLastQueryEquals('COMMIT;'); - $this->assertEquals(0, $this->db->transactionCount); } /**