Skip to content

Commit

Permalink
Clean up mysqli tests (php#15473)
Browse files Browse the repository at this point in the history
  • Loading branch information
kamil-tekiela authored Aug 17, 2024
1 parent d472866 commit 7e5171d
Show file tree
Hide file tree
Showing 102 changed files with 192 additions and 314 deletions.
2 changes: 0 additions & 2 deletions ext/mysqli/tests/065.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ require_once 'skipifconnectfailure.inc';
printf("[002] Cannot set SQL-Mode, [%d] %s\n", mysqli_errno($mysql), mysqli_error($mysql));

$esc_str = chr(0xbf) . chr(0x5c);
$len = $charset = array();
$tmp = null;

if ($mysql->set_charset("latin1")) {
/* 5C should be escaped */
Expand Down
1 change: 0 additions & 1 deletion ext/mysqli/tests/071.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ require_once 'skipifconnectfailure.inc';
require_once 'connect.inc';

$mysql = new my_mysqli($host, $user, $passwd, $db, $port, $socket);
$version = $mysql->server_version;

var_dump($mysql->query('DO 1'));

Expand Down
2 changes: 1 addition & 1 deletion ext/mysqli/tests/bug45289.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ require_once 'skipifconnectfailure.inc';
if (!$stmt->bind_param('i', $id) || !$stmt->execute())
printf("[003] [%d] %s\n", $stmt->errno, $stmt->error);

if ($res = $link->store_result()) {
if ($link->store_result()) {
printf("[004] Can store result!\n");
} else {
printf("[004] [%d] %s\n", $link->errno, $link->error);
Expand Down
2 changes: 0 additions & 2 deletions ext/mysqli/tests/bug55283.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,6 @@ $link->close();
--FILE--
<?php
require_once 'connect.inc';
$db1 = new mysqli();


$flags = MYSQLI_CLIENT_SSL | MYSQLI_CLIENT_SSL_DONT_VERIFY_SERVER_CERT;

Expand Down
1 change: 0 additions & 1 deletion ext/mysqli/tests/bug62885.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ try {
echo $e->getMessage() . \PHP_EOL;
}

$test2 = array();
$test2 = array();
try {
$test1 = mysqli_poll($test2, $test3, $tablica, 0);
Expand Down
1 change: 0 additions & 1 deletion ext/mysqli/tests/bug66124.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ $table_create = "CREATE TABLE `test` (

$table_insert = "INSERT INTO `test` SET `id`=?";
$table_select = "SELECT * FROM `test`";
$table_delete = "DELETE FROM `test`";
$id = '1311200011005001566';


Expand Down
2 changes: 0 additions & 2 deletions ext/mysqli/tests/bug72489.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,6 @@ while ($stmt->fetch()) {

echo "Finished 1\n";

$newArray = array();

echo "Finished 2\n";

?>
Expand Down
2 changes: 1 addition & 1 deletion ext/mysqli/tests/bug76386.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ $link->query('INSERT INTO t_test VALUES ();');
$stmt = $link->prepare('SELECT * FROM t_test;');
if ($stmt) {
$stmt->execute();
$tid = $t = $t2 = $t3 = $t4 = null;
$tid = $t = $t2 = $t4 = null;
$stmt->bind_result($tid, $t, $t2, $t4, $t6);
while ($stmt->fetch()) {
var_dump($t, $t2, $t4, $t6);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,6 @@ function func_mysqli_fetch_all(
$tmp = mysqli_fetch_all($result, MYSQLI_BOTH);
$row = $tmp[0];

$fields = mysqli_fetch_fields($result);

if ($regexp_comparison) {
if (!preg_match($regexp_comparison, (string)$row['label']) || !preg_match($regexp_comparison, (string)$row[1])) {
printf("[%04d] Expecting %s/%s [reg exp = %s], got %s/%s resp. %s/%s. [%d] %s\n", $offset + 4,
Expand Down
4 changes: 2 additions & 2 deletions ext/mysqli/tests/gh14255.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ mysqli_report(MYSQLI_REPORT_STRICT|MYSQLI_REPORT_ERROR);
$mysqli = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket);

$ca = $mysqli->query('SELECT 1 ');
$c = $ca->fetch_assoc();
$ca->fetch_assoc();
try {
$mysqli->query('SELECT non_existent_column');
} catch (Exception $e) {
echo "Caught exception"."\n";
}
$c = $ca->fetch_assoc();
$ca->fetch_assoc();

print "done!";
?>
Expand Down
4 changes: 2 additions & 2 deletions ext/mysqli/tests/gh9841.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ $mysqli->real_query("SELECT (
UNION ALL
SELECT 2
) FROM dual");
$result = new mysqli_result($mysqli);
new mysqli_result($mysqli);

// now make sure the errors are thrown when not using silent mode
mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);
Expand Down Expand Up @@ -65,7 +65,7 @@ $mysqli->real_query("SELECT (
SELECT 2
) FROM dual");
try {
$result = new mysqli_result($mysqli);
new mysqli_result($mysqli);
} catch (mysqli_sql_exception $e) {
echo $e->getMessage()."\n";
}
Expand Down
3 changes: 1 addition & 2 deletions ext/mysqli/tests/mysqli_affected_rows.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,7 @@ mysqli
if (1 !== ($tmp = mysqli_affected_rows($link)))
printf("[025] Expecting int/1, got %s/%s\n", gettype($tmp), $tmp);

$charsets = array('utf8');
foreach ($charsets as $k => $charset) {
foreach (['utf8'] as $charset) {
if (!($res = mysqli_query($link, sprintf("SHOW CHARACTER SET LIKE '%s'", $charset))))
continue;
mysqli_free_result($res);
Expand Down
4 changes: 2 additions & 2 deletions ext/mysqli/tests/mysqli_begin_transaction.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ if (!have_innodb($link))

/* overrule autocommit */
if (true !== ($tmp = mysqli_begin_transaction($link)))
printf("[011] Got %s - [%d] %s\n", var_dump($tmp, true), mysqli_errno($link), mysqli_error($link));
printf("[011] Got %s - [%d] %s\n", $tmp, mysqli_errno($link), mysqli_error($link));

if (!mysqli_query($link, 'INSERT INTO test(id) VALUES (1)'))
printf("[012] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
Expand Down Expand Up @@ -72,7 +72,7 @@ if (!have_innodb($link))
} else if (!mysqli_commit($link)) {
printf("[018] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
} else {
$res = mysqli_query($link, "SELECT id FROM test WHERE id = 2");
mysqli_query($link, "SELECT id FROM test WHERE id = 2");
}
}

Expand Down
3 changes: 0 additions & 3 deletions ext/mysqli/tests/mysqli_change_user_new.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,6 @@ if (mysqli_get_server_version($link) >= 10_00_00)
<?php
require_once 'connect.inc';

$tmp = NULL;
$link = NULL;

if (!$link = my_mysqli_connect($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);
Expand Down
3 changes: 0 additions & 3 deletions ext/mysqli/tests/mysqli_change_user_old.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@ if (mysqli_get_server_version($link) >= 50600 && mysqli_get_server_version($link
<?php
require_once 'connect.inc';

$tmp = NULL;
$link = NULL;

if (!$link = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket))
printf("[006] Cannot connect to the server using host=%s, user=%s, passwd=***, dbname=%s, port=%s, socket=%s\n",
$host, $user, $db, $port, $socket);
Expand Down
3 changes: 0 additions & 3 deletions ext/mysqli/tests/mysqli_change_user_oo.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@ if (mysqli_get_server_version($link) >= 50600)
<?php
require_once 'connect.inc';

$link = NULL;
$tmp = NULL;

$mysqli = new my_mysqli($host, $user, $passwd, $db, $port, $socket);

if (false !== ($tmp = $mysqli->change_user($user . '_unknown_really', $passwd . 'non_empty', $db)))
Expand Down
2 changes: 1 addition & 1 deletion ext/mysqli/tests/mysqli_change_user_rollback.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ if (!have_innodb($link))
$num = $row['_num'];
assert($num > 0);

if (!$res = mysqli_query($link, 'DELETE FROM test'))
if (false === mysqli_query($link, 'DELETE FROM test'))
printf("[004] [%d] %s\n", mysqli_errno($link), mysqli_error($link));

if (!$res = mysqli_query($link, 'SELECT COUNT(*) AS _num FROM test'))
Expand Down
4 changes: 2 additions & 2 deletions ext/mysqli/tests/mysqli_class_mysqli_properties_no_conn.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ require_once 'skipifconnectfailure.inc';
printf("\nClass variables:\n");
$variables = array_keys(get_class_vars(get_class($mysqli)));
sort($variables);
foreach ($variables as $k => $var) {
foreach ($variables as $var) {
try {
printf("%s = '%s'\n", $var, var_export($mysqli->$var, true));
} catch (Error $exception) {
Expand All @@ -25,7 +25,7 @@ require_once 'skipifconnectfailure.inc';

printf("\nObject variables:\n");
$variables = array_keys(get_object_vars($mysqli));
foreach ($variables as $k => $var) {
foreach ($variables as $var) {
try {
printf("%s = '%s'\n", $var, var_export($mysqli->$var, true));
} catch (Error $exception) {
Expand Down
12 changes: 6 additions & 6 deletions ext/mysqli/tests/mysqli_class_mysqli_result_interface.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,12 @@ require_once 'skipifconnectfailure.inc';
printf("\nClass variables:\n");
$variables = array_keys(get_class_vars(get_class($mysqli_result)));
sort($variables);
foreach ($variables as $k => $var)
foreach ($variables as $var)
printf("%s\n", $var);

printf("\nObject variables:\n");
$variables = array_keys(get_object_vars($mysqli_result));
foreach ($variables as $k => $var)
foreach ($variables as $var)
printf("%s\n", $var);

printf("\nMagic, magic properties:\n");
Expand Down Expand Up @@ -121,9 +121,9 @@ require_once 'skipifconnectfailure.inc';
if (!mysqli_query($link, "SELECT id FROM test ORDER BY id"))
printf("[003] [%d] %s\n", mysqli_errno($link), mysqli_error($link));

$res = new mysqli_result($link);
$res = new mysqli_result($link, MYSQLI_STORE_RESULT);
$res = new mysqli_result($link, MYSQLI_USE_RESULT);
new mysqli_result($link);
new mysqli_result($link, MYSQLI_STORE_RESULT);
new mysqli_result($link, MYSQLI_USE_RESULT);

$valid = array(MYSQLI_STORE_RESULT, MYSQLI_USE_RESULT);
do {
Expand All @@ -132,7 +132,7 @@ require_once 'skipifconnectfailure.inc';

if ($TEST_EXPERIMENTAL) {
ob_start();
$res = new mysqli_result($link, $mode);
new mysqli_result($link, $mode);
$content = ob_get_contents();
ob_end_clean();
if (!stristr($content, 'Invalid value for resultmode'))
Expand Down
4 changes: 2 additions & 2 deletions ext/mysqli/tests/mysqli_class_mysqli_stmt_interface.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,12 @@ mysqli
printf("\nClass variables:\n");
$variables = array_keys(get_class_vars(get_class($stmt)));
sort($variables);
foreach ($variables as $k => $var)
foreach ($variables as $var)
printf("%s\n", $var);

printf("\nObject variables:\n");
$variables = array_keys(get_object_vars($stmt));
foreach ($variables as $k => $var)
foreach ($variables as $var)
printf("%s\n", $var);

printf("\nMagic, magic properties:\n");
Expand Down
4 changes: 1 addition & 3 deletions ext/mysqli/tests/mysqli_connect.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,13 @@ require_once 'skipifconnectfailure.inc';
<?php
require_once 'connect.inc';

$tmp = NULL;
$link = NULL;

/* we need to check, if the server allows anonymous login (empty user) */
$tmp = @mysqli_connect('localhost');
$anon_allow = (gettype($tmp) == "object");

$exptype = ($anon_allow) ? "mysqli_object" : "false";

$link = NULL;
$tmp = @mysqli_connect($link);
if (($anon_allow && gettype($tmp) != "object") || (!$anon_allow && $tmp != false)) {
printf("[002] Expecting %s, got %s/%s\n", $exptype, gettype($tmp), $tmp);
Expand Down
3 changes: 0 additions & 3 deletions ext/mysqli/tests/mysqli_connect_attr.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,6 @@ mysqli_close($link);
<?php
require_once 'connect.inc';

$tmp = NULL;
$link = NULL;
$res = NULL;
if (!$link = mysqli_connect($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);

Expand Down
1 change: 0 additions & 1 deletion ext/mysqli/tests/mysqli_connect_errno.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ require_once 'skipifconnectfailure.inc';
<?php
require_once 'connect.inc';

$tmp = NULL;
$link = NULL;

// too many parameter
Expand Down
3 changes: 1 addition & 2 deletions ext/mysqli/tests/mysqli_connect_error.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ require_once 'skipifconnectfailure.inc';
<?php
require_once 'connect.inc';

$tmp = NULL;
$link = NULL;

// too many parameter
Expand All @@ -29,7 +28,7 @@ require_once 'skipifconnectfailure.inc';

mysqli_close($link);

if ($link = @my_mysqli_connect($host, $user . 'unknown_really', $passwd . 'non_empty', $db, $port, $socket))
if (false !== @my_mysqli_connect($host, $user . 'unknown_really', $passwd . 'non_empty', $db, $port, $socket))
printf("[003] Connect to the server should fail using host=%s, user=%s, passwd=***non_empty, dbname=%s, port=%s, socket=%s\n",
$host, $user . 'unknown_really', $db, $port, $socket);

Expand Down
5 changes: 0 additions & 5 deletions ext/mysqli/tests/mysqli_connect_oo.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,6 @@ require_once 'skipifconnectfailure.inc';
<?php
require_once 'connect.inc';

$tmp = NULL;
$link = NULL;

$obj = new stdClass();

if ($mysqli = new mysqli($host, $user . 'unknown_really', $passwd . 'non_empty', $db, $port, $socket) && !mysqli_connect_errno())
printf("[003] Can connect to the server using host=%s, user=%s, passwd=***non_empty, dbname=%s, port=%s, socket=%s\n",
$host, $user . 'unknown_really', $db, $port, $socket);
Expand Down
3 changes: 0 additions & 3 deletions ext/mysqli/tests/mysqli_connect_oo_defaults.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@ require_once 'skipifconnectfailure.inc';
<?php
require_once 'connect.inc';

$tmp = NULL;
$link = NULL;

if ($socket != "")
/* mysqli.default_socket requires non-empty string */
ini_set('mysqli.default_socket', 'socket');
Expand Down
3 changes: 1 addition & 2 deletions ext/mysqli/tests/mysqli_constants.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,6 @@ $expected_constants['MYSQLI_STORE_RESULT_COPY_DATA'] = true;

$expected_constants['MYSQLI_REFRESH_BACKUP_LOG'] = true;

$version = 50007 + 1;
$expected_constants['MYSQLI_OPT_NET_CMD_BUFFER_SIZE'] = true;
$expected_constants['MYSQLI_OPT_NET_READ_BUFFER_SIZE'] = true;
$expected_constants['MYSQLI_ASYNC'] = true;
Expand Down Expand Up @@ -154,7 +153,7 @@ $expected_constants["MYSQLI_TYPE_JSON"] = true;

$unexpected_constants = array();

foreach ($constants as $group => $consts) {
foreach ($constants as $consts) {
foreach ($consts as $name => $value) {
if (stristr($name, 'mysqli')) {
$name = strtoupper($name);
Expand Down
2 changes: 1 addition & 1 deletion ext/mysqli/tests/mysqli_debug_control_string.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ if (defined('MYSQLI_DEBUG_TRACE_ENABLED') && !MYSQLI_DEBUG_TRACE_ENABLED)
return false;
}

if (!$res = mysqli_query($link, 'SELECT * FROM test')) {
if (false === mysqli_query($link, 'SELECT * FROM test')) {
printf("[%03d][control string '%s'] [%d] %s.\n",
$offset + 2,
$control_string,
Expand Down
Loading

0 comments on commit 7e5171d

Please sign in to comment.