Skip to content

Commit 4bd3cb6

Browse files
kamil-tekielanikic
authored andcommitted
Clean up mysqli_driver test cases
And remove an unnecessary test case that is already covered by the other two.
1 parent 5801ead commit 4bd3cb6

File tree

3 files changed

+170
-171
lines changed

3 files changed

+170
-171
lines changed

ext/mysqli/tests/073.phpt

Lines changed: 0 additions & 22 deletions
This file was deleted.

ext/mysqli/tests/mysqli_class_mysqli_driver_interface.phpt

Lines changed: 67 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -3,81 +3,81 @@ Interface of the class mysqli_driver
33
--SKIPIF--
44
<?php
55
require_once('skipif.inc');
6-
require_once('skipifconnectfailure.inc');
76
?>
87
--FILE--
98
<?php
10-
require('connect.inc');
11-
require('table.inc');
129

13-
$driver = new mysqli_driver();
10+
$driver = new mysqli_driver();
1411

15-
printf("Parent class:\n");
16-
var_dump(get_parent_class($driver));
12+
printf("Parent class:\n");
13+
var_dump(get_parent_class($driver));
1714

18-
printf("\nMethods:\n");
19-
$methods = get_class_methods($driver);
20-
$expected_methods = array();
15+
printf("\nMethods:\n");
16+
$methods = get_class_methods($driver);
17+
$expected_methods = [];
2118

