Skip to content

Commit aab36a7

Browse files
committed
Tidy up new my_mysqli in tests
1 parent 1451b9e commit aab36a7

13 files changed

+26
-57
lines changed

ext/mysqli/tests/065.phpt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@ require_once 'skipifconnectfailure.inc';
1010
<?php
1111
require_once 'connect.inc';
1212

13-
if (!$mysql = new my_mysqli($host, $user, $passwd, $db, $port, $socket))
14-
printf("[001] [%d] %s\n", mysqli_connect_errno(), mysqli_connect_error());
13+
$mysql = new my_mysqli($host, $user, $passwd, $db, $port, $socket);
1514

1615
if (!mysqli_query($mysql, "SET sql_mode=''"))
1716
printf("[002] Cannot set SQL-Mode, [%d] %s\n", mysqli_errno($mysql), mysqli_error($mysql));

ext/mysqli/tests/connect.inc

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,12 +67,22 @@
6767
public function __construct($host, $user, $passwd, $db, $port, $socket, $enable_env_flags = true) {
6868
$flags = ($enable_env_flags) ? get_environment_connection_flags() : 0;
6969

70+
// Because the tests are meant to test both error modes, they can set the report_mode to a different value,
71+
// which we do not want to override. However, we want to make sure that if a connection cannot be made,
72+
// the constuctor will throw an exception. We store current report_mode in variable and restore it later.
73+
$driver = new mysqli_driver;
74+
$report_mode = $driver->report_mode;
75+
$driver->report_mode = MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT;
76+
7077
if ($flags !== 0) {
7178
parent::__construct();
7279
$this->real_connect($host, $user, $passwd, $db, $port, $socket, $flags);
7380
} else {
7481
parent::__construct($host, $user, $passwd, $db, $port, $socket);
7582
}
83+
84+
// Restore error mode
85+
$driver->report_mode = $report_mode;
7686
}
7787
}
7888

ext/mysqli/tests/mysqli_affected_rows_oo.phpt

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,7 @@ mysqli
1717
echo $exception->getMessage() . "\n";
1818
}
1919

20-
if (!$mysqli = new my_mysqli($host, $user, $passwd, $db, $port, $socket)) {
21-
printf("[001] Cannot connect to the server using host=%s, user=%s, passwd=***, dbname=%s, port=%s, socket=%s\n",
22-
$host, $user, $db, $port, $socket);
23-
}
20+
$mysqli = new my_mysqli($host, $user, $passwd, $db, $port, $socket);
2421

2522
if (0 !== ($tmp = $mysqli->affected_rows))
2623
printf("[002] Expecting int/0, got %s/%s\n", gettype($tmp), $tmp);

ext/mysqli/tests/mysqli_autocommit_oo.phpt

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,7 @@ mysqli
1717
<?php
1818
require_once 'connect.inc';
1919

20-
if (!$mysqli = new my_mysqli($host, $user, $passwd, $db, $port, $socket)) {
21-
printf("[001] Cannot connect to the server using host=%s, user=%s, passwd=***, dbname=%s, port=%s, socket=%s\n",
22-
$host, $user, $db, $port, $socket);
23-
}
20+
$mysqli = new my_mysqli($host, $user, $passwd, $db, $port, $socket);
2421

2522
if (!is_bool($tmp = $mysqli->autocommit(true)))
2623
printf("[002] Expecting boolean/any, got %s/%s\n", gettype($tmp), $tmp);

ext/mysqli/tests/mysqli_change_user_oo.phpt

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,7 @@ if (mysqli_get_server_version($link) >= 50600)
1818
$link = NULL;
1919
$tmp = NULL;
2020

21-
if (!$mysqli = new my_mysqli($host, $user, $passwd, $db, $port, $socket))
22-
printf("[001] Cannot connect to the server using host=%s, user=%s, passwd=***, dbname=%s, port=%s, socket=%s\n",
23-
$host, $user, $db, $port, $socket);
21+
$mysqli = new my_mysqli($host, $user, $passwd, $db, $port, $socket);
2422

2523
if (false !== ($tmp = $mysqli->change_user($user . '_unknown_really', $passwd . 'non_empty', $db)))
2624
printf("[006] Expecting false, got %s/%s\n", gettype($tmp), $tmp);
@@ -32,9 +30,7 @@ if (mysqli_get_server_version($link) >= 50600)
3230
printf("[008] Expecting false, got %s/%s\n", gettype($tmp), $tmp);
3331

