From: Ulf Wendel Date: Thu, 12 Jul 2007 21:02:21 +0000 (+0000) Subject: The last bunch of changes to the old 0*.phpt tests. Once final time a X-Git-Tag: BEFORE_IMPORT_OF_MYSQLND~149 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=a4cd950dc8605d4fcc1b6f787c957f1253b0c338;p=php The last bunch of changes to the old 0*.phpt tests. Once final time a verbose explanation of changes: - take connection parameter from connect.inc - use proper UEXPECTF - have 'print "done!"' or similar at the end to detect crashes - whitespace changes where needed - take care of portability: PHP 5 vs. PHP 5, MySQL 4.1 - 6.0 - understand return value checking as sometime that makes you type more when you write but makes you happy when you debug --- diff --git a/ext/mysqli/tests/060.phpt b/ext/mysqli/tests/060.phpt index e06f25949d..805bf569cd 100644 --- a/ext/mysqli/tests/060.phpt +++ b/ext/mysqli/tests/060.phpt @@ -5,21 +5,21 @@ mysqli_fetch_object with classes --FILE-- --EXPECTF-- diff --git a/ext/mysqli/tests/061.phpt b/ext/mysqli/tests/061.phpt index 9516d0ce53..f0422ec6f7 100644 --- a/ext/mysqli/tests/061.phpt +++ b/ext/mysqli/tests/061.phpt @@ -10,34 +10,49 @@ local infile handler $buffer = strrev(fread($fp, $buflen)); return(strlen($buffer)); } - + /*** test mysqli_connect 127.0.0.1 ***/ - $link = mysqli_connect($host, $user, $passwd, "test"); + $link = mysqli_connect($host, $user, $passwd, $db, $port, $socket); /* create temporary file */ $filename = dirname(__FILE__) . "061.csv"; $fp = fopen($filename, "w"); - @fwrite($fp, "foo;bar"); + fwrite($fp, b"foo;bar"); fclose($fp); - mysqli_query($link,"DROP TABLE IF EXISTS t_061"); - mysqli_query($link,"CREATE TABLE t_061 (c1 varchar(10), c2 varchar(10))"); + if (!mysqli_query($link,"DROP TABLE IF EXISTS t_061")) + printf("Cannot drop table: [%d] %s\n", mysqli_errno($link), mysqli_error($link)); + if (!mysqli_query($link,"CREATE TABLE t_061 (c1 varchar(10), c2 varchar(10))")) + printf("Cannot create table: [%d] %s\n", mysqli_errno($link), mysqli_error($link)); - mysqli_query($link, "LOAD DATA LOCAL INFILE '{$filename}' INTO TABLE t_061 FIELDS TERMINATED BY ';'"); + if (!mysqli_query($link, sprintf("LOAD DATA LOCAL INFILE '%s' INTO TABLE t_061 FIELDS TERMINATED BY ';'", mysqli_real_escape_string($link, $filename)))) + printf("Cannot load data: [%d] %s\n", mysqli_errno($link), mysqli_error($link)); mysqli_set_local_infile_handler($link, "my_read"); - mysqli_query($link, "LOAD DATA LOCAL INFILE '{$filename}' INTO TABLE t_061 FIELDS TERMINATED BY ';'"); + if (!mysqli_query($link, sprintf("LOAD DATA LOCAL INFILE '%s' INTO TABLE t_061 FIELDS TERMINATED BY ';'", mysqli_real_escape_string($link, $filename)))) + printf("Cannot load data using infile handler: [%d] %s\n", mysqli_errno($link), mysqli_error($link)); if ($result = mysqli_query($link, "SELECT c1,c2 FROM t_061")) { while (($row = mysqli_fetch_row($result))) { printf("%s-%s\n", $row[0], $row[1]); + printf("%s-%s\n", gettype($row[0]), gettype($row[1])); } mysqli_free_result($result); } mysqli_close($link); unlink($filename); + print "done!"; ?> --EXPECT-- foo-bar +string-string +rab-oof +string-string +done! +--UEXPECTF-- +foo-bar +unicode-unicode rab-oof +unicode-unicode +done! \ No newline at end of file diff --git a/ext/mysqli/tests/062.phpt b/ext/mysqli/tests/062.phpt index cd1fc9b032..652f5cf47f 100644 --- a/ext/mysqli/tests/062.phpt +++ b/ext/mysqli/tests/062.phpt @@ -1,12 +1,12 @@ --TEST-- -resultset constructor +resultset constructor --SKIPIF-- --FILE-- real_query("SELECT 'foo' FROM DUAL"); @@ -17,9 +17,17 @@ resultset constructor $mysql->close(); var_dump($row); + print "done!"; ?> --EXPECTF-- array(1) { [0]=> - %s(3) "foo" + string(3) "foo" } +done! +--UEXPECTF-- +array(1) { + [0]=> + unicode(3) "foo" +} +done! \ No newline at end of file diff --git a/ext/mysqli/tests/063.phpt b/ext/mysqli/tests/063.phpt index 86d66b1544..9aedbc8d7f 100644 --- a/ext/mysqli/tests/063.phpt +++ b/ext/mysqli/tests/063.phpt @@ -6,7 +6,7 @@ resultset constructor execute(); diff --git a/ext/mysqli/tests/064.phpt b/ext/mysqli/tests/064.phpt index e6df1e4505..6cdd3c6dac 100644 --- a/ext/mysqli/tests/064.phpt +++ b/ext/mysqli/tests/064.phpt @@ -6,7 +6,7 @@ NULL binding execute(); diff --git a/ext/mysqli/tests/065.phpt b/ext/mysqli/tests/065.phpt index b064e744f4..80e3bbf92b 100644 --- a/ext/mysqli/tests/065.phpt +++ b/ext/mysqli/tests/065.phpt @@ -14,31 +14,40 @@ if (unicode_semantics()) { set_charset("latin1")) { /* 5C should be escaped */ - $len[0] = strlen($mysql->real_escape_string($esc_str)); - $charset[0] = $mysql->client_encoding(); + if (3 !== ($tmp = strlen($mysql->real_escape_string($esc_str)))) + printf("[003] Expecting 3/int got %s/%s\n", gettype($tmp), $tmp); + + if ('latin1' !== ($tmp = $mysql->client_encoding())) + printf("[004] Expecting latin1/string got %s/%s\n", gettype($tmp), $tmp); } - if ($mysql->set_charset("gbk")) { - /* nothing should be escaped, it's a valid gbk character */ - $len[1] = strlen($mysql->real_escape_string($esc_str)); - $charset[1] = $mysql->client_encoding(); + if ($res = $mysql->query("SHOW CHARACTER SET LIKE 'gbk'")) { + $res->free_result(); + if ($mysql->set_charset("gbk")) { + /* nothing should be escaped, it's a valid gbk character */ + + if (2 !== ($tmp = strlen($mysql->real_escape_string($esc_str)))) + printf("[005] Expecting 2/int got %s/%s\n", gettype($tmp), $tmp); + + if ('gbk' !== ($tmp = $mysql->client_encoding())) + printf("[005] Expecting gbk/string got %s/%s\n", gettype($tmp), $tmp);; + } } - $mysql->close(); - var_dump($len[0]); - var_dump($len[1]); - var_dump($charset[0]); - var_dump($charset[1]); + + print "done!"; ?> --EXPECT-- -int(3) -int(2) -string(6) "latin1" -string(3) "gbk" +done! \ No newline at end of file diff --git a/ext/mysqli/tests/066.phpt b/ext/mysqli/tests/066.phpt index 01434f8d3f..33ae64d5c6 100644 --- a/ext/mysqli/tests/066.phpt +++ b/ext/mysqli/tests/066.phpt @@ -6,16 +6,16 @@ function test: mysqli_warning object query("DROP TABLE IF EXISTS test_warnings"); - $mysql->query("CREATE TABLE test_warnings (a int not null)"); + $mysql->query("CREATE TABLE test_warnings (a int not null) ENGINE=myisam"); $mysql->query("INSERT INTO test_warnings VALUES (1),(2),(NULL)"); - + if (($warning = new mysqli_warning($mysql))) { do { printf("Warning\n"); @@ -23,6 +23,8 @@ function test: mysqli_warning object } $mysql->close(); + print "done!"; ?> --EXPECT-- Warning +done! \ No newline at end of file diff --git a/ext/mysqli/tests/067.phpt b/ext/mysqli/tests/067.phpt index d58d24cfee..fd6016bd59 100644 --- a/ext/mysqli/tests/067.phpt +++ b/ext/mysqli/tests/067.phpt @@ -1,38 +1,50 @@ --TEST-- function test: nested selects (cursors) --SKIPIF-- - --FILE-- prepare($query); + if (!is_object($stmt = $mysql->prepare($query))) { + printf("[001] Cannot create statement object for '%s', [%d] %s\n", + $query, $mysql->errno, $mysql->error); + } + $stmt->attr_set(MYSQLI_STMT_ATTR_CURSOR_TYPE, MYSQLI_CURSOR_TYPE_READ_ONLY); return $stmt; } include "connect.inc"; $a = array(); - + /*** test mysqli_connect 127.0.0.1 ***/ - $mysql = new mysqli($host, $user, $passwd, "test"); + $mysql = new mysqli($host, $user, $passwd, $db, $port, $socket); for ($i=0;$i < 3; $i++) { $mysql->query("DROP TABLE IF EXISTS cursor$i"); - $mysql->query("CREATE TABLE cursor$i (a int not null)"); + $mysql->query("CREATE TABLE cursor$i (a int not null) ENGINE=" . $engine); $mysql->query("INSERT INTO cursor$i VALUES (1),(2),(3),(4),(5),(6)"); $stmt[$i] = open_cursor($mysql, "SELECT a FROM cursor$i"); $stmt[$i]->execute(); $stmt[$i]->bind_result($a[$i]); } - + $cnt = 0; while ($stmt[0]->fetch()) { $stmt[1]->fetch(); @@ -48,4 +60,4 @@ function test: nested selects (cursors) var_dump($cnt); ?> --EXPECT-- -int(63) +int(63) \ No newline at end of file diff --git a/ext/mysqli/tests/068.phpt b/ext/mysqli/tests/068.phpt index c0baeced04..446fb2013b 100644 --- a/ext/mysqli/tests/068.phpt +++ b/ext/mysqli/tests/068.phpt @@ -1,13 +1,11 @@ --TEST-- mysqli get_client_info --SKIPIF-- - + --FILE-- --EXPECT-- string diff --git a/ext/mysqli/tests/069.phpt b/ext/mysqli/tests/069.phpt index 49502513ed..4088fe50b8 100644 --- a/ext/mysqli/tests/069.phpt +++ b/ext/mysqli/tests/069.phpt @@ -6,29 +6,40 @@ mysqli multi_query, next_result, more_results multi_query('SELECT 1;SELECT 2'); do { - $res = $mysql->store_result(); + $res = $mysql->store_result(); if ($mysql->errno == 0) { while ($arr = $res->fetch_assoc()) { var_dump($arr); } $res->free(); } - if ($mysql->more_results()) { - echo "---\n"; + if (!$mysql->more_results()) { + break; } - } while ($mysql->next_result()); + } while (@$mysql->next_result()); $mysql->close(); + print "done!"; ?> --EXPECTF-- array(1) { [1]=> - %s(1) "1" + string(1) "1" } ---- array(1) { [2]=> - %s(1) "2" + string(1) "2" } +done! +--UEXPECTF-- +array(1) { + [1]=> + unicode(1) "1" +} +array(1) { + [2]=> + unicode(1) "2" +} +done! \ No newline at end of file diff --git a/ext/mysqli/tests/070.phpt b/ext/mysqli/tests/070.phpt index 6122589cca..dd666cc09a 100644 --- a/ext/mysqli/tests/070.phpt +++ b/ext/mysqli/tests/070.phpt @@ -6,9 +6,11 @@ mysqli ping ping()); $mysql->close(); + print "done!"; ?> --EXPECT-- bool(true) +done! \ No newline at end of file diff --git a/ext/mysqli/tests/071.phpt b/ext/mysqli/tests/071.phpt index 75ff3e850d..365e2a8034 100644 --- a/ext/mysqli/tests/071.phpt +++ b/ext/mysqli/tests/071.phpt @@ -7,7 +7,7 @@ mysqli thread_id & kill ping()); @@ -17,7 +17,7 @@ mysqli thread_id & kill $mysql->close(); - $mysql = new mysqli($host, $user, $passwd, "test"); + $mysql = new mysqli($host, $user, $passwd, $db, $port, $socket); var_dump(mysqli_ping($mysql)); @@ -26,6 +26,7 @@ mysqli thread_id & kill var_dump(mysqli_ping($mysql)); $mysql->close(); + print "done!"; ?> --EXPECT-- bool(true) @@ -34,3 +35,4 @@ bool(false) bool(true) bool(true) bool(false) +done! \ No newline at end of file diff --git a/ext/mysqli/tests/072.phpt b/ext/mysqli/tests/072.phpt index b3d847f30e..df473f6f4f 100644 --- a/ext/mysqli/tests/072.phpt +++ b/ext/mysqli/tests/072.phpt @@ -6,7 +6,7 @@ mysqli warning_count, get_warnings query("DROP TABLE IF EXISTS not_exists"); @@ -19,9 +19,17 @@ mysqli warning_count, get_warnings var_dump($w->sqlstate); $mysql->close(); + echo "done!" ?> ---EXPECT-- +--EXPECTF-- int(1) int(1051) string(26) "Unknown table 'not_exists'" string(5) "HY000" +done! +--UEXPECTF-- +int(1) +int(1051) +unicode(26) "Unknown table 'not_exists'" +unicode(5) "HY000" +done! \ No newline at end of file diff --git a/ext/mysqli/tests/073.phpt b/ext/mysqli/tests/073.phpt index e4f9e49768..80e77c2ad2 100644 --- a/ext/mysqli/tests/073.phpt +++ b/ext/mysqli/tests/073.phpt @@ -6,18 +6,27 @@ mysqli_driver properties embedded); - var_dump( $driver->client_version); - var_dump( $driver->client_info); - var_dump( $driver->driver_version); - var_dump( $driver->reconnect); - var_dump( $driver->report_mode); - + var_dump($driver->embedded); + 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-- bool(%s) int(%d) -%s(%d) "%s" +string(%d) "%s" int(%d) bool(%s) int(%d) +done! +--UEXPECTF-- +bool(%s) +int(%d) +unicode(%d) "%s" +int(%d) +bool(%s) +int(%d) +done! \ No newline at end of file diff --git a/ext/mysqli/tests/074.phpt b/ext/mysqli/tests/074.phpt index 4150e81fe7..794f3572d5 100644 --- a/ext/mysqli/tests/074.phpt +++ b/ext/mysqli/tests/074.phpt @@ -1,33 +1,42 @@ --TEST-- mysqli_autocommit() tests --SKIPIF-- - + --FILE-- autocommit(false)); -$result = $mysqli->query("SELECT @@autocommit"); -var_dump($result->fetch_row()); + var_dump($mysqli->autocommit(false)); + $result = $mysqli->query("SELECT @@autocommit"); + var_dump($result->fetch_row()); -var_dump($mysqli->autocommit(true)); -$result = $mysqli->query("SELECT @@autocommit"); -var_dump($result->fetch_row()); + var_dump($mysqli->autocommit(true)); + $result = $mysqli->query("SELECT @@autocommit"); + var_dump($result->fetch_row()); ?> --EXPECTF-- bool(true) array(1) { [0]=> - %s(1) "0" + string(1) "0" +} +bool(true) +array(1) { + [0]=> + string(1) "1" } +--UEXPECTF-- bool(true) array(1) { [0]=> - %s(1) "1" + unicode(1) "0" } +bool(true) +array(1) { + [0]=> + unicode(1) "1" +} \ No newline at end of file