22-
foreach ($methods as $k => $method) {
23-
if (isset($expected_methods[$method])) {
24-
unset($expected_methods[$method]);
25-
unset($methods[$k]);
26-
}
19+
foreach ($methods as $k => $method) {
20+
if (isset($expected_methods[$method])) {
21+
unset($expected_methods[$method], $methods[$k]);
2722
}
28-
if (!empty($expected_methods)) {
29-
printf("Dumping list of missing methods.\n");
30-
var_dump($expected_methods);
31-
}
32-
if (!empty($methods)) {
33-
printf("Dumping list of unexpected methods.\n");
34-
var_dump($methods);
35-
}
36-
if (empty($expected_methods) && empty($methods))
37-
printf("ok\n");
38-
39-
printf("\nClass variables:\n");
40-
$variables = array_keys(get_class_vars(get_class($driver)));
41-
sort($variables);
42-
foreach ($variables as $k => $var)
43-
printf("%s\n", $var);
44-
45-
printf("\nObject variables:\n");
46-
$variables = array_keys(get_object_vars($driver));
47-
foreach ($variables as $k => $var)
48-
printf("%s\n", $var);
49-
50-
printf("\nMagic, magic properties:\n");
51-
52-
assert(mysqli_get_client_info() === $driver->client_info);
53-
printf("driver->client_info = '%s'\n", $driver->client_info);
54-
55-
assert(mysqli_get_client_version() === $driver->client_version);
56-
printf("driver->client_version = '%s'\n", $driver->client_version);
57-
58-
assert($driver->driver_version > 0);
59-
printf("driver->driver_version = '%s'\n", $driver->driver_version);
60-
61-
assert(in_array($driver->report_mode,
62-
array(
63-
MYSQLI_REPORT_ALL,
64-
MYSQLI_REPORT_STRICT,
65-
MYSQLI_REPORT_ERROR,
66-
MYSQLI_REPORT_INDEX,
67-
MYSQLI_REPORT_OFF
68-
)
69-
));
70-
71-
printf("driver->report_mode = '%s'\n", $driver->report_mode);
72-
$driver->report_mode = MYSQLI_REPORT_STRICT;
73-
assert($driver->report_mode === MYSQLI_REPORT_STRICT);
74-
75-
printf("driver->reconnect = '%s'\n", $driver->reconnect);
76-
77-
printf("\nAccess to undefined properties:\n");
78-
printf("driver->unknown = '%s'\n", @$driver->unknown);
79-
80-
print "done!";
23+
}
24+
if (!empty($expected_methods)) {
25+
printf("Dumping list of missing methods.\n");
26+
var_dump($expected_methods);
27+
}
28+
if (!empty($methods)) {
29+
printf("Dumping list of unexpected methods.\n");
30+
var_dump($methods);
31+
}
32+
if (empty($expected_methods) && empty($methods)) {
33+
printf("ok\n");
34+
}
35+
36+
printf("\nClass variables:\n");
37+
$variables = array_keys(get_class_vars(get_class($driver)));
38+
sort($variables);
39+
foreach ($variables as $var) {
40+
printf("%s\n", $var);
41+
}
42+
43+
printf("\nObject variables:\n");
44+
$variables = array_keys(get_object_vars($driver));
45+
foreach ($variables as $var) {
46+
printf("%s\n", $var);
47+
}
48+
49+
printf("\nMagic, magic properties:\n");
50+
51+
assert(mysqli_get_client_info() === $driver->client_info);
52+
printf("driver->client_info = '%s'\n", $driver->client_info);
53+
54+
assert(mysqli_get_client_version() === $driver->client_version);
55+
printf("driver->client_version = '%s'\n", $driver->client_version);
56+
57+
assert($driver->driver_version > 0);
58+
printf("driver->driver_version = '%s'\n", $driver->driver_version);
59+
60+
assert(in_array($driver->report_mode, [
61+
MYSQLI_REPORT_ALL,
62+
MYSQLI_REPORT_STRICT,
63+
MYSQLI_REPORT_STRICT|MYSQLI_REPORT_ERROR,
64+
MYSQLI_REPORT_STRICT|MYSQLI_REPORT_INDEX,
65+
MYSQLI_REPORT_ERROR,
66+
MYSQLI_REPORT_ERROR|MYSQLI_REPORT_INDEX,
67+
MYSQLI_REPORT_INDEX,
68+
MYSQLI_REPORT_OFF
69+
]));
70+
71+
printf("driver->report_mode = '%s'\n", $driver->report_mode);
72+
$driver->report_mode = MYSQLI_REPORT_STRICT;
73+
assert($driver->report_mode === MYSQLI_REPORT_STRICT);
74+
75+
printf("driver->reconnect = '%s'\n", $driver->reconnect);
76+
77+
printf("\nAccess to undefined properties:\n");
78+
printf("driver->unknown = '%s'\n", @$driver->unknown);
79+
80+
print "done!";
8181
?>
8282
--EXPECTF--
8383
Parent class:

ext/mysqli/tests/mysqli_driver.phpt

Lines changed: 103 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -7,102 +7,123 @@ require_once('skipifconnectfailure.inc');
77
?>
88
--FILE--
99
<?php
10-
require("table.inc");
10+
require_once('connect.inc');
1111

12-
if (!is_object($driver = new mysqli_driver()))
13-
printf("[001] Failed to create mysqli_driver object\n");
12+
if (!is_object($driver = new mysqli_driver())) {
13+
printf("[001] Failed to create mysqli_driver object\n");
14+
}
1415

15-
$client_info = mysqli_get_client_info();
16-
if (($tmp = $driver->client_info) !== $client_info)
17-
printf("[002] Expecting %s/%s, got %s/%s\n",
18-
gettype($client_info), $client_info,
19-
gettype($tmp), $tmp);
20-
21-
$client_version = mysqli_get_client_version();
22-
if (($tmp = $driver->client_version) !== $client_version)
23-
printf("[003] Expecting %s/%s, got %s/%s\n",
24-
gettype($client_version), $client_version,
25-
gettype($tmp), $tmp);
26-
27-
if (!is_int($tmp = $driver->driver_version) || (0 == $tmp))
28-
printf("[004] Expecting int/any, got %s/%s\n",
16+
$client_info = mysqli_get_client_info();
17+
if (($tmp = $driver->client_info) !== $client_info) {
18+
printf("[002] Expecting %s/%s, got %s/%s\n",
19+
gettype($client_info), $client_info,
2920
gettype($tmp), $tmp);
30-
31-
32-
$all_modes = array(MYSQLI_REPORT_INDEX, MYSQLI_REPORT_ERROR, MYSQLI_REPORT_STRICT,
33-
MYSQLI_REPORT_ALL, MYSQLI_REPORT_OFF);
34-
$report_mode = $driver->report_mode;
35-
if (!is_int($report_mode))
36-
printf("[005] Expecting int/any, got %s/%s\n",
37-
gettype($report_mode), $report_mode);
38-
39-
if (!in_array($report_mode, $all_modes))
40-
printf("[006] Illegal report mode returned? Got %s, expected %s\n",
41-
$report_mode, implode(', ', $all_modes));
42-
43-
$driver->report_mode = MYSQLI_REPORT_STRICT;
44-
$ok = false;
45-
try {
46-
47-
if ($link = my_mysqli_connect($host, $user . 'unknown_really', $passwd . 'non_empty', $db, $port, $socket))
48-
printf("[007] Can connect to the server using host=%s, user=%s, passwd=***non_empty, dbname=%s, port=%s, socket=%s\n",
49-
$host, $user . 'unknown_really', $db, $port, $socket);
50-
mysqli_close($link);
51-
52-
} catch (mysqli_sql_exception $e) {
53-
$ok = true;
54-
if ('' == $e->getMessage())
55-
printf("[008] getMessage() has returned an empty string.\n");
56-
if ('' == $e->getCode())
57-
printf("[009] getCode() has returned an empty string.\n");
58-
if ('' == $e->getFile())
59-
printf("[010] getFile() has returned an empty string.\n");
60-
if ('' == $e->getLine())
61-
printf("[011] getLine() has returned an empty string.\n");
62-
$tmp = $e->getTrace();
63-
if (empty($tmp))
64-
printf("[012] getTrace() has returned an empty array.\n");
65-
if ('' == $e->getTraceAsString())
66-
printf("[013] getTraceAsString() has returned an empty string.\n");
67-
if ('' == $e->__toString())
68-
printf("[014] __toString() has returned an empty string.\n");
69-
21+
}
22+
23+
$client_version = mysqli_get_client_version();
24+
if (($tmp = $driver->client_version) !== $client_version) {
25+
printf("[003] Expecting %s/%s, got %s/%s\n",
26+
gettype($client_version), $client_version,
27+
gettype($tmp), $tmp);
28+
}
29+
30+
if (!is_int($tmp = $driver->driver_version) || (0 == $tmp)) {
31+
printf("[004] Expecting int/any, got %s/%s\n",
32+
gettype($tmp), $tmp);
33+
}
34+
35+
$all_modes = [
36+
MYSQLI_REPORT_ALL,
37+
MYSQLI_REPORT_STRICT,
38+
MYSQLI_REPORT_STRICT|MYSQLI_REPORT_ERROR,
39+
MYSQLI_REPORT_STRICT|MYSQLI_REPORT_INDEX,
40+
MYSQLI_REPORT_ERROR,
41+
MYSQLI_REPORT_ERROR|MYSQLI_REPORT_INDEX,
42+
MYSQLI_REPORT_INDEX,
43+
MYSQLI_REPORT_OFF
44+
];
45+
$report_mode = $driver->report_mode;
46+
if (!is_int($report_mode)) {
47+
printf("[005] Expecting int/any, got %s/%s\n",
48+
gettype($report_mode), $report_mode);
49+
}
50+
51+
if (!in_array($report_mode, $all_modes)) {
52+
printf("[006] Illegal report mode returned? Got %s, expected %s\n",
53+
$report_mode, implode(', ', $all_modes));
54+
}
55+
56+
$driver->report_mode = MYSQLI_REPORT_STRICT;
57+
$ok = false;
58+
try {
59+
if ($link = my_mysqli_connect($host, $user . 'unknown_really', $passwd . 'non_empty', $db, $port, $socket)) {
60+
printf("[007] Can connect to the server using host=%s, user=%s, passwd=***non_empty, dbname=%s, port=%s, socket=%s\n",
61+
$host, $user . 'unknown_really', $db, $port, $socket);
7062
}
71-
if (!$ok)
72-
printf("[015] Error reporting mode has not been switched to exceptions and or no exception thrown\n");
73-
74-
75-
$driver->report_mode = MYSQLI_REPORT_OFF;
76-
if (!$link = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket))
77-
printf("[016] [%d] %s\n", mysqli_connect_errno(), mysqli_connect_error());
78-
mysqli_query($link, "NO_SQL");
7963
mysqli_close($link);
64+
} catch (mysqli_sql_exception $e) {
65+
$ok = true;
66+
if ('' == $e->getMessage()) {
67+
printf("[008] getMessage() has returned an empty string.\n");
68+
}
69+
if ('' == $e->getCode()) {
70+
printf("[009] getCode() has returned an empty string.\n");
71+
}
72+
if ('' == $e->getFile()) {
73+
printf("[010] getFile() has returned an empty string.\n");
74+
}
75+
if ('' == $e->getLine()) {
76+
printf("[011] getLine() has returned an empty string.\n");
77+
}
78+
if ([] == $e->getTrace()) {
79+
printf("[012] getTrace() has returned an empty array.\n");
80+
}
81+
if ('' == $e->getTraceAsString()) {
82+
printf("[013] getTraceAsString() has returned an empty string.\n");
83+
}
84+
if ('' == $e->__toString()) {
85+
printf("[014] __toString() has returned an empty string.\n");
86+
}
87+
}
88+
if (!$ok) {
89+
printf("[015] Error reporting mode has not been switched to exceptions and or no exception thrown\n");
90+
}
8091

81-
$driver->report_mode = MYSQLI_REPORT_ERROR;
92+
$driver->report_mode = MYSQLI_REPORT_OFF;
93+
if (!$link = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket)) {
94+
printf("[016] [%d] %s\n", mysqli_connect_errno(), mysqli_connect_error());
95+
}
96+
mysqli_query($link, "NO_SQL");
97+
mysqli_close($link);
8298

83-
if (!$link = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket))
84-
printf("[017] [%d] %s\n", mysqli_connect_errno(), mysqli_connect_error());
85-
mysqli_query($link, "NO_SQL");
86-
mysqli_close($link);
99+
$driver->report_mode = MYSQLI_REPORT_ERROR;
100+
101+
if (!$link = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket)) {
102+
printf("[017] [%d] %s\n", mysqli_connect_errno(), mysqli_connect_error());
103+
}
104+
mysqli_query($link, "NO_SQL");
105+
mysqli_close($link);
87106

