From aab36a774a697b6b0957de295215c4be4d63e539 Mon Sep 17 00:00:00 2001 From: Kamil Tekiela Date: Tue, 1 Aug 2023 18:30:46 +0100 Subject: [PATCH] Tidy up new my_mysqli in tests --- ext/mysqli/tests/065.phpt | 3 +-- ext/mysqli/tests/connect.inc | 10 ++++++++++ ext/mysqli/tests/mysqli_affected_rows_oo.phpt | 5 +---- ext/mysqli/tests/mysqli_autocommit_oo.phpt | 5 +---- ext/mysqli/tests/mysqli_change_user_oo.phpt | 8 ++------ ext/mysqli/tests/mysqli_character_set_name_oo.phpt | 7 +------ ext/mysqli/tests/mysqli_close_oo.phpt | 7 +------ ext/mysqli/tests/mysqli_commit_oo.phpt | 8 +------- ext/mysqli/tests/mysqli_connect_twice.phpt | 4 +--- ext/mysqli/tests/mysqli_get_warnings.phpt | 9 +++------ ext/mysqli/tests/mysqli_pconn_conn_multiple.phpt | 8 ++------ ext/mysqli/tests/mysqli_pconn_twice.phpt | 5 +---- ext/mysqli/tests/mysqli_prepare_no_object.phpt | 4 +--- 13 files changed, 26 insertions(+), 57 deletions(-) diff --git a/ext/mysqli/tests/065.phpt b/ext/mysqli/tests/065.phpt index d1c2a813dc8..0a6ca356a20 100644 --- a/ext/mysqli/tests/065.phpt +++ b/ext/mysqli/tests/065.phpt @@ -10,8 +10,7 @@ require_once 'skipifconnectfailure.inc'; report_mode; + $driver->report_mode = MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT; + if ($flags !== 0) { parent::__construct(); $this->real_connect($host, $user, $passwd, $db, $port, $socket, $flags); } else { parent::__construct($host, $user, $passwd, $db, $port, $socket); } + + // Restore error mode + $driver->report_mode = $report_mode; } } diff --git a/ext/mysqli/tests/mysqli_affected_rows_oo.phpt b/ext/mysqli/tests/mysqli_affected_rows_oo.phpt index 69aec1ec24f..311cef500e9 100644 --- a/ext/mysqli/tests/mysqli_affected_rows_oo.phpt +++ b/ext/mysqli/tests/mysqli_affected_rows_oo.phpt @@ -17,10 +17,7 @@ mysqli echo $exception->getMessage() . "\n"; } - if (!$mysqli = new my_mysqli($host, $user, $passwd, $db, $port, $socket)) { - printf("[001] Cannot connect to the server using host=%s, user=%s, passwd=***, dbname=%s, port=%s, socket=%s\n", - $host, $user, $db, $port, $socket); - } + $mysqli = new my_mysqli($host, $user, $passwd, $db, $port, $socket); if (0 !== ($tmp = $mysqli->affected_rows)) printf("[002] Expecting int/0, got %s/%s\n", gettype($tmp), $tmp); diff --git a/ext/mysqli/tests/mysqli_autocommit_oo.phpt b/ext/mysqli/tests/mysqli_autocommit_oo.phpt index fe8ac72e02c..f6219688140 100644 --- a/ext/mysqli/tests/mysqli_autocommit_oo.phpt +++ b/ext/mysqli/tests/mysqli_autocommit_oo.phpt @@ -17,10 +17,7 @@ mysqli autocommit(true))) printf("[002] Expecting boolean/any, got %s/%s\n", gettype($tmp), $tmp); diff --git a/ext/mysqli/tests/mysqli_change_user_oo.phpt b/ext/mysqli/tests/mysqli_change_user_oo.phpt index fdfd331f251..ea7873f31b3 100644 --- a/ext/mysqli/tests/mysqli_change_user_oo.phpt +++ b/ext/mysqli/tests/mysqli_change_user_oo.phpt @@ -18,9 +18,7 @@ if (mysqli_get_server_version($link) >= 50600) $link = NULL; $tmp = NULL; - if (!$mysqli = new my_mysqli($host, $user, $passwd, $db, $port, $socket)) - printf("[001] Cannot connect to the server using host=%s, user=%s, passwd=***, dbname=%s, port=%s, socket=%s\n", - $host, $user, $db, $port, $socket); + $mysqli = new my_mysqli($host, $user, $passwd, $db, $port, $socket); if (false !== ($tmp = $mysqli->change_user($user . '_unknown_really', $passwd . 'non_empty', $db))) printf("[006] Expecting false, got %s/%s\n", gettype($tmp), $tmp); @@ -32,9 +30,7 @@ if (mysqli_get_server_version($link) >= 50600) printf("[008] Expecting false, got %s/%s\n", gettype($tmp), $tmp); // Reconnect because after 3 failed change_user attempts, the server blocks you off. - if (!$mysqli = new my_mysqli($host, $user, $passwd, $db, $port, $socket)) - printf("[001] Cannot connect to the server using host=%s, user=%s, passwd=***, dbname=%s, port=%s, socket=%s\n", - $host, $user, $db, $port, $socket); + $mysqli = new my_mysqli($host, $user, $passwd, $db, $port, $socket); if (!$mysqli->query('SET @mysqli_change_user_test_var=1')) printf("[009] Failed to set test variable: [%d] %s\n", $mysqli->errno, $mysqli->error); diff --git a/ext/mysqli/tests/mysqli_character_set_name_oo.phpt b/ext/mysqli/tests/mysqli_character_set_name_oo.phpt index af2077d10d1..4a1f5ea6004 100644 --- a/ext/mysqli/tests/mysqli_character_set_name_oo.phpt +++ b/ext/mysqli/tests/mysqli_character_set_name_oo.phpt @@ -11,12 +11,7 @@ require_once 'skipifconnectfailure.inc'; /* NOTE: http://bugs.mysql.com/bug.php?id=7923 makes this test fail very likely on all 4.1.x - 5.0.x! */ require_once 'connect.inc'; - $tmp = NULL; - $link = NULL; - - if (!$mysqli = new my_mysqli($host, $user, $passwd, $db, $port, $socket)) - printf("[001] Cannot connect to the server using host=%s, user=%s, passwd=***, dbname=%s, port=%s, socket=%s\n", - $host, $user, $db, $port, $socket); + $mysqli = new my_mysqli($host, $user, $passwd, $db, $port, $socket); if (!$res = $mysqli->query('SELECT version() AS server_version')) printf("[003] [%d] %s\n", $mysqli->errno, $mysqli->error); diff --git a/ext/mysqli/tests/mysqli_close_oo.phpt b/ext/mysqli/tests/mysqli_close_oo.phpt index 602ec3354b2..3aafdbdc95f 100644 --- a/ext/mysqli/tests/mysqli_close_oo.phpt +++ b/ext/mysqli/tests/mysqli_close_oo.phpt @@ -10,12 +10,7 @@ require_once 'skipifconnectfailure.inc'; close(); if (true !== $tmp) diff --git a/ext/mysqli/tests/mysqli_commit_oo.phpt b/ext/mysqli/tests/mysqli_commit_oo.phpt index f9c1865328f..d0ff739b8af 100644 --- a/ext/mysqli/tests/mysqli_commit_oo.phpt +++ b/ext/mysqli/tests/mysqli_commit_oo.phpt @@ -15,9 +15,6 @@ if (!have_innodb($link)) commit(); @@ -25,10 +22,7 @@ if (!have_innodb($link)) echo $exception->getMessage() . "\n"; } - if (!$mysqli = new my_mysqli($host, $user, $passwd, $db, $port, $socket)) { - printf("[001] Cannot connect to the server using host=%s, user=%s, passwd=***, dbname=%s, port=%s, socket=%s\n", - $host, $user, $db, $port, $socket); - } + $mysqli = new my_mysqli($host, $user, $passwd, $db, $port, $socket); if (true !== ($tmp = $mysqli->commit())) { printf("[002] Expecting boolean/true got %s/%s\n", gettype($tmp), $tmp); diff --git a/ext/mysqli/tests/mysqli_connect_twice.phpt b/ext/mysqli/tests/mysqli_connect_twice.phpt index 6bcb07a173f..2564933dfdf 100644 --- a/ext/mysqli/tests/mysqli_connect_twice.phpt +++ b/ext/mysqli/tests/mysqli_connect_twice.phpt @@ -35,9 +35,7 @@ require_once 'skipifconnectfailure.inc'; mysqli_close($link); - if (!$link = new my_mysqli($host, $user, $passwd, $db, $port, $socket)) - printf("[007] Cannot connect to the server using host=%s, user=%s, passwd=***, dbname=%s, port=%s, socket=%s\n", - $host, $user, $db, $port, $socket); + $link = new my_mysqli($host, $user, $passwd, $db, $port, $socket); if (!$thread_id = $link->thread_id) printf("[008] Cannot determine thread id, test will fail, [%d] %s\n", mysqli_errno($link), mysqli_error($link)); diff --git a/ext/mysqli/tests/mysqli_get_warnings.phpt b/ext/mysqli/tests/mysqli_get_warnings.phpt index 1c2087e88eb..08831200648 100644 --- a/ext/mysqli/tests/mysqli_get_warnings.phpt +++ b/ext/mysqli/tests/mysqli_get_warnings.phpt @@ -83,8 +83,7 @@ if (!$TEST_EXPERIMENTAL) mysqli_close($link); - if (!$mysqli = new my_mysqli($host, $user, $passwd, $db, $port, $socket)) - printf("[021] Cannot create mysqli object: [%d] %s\n", mysqli_connect_errno(), mysqli_connect_error()); + $mysqli = new my_mysqli($host, $user, $passwd, $db, $port, $socket); if (!$mysqli->query("DROP TABLE IF EXISTS t1")) printf("[022] [%d] %s\n", mysqli_errno($link), mysqli_error($link)); @@ -101,8 +100,7 @@ if (!$TEST_EXPERIMENTAL) printf("[026] [%d] %s\n", mysqli_errno($link), mysqli_error($link)); /* Yes, I really want to check if the object property is empty */ - if (!$mysqli = new my_mysqli($host, $user, $passwd, $db, $port, $socket)) - printf("[027] Cannot create mysqli object: [%d] %s\n", mysqli_connect_errno(), mysqli_connect_error()); + $mysqli = new my_mysqli($host, $user, $passwd, $db, $port, $socket); $warning = new mysqli_warning($mysqli); if (false !== ($tmp = $warning->next())) @@ -111,8 +109,7 @@ if (!$TEST_EXPERIMENTAL) if ('' != ($tmp = $warning->message)) printf("[029] Expecting string/empty, got %s/%s\n", gettype($tmp), $tmp); - if (!$mysqli = new my_mysqli($host, $user, $passwd, $db, $port, $socket)) - printf("[030] Cannot create mysqli object: [%d] %s\n", mysqli_connect_errno(), mysqli_connect_error()); + $mysqli = new my_mysqli($host, $user, $passwd, $db, $port, $socket); if (!$mysqli->query("DROP TABLE IF EXISTS t1")) printf("[031] [%d] %s\n", mysqli_errno($link), mysqli_error($link)); diff --git a/ext/mysqli/tests/mysqli_pconn_conn_multiple.phpt b/ext/mysqli/tests/mysqli_pconn_conn_multiple.phpt index 795c8664a22..8c125054f88 100644 --- a/ext/mysqli/tests/mysqli_pconn_conn_multiple.phpt +++ b/ext/mysqli/tests/mysqli_pconn_conn_multiple.phpt @@ -41,9 +41,7 @@ mysqli.max_links=-1 mysqli_close($link); - if (!$link = new my_mysqli($phost, $user, $passwd, $db, $port, $socket)) - printf("[007] Cannot connect to the server using host=%s, user=%s, passwd=***, dbname=%s, port=%s, socket=%s\n", - $phost, $user, $db, $port, $socket); + $link = new my_mysqli($host, $user, $passwd, $db, $port, $socket); if (!$thread_id = $link->thread_id) printf("[008] Cannot determine thread id, test will fail, [%d] %s\n", mysqli_errno($link), mysqli_error($link)); @@ -103,9 +101,7 @@ mysqli.max_links=-1 mysqli_close($link); - if (!$link = new my_mysqli($host, $user, $passwd, $db, $port, $socket)) - printf("[022] Cannot connect to the server using host=%s, user=%s, passwd=***, dbname=%s, port=%s, socket=%s\n", - $host, $user, $db, $port, $socket); + $link = new my_mysqli($host, $user, $passwd, $db, $port, $socket); if (!$thread_id = $link->thread_id) printf("[023] Cannot determine thread id, test will fail, [%d] %s\n", mysqli_errno($link), mysqli_error($link)); diff --git a/ext/mysqli/tests/mysqli_pconn_twice.phpt b/ext/mysqli/tests/mysqli_pconn_twice.phpt index 219fe385dae..8ef8aea2b95 100644 --- a/ext/mysqli/tests/mysqli_pconn_twice.phpt +++ b/ext/mysqli/tests/mysqli_pconn_twice.phpt @@ -34,10 +34,7 @@ mysqli.max_links=-1 mysqli_close($link); - if (!$link = new my_mysqli($host, $user, $passwd, $db, $port, $socket)) - printf("[007] Cannot connect to the server using host=%s, user=%s, passwd=***, dbname=%s, port=%s, socket=%s\n", - $host, $user, $db, $port, $socket); - + $link = new my_mysqli($host, $user, $passwd, $db, $port, $socket); if (true !== ($tmp = $link->real_connect($host, $user, $passwd, $db, $port, $socket))) printf("[009] Expecting boolean/true got %s/%s\n", gettype($tmp), $tmp); diff --git a/ext/mysqli/tests/mysqli_prepare_no_object.phpt b/ext/mysqli/tests/mysqli_prepare_no_object.phpt index aec432260a2..c488cbe5059 100644 --- a/ext/mysqli/tests/mysqli_prepare_no_object.phpt +++ b/ext/mysqli/tests/mysqli_prepare_no_object.phpt @@ -20,9 +20,7 @@ require_once 'skipifconnectfailure.inc'; mysqli_close($link); - if (!$mysqli = new my_mysqli($host, $user, $passwd, $db, $port, $socket)) - printf("[003] Cannot connect to the server using host=%s, user=%s, passwd=***, dbname=%s, port=%s, socket=%s\n", - $host, $user, $db, $port, $socket); + $mysqli = new my_mysqli($host, $user, $passwd, $db, $port, $socket); if (false !== ($tmp = $mysqli->prepare(false))) printf("[004] Expecting boolean/false, got %s/%s\n", gettype($tmp), (is_object($tmp) ? var_dump($tmp, true) : $tmp));