summaryrefslogtreecommitdiff
path: root/ext/mysqli
diff options
context:
space:
mode:
authorDharman <tekiela246@gmail.com>2021-03-13 18:17:56 +0000
committerNikita Popov <nikita.ppv@gmail.com>2021-03-15 10:34:55 +0100
commit4bd3cb66263ef9430c1def80ef836226f83f6317 (patch)
treee6910027165d93cf01e7b745bbd1da28ae822015 /ext/mysqli
parent5801ead8ea03b78a9f320e0ac1cdff171a49dc0b (diff)
downloadphp-git-4bd3cb66263ef9430c1def80ef836226f83f6317.tar.gz
Clean up mysqli_driver test cases
And remove an unnecessary test case that is already covered by the other two.
Diffstat (limited to 'ext/mysqli')
-rw-r--r--ext/mysqli/tests/073.phpt22
-rw-r--r--ext/mysqli/tests/mysqli_class_mysqli_driver_interface.phpt134
-rw-r--r--ext/mysqli/tests/mysqli_driver.phpt185
3 files changed, 170 insertions, 171 deletions
diff --git a/ext/mysqli/tests/073.phpt b/ext/mysqli/tests/073.phpt
deleted file mode 100644
index c03cb2236d..0000000000
--- a/ext/mysqli/tests/073.phpt
+++ /dev/null
@@ -1,22 +0,0 @@
---TEST--
-mysqli_driver properties
---SKIPIF--
-<?php require_once('skipif.inc'); ?>
---FILE--
-<?php
- require_once("connect.inc");
-
- var_dump($driver->client_version);
- var_dump($driver->client_info);
- var_dump($driver->driver_version);
- var_dump($driver->reconnect);
- var_dump($driver->report_mode);
- print "done!";
-?>
---EXPECTF--
-int(%d)
-string(%d) "%s"
-int(%d)
-bool(%s)
-int(%d)
-done!
diff --git a/ext/mysqli/tests/mysqli_class_mysqli_driver_interface.phpt b/ext/mysqli/tests/mysqli_class_mysqli_driver_interface.phpt
index 55fd3be47e..32d13d6750 100644
--- a/ext/mysqli/tests/mysqli_class_mysqli_driver_interface.phpt
+++ b/ext/mysqli/tests/mysqli_class_mysqli_driver_interface.phpt
@@ -3,81 +3,81 @@ Interface of the class mysqli_driver
--SKIPIF--
<?php
require_once('skipif.inc');
-require_once('skipifconnectfailure.inc');
?>
--FILE--
<?php
- require('connect.inc');
- require('table.inc');
- $driver = new mysqli_driver();
+$driver = new mysqli_driver();
- printf("Parent class:\n");
- var_dump(get_parent_class($driver));
+printf("Parent class:\n");
+var_dump(get_parent_class($driver));
- printf("\nMethods:\n");
- $methods = get_class_methods($driver);
- $expected_methods = array();
+printf("\nMethods:\n");
+$methods = get_class_methods($driver);
+$expected_methods = [];
- foreach ($methods as $k => $method) {
- if (isset($expected_methods[$method])) {
- unset($expected_methods[$method]);
- unset($methods[$k]);
- }
+foreach ($methods as $k => $method) {
+ if (isset($expected_methods[$method])) {
+ unset($expected_methods[$method], $methods[$k]);
}
- if (!empty($expected_methods)) {
- printf("Dumping list of missing methods.\n");
- var_dump($expected_methods);
- }
- if (!empty($methods)) {
- printf("Dumping list of unexpected methods.\n");
- var_dump($methods);
- }
- if (empty($expected_methods) && empty($methods))
- printf("ok\n");
-
- printf("\nClass variables:\n");
- $variables = array_keys(get_class_vars(get_class($driver)));
- sort($variables);
- foreach ($variables as $k => $var)
- printf("%s\n", $var);
-
- printf("\nObject variables:\n");
- $variables = array_keys(get_object_vars($driver));
- foreach ($variables as $k => $var)
- printf("%s\n", $var);
-
- printf("\nMagic, magic properties:\n");
-
- assert(mysqli_get_client_info() === $driver->client_info);
- printf("driver->client_info = '%s'\n", $driver->client_info);
-
- assert(mysqli_get_client_version() === $driver->client_version);
- printf("driver->client_version = '%s'\n", $driver->client_version);
-
- assert($driver->driver_version > 0);
- printf("driver->driver_version = '%s'\n", $driver->driver_version);
-
- assert(in_array($driver->report_mode,
- array(
- MYSQLI_REPORT_ALL,
- MYSQLI_REPORT_STRICT,
- MYSQLI_REPORT_ERROR,
- MYSQLI_REPORT_INDEX,
- MYSQLI_REPORT_OFF
- )
- ));
-
- printf("driver->report_mode = '%s'\n", $driver->report_mode);
- $driver->report_mode = MYSQLI_REPORT_STRICT;
- assert($driver->report_mode === MYSQLI_REPORT_STRICT);
-
- printf("driver->reconnect = '%s'\n", $driver->reconnect);
-
- printf("\nAccess to undefined properties:\n");
- printf("driver->unknown = '%s'\n", @$driver->unknown);
-
- print "done!";
+}
+if (!empty($expected_methods)) {
+ printf("Dumping list of missing methods.\n");
+ var_dump($expected_methods);
+}
+if (!empty($methods)) {
+ printf("Dumping list of unexpected methods.\n");
+ var_dump($methods);
+}
+if (empty($expected_methods) && empty($methods)) {
+ printf("ok\n");
+}
+
+printf("\nClass variables:\n");
+$variables = array_keys(get_class_vars(get_class($driver)));
+sort($variables);
+foreach ($variables as $var) {
+ printf("%s\n", $var);
+}
+
+printf("\nObject variables:\n");
+$variables = array_keys(get_object_vars($driver));
+foreach ($variables as $var) {
+ printf("%s\n", $var);
+}
+
+printf("\nMagic, magic properties:\n");
+
+assert(mysqli_get_client_info() === $driver->client_info);
+printf("driver->client_info = '%s'\n", $driver->client_info);
+
+assert(mysqli_get_client_version() === $driver->client_version);
+printf("driver->client_version = '%s'\n", $driver->client_version);
+
+assert($driver->driver_version > 0);
+printf("driver->driver_version = '%s'\n", $driver->driver_version);
+
+assert(in_array($driver->report_mode, [
+ MYSQLI_REPORT_ALL,
+ MYSQLI_REPORT_STRICT,
+ MYSQLI_REPORT_STRICT|MYSQLI_REPORT_ERROR,
+ MYSQLI_REPORT_STRICT|MYSQLI_REPORT_INDEX,
+ MYSQLI_REPORT_ERROR,
+ MYSQLI_REPORT_ERROR|MYSQLI_REPORT_INDEX,
+ MYSQLI_REPORT_INDEX,
+ MYSQLI_REPORT_OFF
+]));
+
+printf("driver->report_mode = '%s'\n", $driver->report_mode);
+$driver->report_mode = MYSQLI_REPORT_STRICT;
+assert($driver->report_mode === MYSQLI_REPORT_STRICT);
+
+printf("driver->reconnect = '%s'\n", $driver->reconnect);
+
+printf("\nAccess to undefined properties:\n");
+printf("driver->unknown = '%s'\n", @$driver->unknown);
+
+print "done!";
?>
--EXPECTF--
Parent class:
diff --git a/ext/mysqli/tests/mysqli_driver.phpt b/ext/mysqli/tests/mysqli_driver.phpt
index 4ef41e355c..be2c61919b 100644
--- a/ext/mysqli/tests/mysqli_driver.phpt
+++ b/ext/mysqli/tests/mysqli_driver.phpt
@@ -7,102 +7,123 @@ require_once('skipifconnectfailure.inc');
?>
--FILE--
<?php
- require("table.inc");
+require_once('connect.inc');
- if (!is_object($driver = new mysqli_driver()))
- printf("[001] Failed to create mysqli_driver object\n");
+if (!is_object($driver = new mysqli_driver())) {
+ printf("[001] Failed to create mysqli_driver object\n");
+}
- $client_info = mysqli_get_client_info();
- if (($tmp = $driver->client_info) !== $client_info)
- printf("[002] Expecting %s/%s, got %s/%s\n",
- gettype($client_info), $client_info,
- gettype($tmp), $tmp);
-
- $client_version = mysqli_get_client_version();
- if (($tmp = $driver->client_version) !== $client_version)
- printf("[003] Expecting %s/%s, got %s/%s\n",
- gettype($client_version), $client_version,
- gettype($tmp), $tmp);
-
- if (!is_int($tmp = $driver->driver_version) || (0 == $tmp))
- printf("[004] Expecting int/any, got %s/%s\n",
+$client_info = mysqli_get_client_info();
+if (($tmp = $driver->client_info) !== $client_info) {
+ printf("[002] Expecting %s/%s, got %s/%s\n",
+ gettype($client_info), $client_info,
gettype($tmp), $tmp);
-
-
- $all_modes = array(MYSQLI_REPORT_INDEX, MYSQLI_REPORT_ERROR, MYSQLI_REPORT_STRICT,
- MYSQLI_REPORT_ALL, MYSQLI_REPORT_OFF);
- $report_mode = $driver->report_mode;
- if (!is_int($report_mode))
- printf("[005] Expecting int/any, got %s/%s\n",
- gettype($report_mode), $report_mode);
-
- if (!in_array($report_mode, $all_modes))
- printf("[006] Illegal report mode returned? Got %s, expected %s\n",
- $report_mode, implode(', ', $all_modes));
-
- $driver->report_mode = MYSQLI_REPORT_STRICT;
- $ok = false;
- try {
-
- if ($link = my_mysqli_connect($host, $user . 'unknown_really', $passwd . 'non_empty', $db, $port, $socket))
- printf("[007] 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);
- mysqli_close($link);
-
- } catch (mysqli_sql_exception $e) {
- $ok = true;
- if ('' == $e->getMessage())
- printf("[008] getMessage() has returned an empty string.\n");
- if ('' == $e->getCode())
- printf("[009] getCode() has returned an empty string.\n");
- if ('' == $e->getFile())
- printf("[010] getFile() has returned an empty string.\n");
- if ('' == $e->getLine())
- printf("[011] getLine() has returned an empty string.\n");
- $tmp = $e->getTrace();
- if (empty($tmp))
- printf("[012] getTrace() has returned an empty array.\n");
- if ('' == $e->getTraceAsString())
- printf("[013] getTraceAsString() has returned an empty string.\n");
- if ('' == $e->__toString())
- printf("[014] __toString() has returned an empty string.\n");
-
+}
+
+$client_version = mysqli_get_client_version();
+if (($tmp = $driver->client_version) !== $client_version) {
+ printf("[003] Expecting %s/%s, got %s/%s\n",
+ gettype($client_version), $client_version,
+ gettype($tmp), $tmp);
+}
+
+if (!is_int($tmp = $driver->driver_version) || (0 == $tmp)) {
+ printf("[004] Expecting int/any, got %s/%s\n",
+ gettype($tmp), $tmp);
+}
+
+$all_modes = [
+ MYSQLI_REPORT_ALL,
+ MYSQLI_REPORT_STRICT,
+ MYSQLI_REPORT_STRICT|MYSQLI_REPORT_ERROR,
+ MYSQLI_REPORT_STRICT|MYSQLI_REPORT_INDEX,
+ MYSQLI_REPORT_ERROR,
+ MYSQLI_REPORT_ERROR|MYSQLI_REPORT_INDEX,
+ MYSQLI_REPORT_INDEX,
+ MYSQLI_REPORT_OFF
+];
+$report_mode = $driver->report_mode;
+if (!is_int($report_mode)) {
+ printf("[005] Expecting int/any, got %s/%s\n",
+ gettype($report_mode), $report_mode);
+}
+
+if (!in_array($report_mode, $all_modes)) {
+ printf("[006] Illegal report mode returned? Got %s, expected %s\n",
+ $report_mode, implode(', ', $all_modes));
+}
+
+$driver->report_mode = MYSQLI_REPORT_STRICT;
+$ok = false;
+try {
+ if ($link = my_mysqli_connect($host, $user . 'unknown_really', $passwd . 'non_empty', $db, $port, $socket)) {
+ printf("[007] 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);
}
- if (!$ok)
- printf("[015] Error reporting mode has not been switched to exceptions and or no exception thrown\n");
-
-
- $driver->report_mode = MYSQLI_REPORT_OFF;
- if (!$link = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket))
- printf("[016] [%d] %s\n", mysqli_connect_errno(), mysqli_connect_error());
- mysqli_query($link, "NO_SQL");
mysqli_close($link);
+} catch (mysqli_sql_exception $e) {
+ $ok = true;
+ if ('' == $e->getMessage()) {
+ printf("[008] getMessage() has returned an empty string.\n");
+ }
+ if ('' == $e->getCode()) {
+ printf("[009] getCode() has returned an empty string.\n");
+ }
+ if ('' == $e->getFile()) {
+ printf("[010] getFile() has returned an empty string.\n");
+ }
+ if ('' == $e->getLine()) {
+ printf("[011] getLine() has returned an empty string.\n");
+ }
+ if ([] == $e->getTrace()) {
+ printf("[012] getTrace() has returned an empty array.\n");
+ }
+ if ('' == $e->getTraceAsString()) {
+ printf("[013] getTraceAsString() has returned an empty string.\n");
+ }
+ if ('' == $e->__toString()) {
+ printf("[014] __toString() has returned an empty string.\n");
+ }
+}
+if (!$ok) {
+ printf("[015] Error reporting mode has not been switched to exceptions and or no exception thrown\n");
+}
- $driver->report_mode = MYSQLI_REPORT_ERROR;
+$driver->report_mode = MYSQLI_REPORT_OFF;
+if (!$link = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket)) {
+ printf("[016] [%d] %s\n", mysqli_connect_errno(), mysqli_connect_error());
+}
+mysqli_query($link, "NO_SQL");
+mysqli_close($link);
- if (!$link = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket))
- printf("[017] [%d] %s\n", mysqli_connect_errno(), mysqli_connect_error());
- mysqli_query($link, "NO_SQL");
- mysqli_close($link);
+$driver->report_mode = MYSQLI_REPORT_ERROR;
+
+if (!$link = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket)) {
+ printf("[017] [%d] %s\n", mysqli_connect_errno(), mysqli_connect_error());
+}
+mysqli_query($link, "NO_SQL");
+mysqli_close($link);
- if (MYSQLI_REPORT_ERROR !== $driver->report_mode)
- printf("[018] Error mode should be different\n");
+if (MYSQLI_REPORT_ERROR !== $driver->report_mode) {
+ printf("[018] Error reporting mode should be different\n");
+}
- /* TODO - more report testing should go in here, but it's not really documented what behaviour is expected */
+/* TODO - more report testing should go in here, but it's not really documented what behaviour is expected */
- $driver->report_mode = $report_mode;
+$driver->report_mode = $report_mode;
- $reconnect = $driver->reconnect;
- if (!is_bool($reconnect))
+$reconnect = $driver->reconnect;
+if (!is_bool($reconnect)) {
printf("[019] Expecting boolean/any, got %s/%s\n",
- gettype($reconnect), $reconnect);
+ gettype($reconnect), $reconnect);
+}
- /* pointless, but I need more documentation */
- $driver->reconnect = true;
- $driver->reconnect = false;
- $driver->reconnect = $reconnect;
+/* pointless, but I need more documentation */
+$driver->reconnect = true;
+$driver->reconnect = false;
+$driver->reconnect = $reconnect;
- print "done!";
+print "done!";
?>
--EXPECTF--
Warning: mysqli_query(): (%d/%d): You have an error in your SQL syntax; check the manual that corresponds to your %s server version for the right syntax to use near 'NO_SQL' at line 1 in %s on line %d