88-
if (MYSQLI_REPORT_ERROR !== $driver->report_mode)
89-
printf("[018] Error mode should be different\n");
107+
if (MYSQLI_REPORT_ERROR !== $driver->report_mode) {
108+
printf("[018] Error reporting mode should be different\n");
109+
}
90110

91-
/* TODO - more report testing should go in here, but it's not really documented what behaviour is expected */
111+
/* TODO - more report testing should go in here, but it's not really documented what behaviour is expected */
92112

93-
$driver->report_mode = $report_mode;
113+
$driver->report_mode = $report_mode;
94114

95-
$reconnect = $driver->reconnect;
96-
if (!is_bool($reconnect))
115+
$reconnect = $driver->reconnect;
116+
if (!is_bool($reconnect)) {
97117
printf("[019] Expecting boolean/any, got %s/%s\n",
98-
gettype($reconnect), $reconnect);
118+
gettype($reconnect), $reconnect);
119+
}
99120

100-
/* pointless, but I need more documentation */
101-
$driver->reconnect = true;
102-
$driver->reconnect = false;
103-
$driver->reconnect = $reconnect;
121+
/* pointless, but I need more documentation */
122+
$driver->reconnect = true;
123+
$driver->reconnect = false;
124+
$driver->reconnect = $reconnect;
104125

105-
print "done!";
126+
print "done!";
106127
?>
107128
--EXPECTF--
108129
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

0 commit comments

Comments
 (0)