3432
// Reconnect because after 3 failed change_user attempts, the server blocks you off.
35-
if (!$mysqli = new my_mysqli($host, $user, $passwd, $db, $port, $socket))
36-
printf("[001] Cannot connect to the server using host=%s, user=%s, passwd=***, dbname=%s, port=%s, socket=%s\n",
37-
$host, $user, $db, $port, $socket);
33+
$mysqli = new my_mysqli($host, $user, $passwd, $db, $port, $socket);
3834

3935
if (!$mysqli->query('SET @mysqli_change_user_test_var=1'))
4036
printf("[009] Failed to set test variable: [%d] %s\n", $mysqli->errno, $mysqli->error);

ext/mysqli/tests/mysqli_character_set_name_oo.phpt

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,7 @@ require_once 'skipifconnectfailure.inc';
1111
/* NOTE: http://bugs.mysql.com/bug.php?id=7923 makes this test fail very likely on all 4.1.x - 5.0.x! */
1212
require_once 'connect.inc';
1313

14-
$tmp = NULL;
15-
$link = NULL;
16-
17-
if (!$mysqli = new my_mysqli($host, $user, $passwd, $db, $port, $socket))
18-
printf("[001] Cannot connect to the server using host=%s, user=%s, passwd=***, dbname=%s, port=%s, socket=%s\n",
19-
$host, $user, $db, $port, $socket);
14+
$mysqli = new my_mysqli($host, $user, $passwd, $db, $port, $socket);
2015

2116
if (!$res = $mysqli->query('SELECT version() AS server_version'))
2217
printf("[003] [%d] %s\n", $mysqli->errno, $mysqli->error);

ext/mysqli/tests/mysqli_close_oo.phpt

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,7 @@ require_once 'skipifconnectfailure.inc';
1010
<?php
1111
require_once 'connect.inc';
1212

13-
$tmp = NULL;
14-
$link = NULL;
15-
16-
if (!$mysqli = new my_mysqli($host, $user, $passwd, $db, $port, $socket))
17-
printf("[001] Cannot connect to the server using host=%s, user=%s, passwd=***, dbname=%s, port=%s, socket=%s\n",
18-
$host, $user, $db, $port, $socket);
13+
$mysqli = new my_mysqli($host, $user, $passwd, $db, $port, $socket);
1914

2015
$tmp = $mysqli->close();
2116
if (true !== $tmp)

ext/mysqli/tests/mysqli_commit_oo.phpt

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,20 +15,14 @@ if (!have_innodb($link))
1515
<?php
1616
require_once 'connect.inc';
1717

18-
$tmp = NULL;
19-
$link = NULL;
20-
2118
$mysqli = new mysqli();
2219
try {
2320
$mysqli->commit();
2421
} catch (Error $exception) {
2522
echo $exception->getMessage() . "\n";
2623
}
2724

28-
if (!$mysqli = new my_mysqli($host, $user, $passwd, $db, $port, $socket)) {
29-
printf("[001] Cannot connect to the server using host=%s, user=%s, passwd=***, dbname=%s, port=%s, socket=%s\n",
30-
$host, $user, $db, $port, $socket);
31-
}
25+
$mysqli = new my_mysqli($host, $user, $passwd, $db, $port, $socket);
3226

