From 72a39920c70667bddb95a471f01d91b02c8b8b19 Mon Sep 17 00:00:00 2001 From: rxu Date: Sat, 14 Nov 2020 23:20:39 +0700 Subject: [PATCH] [ticket/16549] Fix database testcase transactions handling, fix indentations PHPBB3-16549 --- tests/test_framework/phpbb_database_test_case.php | 8 ++++---- .../phpbb_database_test_connection_manager.php | 6 +++++- tests/test_framework/phpbb_test_case.php | 8 ++++---- 3 files changed, 13 insertions(+), 9 deletions(-) diff --git a/tests/test_framework/phpbb_database_test_case.php b/tests/test_framework/phpbb_database_test_case.php index d357364f81..b6bfb40598 100644 --- a/tests/test_framework/phpbb_database_test_case.php +++ b/tests/test_framework/phpbb_database_test_case.php @@ -390,8 +390,8 @@ abstract class phpbb_database_test_case extends TestCase * PHPUnit deprecates several methods and properties in its recent versions * Provide BC layer to be able to test in multiple environment settings */ - public function expectException(string $exception): void - { + public function expectException(string $exception): void + { if (version_compare(self::$phpunit_version, '9.0', '>=')) { switch ($exception) { @@ -426,8 +426,8 @@ abstract class phpbb_database_test_case extends TestCase * PHPUnit deprecates several methods and properties in its recent versions * Provide BC layer to be able to test in multiple environment settings */ - public static function assertFileNotExists(string $filename, string $message = ''): void - { + public static function assertFileNotExists(string $filename, string $message = ''): void + { if (version_compare(self::$phpunit_version, '9.0', '>=')) { parent::assertFileDoesNotExist($filename, $message); diff --git a/tests/test_framework/phpbb_database_test_connection_manager.php b/tests/test_framework/phpbb_database_test_connection_manager.php index e4c1a194cc..dce9d849e1 100644 --- a/tests/test_framework/phpbb_database_test_connection_manager.php +++ b/tests/test_framework/phpbb_database_test_connection_manager.php @@ -393,12 +393,16 @@ class phpbb_database_test_connection_manager { $this->pdo->beginTransaction(); } - else if ($query === 'commit') + else if ($query === 'commit' && $this->pdo->inTransaction()) { $this->pdo->commit(); } else { + if (!$this->pdo->inTransaction()) + { + $this->pdo->beginTransaction(); + } $this->pdo->exec($query); } } diff --git a/tests/test_framework/phpbb_test_case.php b/tests/test_framework/phpbb_test_case.php index cb48de23d4..726f6671ae 100644 --- a/tests/test_framework/phpbb_test_case.php +++ b/tests/test_framework/phpbb_test_case.php @@ -88,8 +88,8 @@ class phpbb_test_case extends TestCase * PHPUnit deprecates several methods and properties in its recent versions * Provide BC layer to be able to test in multiple environment settings */ - public function expectException(string $exception): void - { + public function expectException(string $exception): void + { if (version_compare(self::$phpunit_version, '9.0', '>=')) { switch ($exception) { @@ -124,8 +124,8 @@ class phpbb_test_case extends TestCase * PHPUnit deprecates several methods and properties in its recent versions * Provide BC layer to be able to test in multiple environment settings */ - public static function assertFileNotExists(string $filename, string $message = ''): void - { + public static function assertFileNotExists(string $filename, string $message = ''): void + { if (version_compare(self::$phpunit_version, '9.0', '>=')) { parent::assertFileDoesNotExist($filename, $message);