Skip to content

Commit 5f6bf3e

Browse files
committed
Improve mysqli_character_set_name tests
1 parent f957335 commit 5f6bf3e

File tree

2 files changed

+55
-97
lines changed

2 files changed

+55
-97
lines changed

ext/mysqli/tests/mysqli_character_set_name.phpt

Lines changed: 27 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
--TEST--
2-
mysqli_character_set_name(), mysql_client_encoding() [alias]
2+
mysqli_character_set_name()
33
--EXTENSIONS--
44
mysqli
55
--SKIPIF--
@@ -8,55 +8,37 @@ require_once 'skipifconnectfailure.inc';
88
?>
99
--FILE--
1010
<?php
11-
/* NOTE: http://bugs.mysql.com/bug.php?id=7923 makes this test fail very likely on all 4.1.x - 5.0.x! */
12-
require_once 'connect.inc';
13-
14-
if (!$link = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket))
15-
printf("[005] Cannot connect to the server using host=%s, user=%s, passwd=***, dbname=%s, port=%s, socket=%s\n",
16-
$host, $user, $db, $port, $socket);
17-
18-
if (!$res = mysqli_query($link, 'SELECT version() AS server_version'))
19-
printf("[005] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
20-
$tmp = mysqli_fetch_assoc($res);
21-
mysqli_free_result($res);
22-
$version = explode('.', $tmp['server_version']);
23-
if (empty($version))
24-
printf("[006] Cannot determine server version, need MySQL Server 4.1+ for the test!\n");
25-
26-
if ($version[0] <= 4 && $version[1] < 1)
27-
printf("[007] Need MySQL Server 4.1+ for the test!\n");
28-
29-
if (!$res = mysqli_query($link, 'SELECT @@character_set_connection AS charset, @@collation_connection AS collation'))
30-
printf("[008] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
31-
$tmp = mysqli_fetch_assoc($res);
32-
mysqli_free_result($res);
33-
if (!$tmp['charset'])
34-
printf("[009] Cannot determine current character set and collation\n");
35-
36-
$charset = mysqli_character_set_name($link);
37-
if ($tmp['charset'] !== $charset) {
38-
if ($tmp['collation'] === $charset) {
39-
printf("[010] Could be known server bug http://bugs.mysql.com/bug.php?id=7923, collation %s instead of character set returned, expected string/%s, got %s/%s\n",
11+
/* NOTE: http://bugs.mysql.com/bug.php?id=7923 makes this test fail very likely on all 4.1.x - 5.0.x! */
12+
require_once 'connect.inc';
13+
14+
$link = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket);
15+
16+
if (!$res = mysqli_query($link, 'SELECT @@character_set_connection AS charset, @@collation_connection AS collation'))
17+
printf("[001] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
18+
$tmp = mysqli_fetch_assoc($res);
19+
mysqli_free_result($res);
20+
if (!$tmp['charset'])
21+
printf("[002] Cannot determine current character set and collation\n");
22+
23+
$charset = mysqli_character_set_name($link);
24+
if ($tmp['charset'] !== $charset) {
25+
if ($tmp['collation'] === $charset) {
26+
printf("[003] Could be known server bug http://bugs.mysql.com/bug.php?id=7923, collation %s instead of character set returned, expected string/%s, got %s/%s\n",
4027
$tmp['collation'], $tmp['charset'], gettype($charset), $charset);
41-
} else {
42-
printf("[011] Expecting character set %s/%s, got %s/%s\n", gettype($tmp['charset']), $tmp['charset'], gettype($charset), $charset);
43-
}
44-
}
45-
46-
$charset2 = mysqli_character_set_name($link);
47-
if ($charset2 !== $charset) {
48-
printf("[012] Alias mysqli_character_set_name returned %s/%s, expected %s/%s\n", gettype($charset2), $charset2, gettype($charset), $charset);
28+
} else {
29+
printf("[004] Expecting character set %s/%s, got %s/%s\n", gettype($tmp['charset']), $tmp['charset'], gettype($charset), $charset);
4930
}
31+
}
5032

51-
mysqli_close($link);
33+
mysqli_close($link);
5234

53-
try {
54-
mysqli_character_set_name($link);
55-
} catch (Error $exception) {
56-
echo $exception->getMessage() . "\n";
57-
}
35+
try {
36+
mysqli_character_set_name($link);
37+
} catch (Error $exception) {
38+
echo $exception->getMessage() . "\n";
39+
}
5840

59-
print "done!";
41+
print "done!";
6042
?>
6143
--EXPECT--
6244
mysqli object is already closed
Lines changed: 28 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
--TEST--
2-
mysqli_character_set_name(), mysql_client_encoding() [alias]
2+
mysqli_character_set_name()
33
--EXTENSIONS--
44
mysqli
55
--SKIPIF--
@@ -8,62 +8,38 @@ require_once 'skipifconnectfailure.inc';
88
?>
99
--FILE--
1010
<?php
11-
/* NOTE: http://bugs.mysql.com/bug.php?id=7923 makes this test fail very likely on all 4.1.x - 5.0.x! */
12-
require_once 'connect.inc';
13-
14-
$mysqli = new my_mysqli($host, $user, $passwd, $db, $port, $socket);
15-
16-
if (!$res = $mysqli->query('SELECT version() AS server_version'))
17-
printf("[003] [%d] %s\n", $mysqli->errno, $mysqli->error);
18-
$tmp = $res->fetch_assoc();
19-
$res->free_result();
20-
$version = explode('.', $tmp['server_version']);
21-
if (empty($version))
22-
printf("[006] Cannot determine server version, need MySQL Server 4.1+ for the test!\n");
23-
24-
if ($version[0] <= 4 && $version[1] < 1)
25-
printf("[007] Need MySQL Server 4.1+ for the test!\n");
26-
27-
if (!$res = $mysqli->query('SELECT @@character_set_connection AS charset, @@collation_connection AS collation'))
28-
printf("[008] [%d] %s\n", $mysqli->errno, $mysqli->error);
29-
$tmp = $res->fetch_assoc();
30-
$res->free_result();
31-
if (!$tmp['charset'])
32-
printf("[009] Cannot determine current character set and collation\n");
33-
34-
$charset = $mysqli->character_set_name();
35-
if ($tmp['charset'] !== $charset) {
36-
if ($tmp['collation'] === $charset) {
37-
printf("[010] Could be known server bug http://bugs.mysql.com/bug.php?id=7923, collation %s instead of character set returned, expected string/%s, got %s/%s\n",
38-
$tmp['collation'], $tmp['charset'], gettype($charset), $charset);
39-
} else {
40-
printf("[011] Expecting character set %s/%s, got %s/%s\n", gettype($tmp['charset']), $tmp['charset'], gettype($charset), $charset);
41-
}
11+
/* NOTE: http://bugs.mysql.com/bug.php?id=7923 makes this test fail very likely on all 4.1.x - 5.0.x! */
12+
require_once 'connect.inc';
13+
14+
$mysqli = new my_mysqli($host, $user, $passwd, $db, $port, $socket);
15+
16+
if (!$res = $mysqli->query('SELECT @@character_set_connection AS charset, @@collation_connection AS collation'))
17+
printf("[001] [%d] %s\n", $mysqli->errno, $mysqli->error);
18+
$tmp = $res->fetch_assoc();
19+
$res->free_result();
20+
if (!$tmp['charset'])
21+
printf("[002] Cannot determine current character set and collation\n");
22+
23+
$charset = $mysqli->character_set_name();
24+
if ($tmp['charset'] !== $charset) {
25+
if ($tmp['collation'] === $charset) {
26+
printf("[003] Could be known server bug http://bugs.mysql.com/bug.php?id=7923, collation %s instead of character set returned, expected string/%s, got %s/%s\n",
27+
$tmp['collation'], $tmp['charset'], gettype($charset), $charset);
28+
} else {
29+
printf("[004] Expecting character set %s/%s, got %s/%s\n", gettype($tmp['charset']), $tmp['charset'], gettype($charset), $charset);
4230
}
31+
}
4332

44-
$charset2 = $mysqli->character_set_name();
45-
if ($charset2 !== $charset) {
46-
printf("[012] Alias mysqli_character_set_name returned %s/%s, expected %s/%s\n",
47-
gettype($charset2), $charset2, gettype($charset), $charset);
48-
}
33+
$mysqli->close();
4934

50-
$mysqli->close();
35+
try {
36+
$mysqli->character_set_name();
37+
} catch (Error $exception) {
38+
echo $exception->getMessage() . "\n";
39+
}
5140

52-
try {
53-
$mysqli->character_set_name();
54-
} catch (Error $exception) {
55-
echo $exception->getMessage() . "\n";
56-
}
57-
58-
try {
59-
$mysqli->character_set_name();
60-
} catch (Error $exception) {
61-
echo $exception->getMessage() . "\n";
62-
}
63-
64-
print "done!";
41+
print "done!";
6542
?>
6643
--EXPECT--
6744
my_mysqli object is already closed
68-
my_mysqli object is already closed
6945
done!

0 commit comments

Comments
 (0)