3327
if (true !== ($tmp = $mysqli->commit())) {
3428
printf("[002] Expecting boolean/true got %s/%s\n", gettype($tmp), $tmp);

ext/mysqli/tests/mysqli_connect_twice.phpt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,7 @@ require_once 'skipifconnectfailure.inc';
3535

3636
mysqli_close($link);
3737

38-
if (!$link = new my_mysqli($host, $user, $passwd, $db, $port, $socket))
39-
printf("[007] Cannot connect to the server using host=%s, user=%s, passwd=***, dbname=%s, port=%s, socket=%s\n",
40-
$host, $user, $db, $port, $socket);
38+
$link = new my_mysqli($host, $user, $passwd, $db, $port, $socket);
4139

4240
if (!$thread_id = $link->thread_id)
4341
printf("[008] Cannot determine thread id, test will fail, [%d] %s\n", mysqli_errno($link), mysqli_error($link));

ext/mysqli/tests/mysqli_get_warnings.phpt

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,7 @@ if (!$TEST_EXPERIMENTAL)
8383
mysqli_close($link);
8484

8585

86-
if (!$mysqli = new my_mysqli($host, $user, $passwd, $db, $port, $socket))
87-
printf("[021] Cannot create mysqli object: [%d] %s\n", mysqli_connect_errno(), mysqli_connect_error());
86+
$mysqli = new my_mysqli($host, $user, $passwd, $db, $port, $socket);
8887

8988
if (!$mysqli->query("DROP TABLE IF EXISTS t1"))
9089
printf("[022] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
@@ -101,8 +100,7 @@ if (!$TEST_EXPERIMENTAL)
101100
printf("[026] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
102101

103102
/* Yes, I really want to check if the object property is empty */
104-
if (!$mysqli = new my_mysqli($host, $user, $passwd, $db, $port, $socket))
105-
printf("[027] Cannot create mysqli object: [%d] %s\n", mysqli_connect_errno(), mysqli_connect_error());
103+
$mysqli = new my_mysqli($host, $user, $passwd, $db, $port, $socket);
106104

107105
$warning = new mysqli_warning($mysqli);
108106
if (false !== ($tmp = $warning->next()))
@@ -111,8 +109,7 @@ if (!$TEST_EXPERIMENTAL)
111109
if ('' != ($tmp = $warning->message))
112110
printf("[029] Expecting string/empty, got %s/%s\n", gettype($tmp), $tmp);
113111

114-
if (!$mysqli = new my_mysqli($host, $user, $passwd, $db, $port, $socket))
115-
printf("[030] Cannot create mysqli object: [%d] %s\n", mysqli_connect_errno(), mysqli_connect_error());
112+
$mysqli = new my_mysqli($host, $user, $passwd, $db, $port, $socket);
116113

117114
if (!$mysqli->query("DROP TABLE IF EXISTS t1"))
118115
printf("[031] [%d] %s\n", mysqli_errno($link), mysqli_error($link));

ext/mysqli/tests/mysqli_pconn_conn_multiple.phpt

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,7 @@ mysqli.max_links=-1
4141

4242
mysqli_close($link);
4343

44-
if (!$link = new my_mysqli($phost, $user, $passwd, $db, $port, $socket))
45-
printf("[007] Cannot connect to the server using host=%s, user=%s, passwd=***, dbname=%s, port=%s, socket=%s\n",
46-
$phost, $user, $db, $port, $socket);
44+
$link = new my_mysqli($host, $user, $passwd, $db, $port, $socket);
4745

4846
if (!$thread_id = $link->thread_id)
4947
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
103101

104102
mysqli_close($link);
105103

106-
if (!$link = new my_mysqli($host, $user, $passwd, $db, $port, $socket))
107-
printf("[022] Cannot connect to the server using host=%s, user=%s, passwd=***, dbname=%s, port=%s, socket=%s\n",
108-
$host, $user, $db, $port, $socket);
104+
$link = new my_mysqli($host, $user, $passwd, $db, $port, $socket);
109105

110106
if (!$thread_id = $link->thread_id)
111107
printf("[023] Cannot determine thread id, test will fail, [%d] %s\n", mysqli_errno($link), mysqli_error($link));

ext/mysqli/tests/mysqli_pconn_twice.phpt

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,7 @@ mysqli.max_links=-1
3434

3535
mysqli_close($link);
3636

37-
if (!$link = new my_mysqli($host, $user, $passwd, $db, $port, $socket))
38-
printf("[007] Cannot connect to the server using host=%s, user=%s, passwd=***, dbname=%s, port=%s, socket=%s\n",
39-
$host, $user, $db, $port, $socket);
40-
37+
$link = new my_mysqli($host, $user, $passwd, $db, $port, $socket);
4138

4239
if (true !== ($tmp = $link->real_connect($host, $user, $passwd, $db, $port, $socket)))
4340
printf("[009] Expecting boolean/true got %s/%s\n", gettype($tmp), $tmp);

ext/mysqli/tests/mysqli_prepare_no_object.phpt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,7 @@ require_once 'skipifconnectfailure.inc';
2020

2121
mysqli_close($link);
2222

23-
if (!$mysqli = new my_mysqli($host, $user, $passwd, $db, $port, $socket))
24-
printf("[003] Cannot connect to the server using host=%s, user=%s, passwd=***, dbname=%s, port=%s, socket=%s\n",
25-
$host, $user, $db, $port, $socket);
23+
$mysqli = new my_mysqli($host, $user, $passwd, $db, $port, $socket);
2624

2725
if (false !== ($tmp = $mysqli->prepare(false)))
2826
printf("[004] Expecting boolean/false, got %s/%s\n", gettype($tmp), (is_object($tmp) ? var_dump($tmp, true) : $tmp));

0 commit comments

Comments
 (0)