]> granicus.if.org Git - php/commitdiff
The last bunch of changes to the old 0*.phpt tests. Once final time a
authorUlf Wendel <uw@php.net>
Thu, 12 Jul 2007 21:02:21 +0000 (21:02 +0000)
committerUlf Wendel <uw@php.net>
Thu, 12 Jul 2007 21:02:21 +0000 (21:02 +0000)
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

15 files changed:
ext/mysqli/tests/060.phpt
ext/mysqli/tests/061.phpt
ext/mysqli/tests/062.phpt
ext/mysqli/tests/063.phpt
ext/mysqli/tests/064.phpt
ext/mysqli/tests/065.phpt
ext/mysqli/tests/066.phpt
ext/mysqli/tests/067.phpt
ext/mysqli/tests/068.phpt
ext/mysqli/tests/069.phpt
ext/mysqli/tests/070.phpt
ext/mysqli/tests/071.phpt
ext/mysqli/tests/072.phpt
ext/mysqli/tests/073.phpt
ext/mysqli/tests/074.phpt

index e06f25949db29c6099764fd0f365239aab277651..805bf569cd878a89a08e42b7b7fca20856fe5c51 100644 (file)
@@ -5,21 +5,21 @@ mysqli_fetch_object with classes
 --FILE--
 <?php
        include "connect.inc";
-       
+
        class test_class {
                function __construct($arg1, $arg2) {
                        echo __METHOD__ . "($arg1,$arg2)\n";
                }
        }
-       
+
        /*** test mysqli_connect 127.0.0.1 ***/
-       $link = mysqli_connect($host, $user, $passwd);
+       $link = mysqli_connect($host, $user, $passwd, $db, $port, $socket);
 
-       mysqli_select_db($link, "test");
+       mysqli_select_db($link, $db);
        mysqli_query($link, "SET sql_mode=''");
 
-       mysqli_query($link,"DROP TABLE IF EXISTS test_fetch");
-       mysqli_query($link,"CREATE TABLE test_fetch(c1 smallint unsigned,
+       mysqli_query($link,"DROP TABLE IF EXISTS test_fetch");
+       mysqli_query($link,"CREATE TABLE test_fetch(c1 smallint unsigned,
                                                      c2 smallint unsigned,
                                                      c3 smallint,
                                                      c4 smallint,
@@ -27,16 +27,16 @@ mysqli_fetch_object with classes
                                                      c6 smallint unsigned,
                                                      c7 smallint)");
 
-       mysqli_query($link, "INSERT INTO test_fetch VALUES ( -23, 35999, NULL, -500, -9999999, -0, 0)"); 
+       mysqli_query($link, "INSERT INTO test_fetch VALUES ( -23, 35999, NULL, -500, -9999999, -0, 0)");
 
-       $result = mysqli_query($link, "SELECT * FROM test_bind_fetch");
+       $result = mysqli_query($link, "SELECT * FROM test_fetch");
        $test = mysqli_fetch_object($result, 'test_class', array(1, 2));
        mysqli_free_result($result);
 
        var_dump($test);
 
        mysqli_close($link);
-       
+
        echo "Done\n";
 ?>
 --EXPECTF--
index 9516d0ce532e0c2322b5cf84d5f37d85cf3409bb..f0422ec6f72b5f8b715566a63b005ab15373aca0 100644 (file)
@@ -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
index cd1fc9b032220695dfed99e6008e0dabc2dcc57c..652f5cf47fc90e87aeb70af599cc3bb39d6cabf5 100644 (file)
@@ -1,12 +1,12 @@
 --TEST--
-resultset constructor 
+resultset constructor
 --SKIPIF--
 <?php require_once('skipif.inc'); ?>
 --FILE--
 <?php
        include "connect.inc";
 
-       $mysql = new mysqli($host, $user, $passwd);
+       $mysql = new mysqli($host, $user, $passwd, $db, $port, $socket);
 
        $mysql->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
index 86d66b1544542891202940ccb1b61b6761ec1cf4..9aedbc8d7f0251cfafb9a007a5d001342bc96eb5 100644 (file)
@@ -6,7 +6,7 @@ resultset constructor
 <?php
        include "connect.inc";
 
-       $mysql = new mysqli($host, $user, $passwd);
+       $mysql = new mysqli($host, $user, $passwd, $db, $port, $socket);
 
        $stmt = new mysqli_stmt($mysql, "SELECT 'foo' FROM DUAL");
        $stmt->execute();
index e6df1e450553b9edcc0dd76baea5cde9186ded98..6cdd3c6dac1706fdd50d0cb4106832d0bbc5ea8f 100644 (file)
@@ -6,7 +6,7 @@ NULL binding
 <?php
        include "connect.inc";
 
-       $mysql = new mysqli($host, $user, $passwd);
+       $mysql = new mysqli($host, $user, $passwd, $db, $port, $socket);
 
        $stmt = new mysqli_stmt($mysql, "SELECT NULL FROM DUAL");
        $stmt->execute();
index b064e744f4c82c693238c72b0468ad00befc58b6..80e3bbf92b0d82d79cb70df6c5b8b1664ca98069 100644 (file)
@@ -14,31 +14,40 @@ if (unicode_semantics()) {
 <?php
        include "connect.inc";
 
-       $mysql = new mysqli($host, $user, $passwd);
-       mysqli_query($mysql, "SET sql_mode=''");
+       if (!$mysql = new mysqli($host, $user, $passwd, $db, $port, $socket))
+          printf("[001] [%d] %s\n", mysqli_connect_errno(), mysqli_connect_error());
+          
+       if (!mysqli_query($mysql, "SET sql_mode=''"))
+          printf("[002] Cannot set SQL-Mode, [%d] %s\n", mysqli_errno($mysql), mysqli_error($mysql));
 
        $esc_str = chr(0xbf) . chr(0x5c);
+       $len = $charset = array();
+       $tmp = null;
 
        if ($mysql->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
index 01434f8d3fb2874a7e5f0870b93860abecba07e1..33ae64d5c6612150f0e502917676110c89156136 100644 (file)
@@ -6,16 +6,16 @@ function test: mysqli_warning object
 <?php
 
        include "connect.inc";
-       
+
        /*** test mysqli_connect 127.0.0.1 ***/
-       $mysql = new mysqli($host, $user, $passwd, "test");
+       $mysql = new mysqli($host, $user, $passwd, $db, $port, $socket);
 
        $mysql->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
index d58d24cfee2e4739163e5ef6d219aa1f571570cd..fd6016bd59fdcd8acea8434fc8dc4fa9405ef1ca 100644 (file)
@@ -1,38 +1,50 @@
 --TEST--
 function test: nested selects (cursors)
 --SKIPIF--
-<?php 
-       require_once('skipif.inc'); 
+<?php
+       require_once('skipif.inc');
+       include "connect.inc";
+
+       if (!$link = mysqli_connect($host, $user, $passwd, $db, $port, $socket))
+               die("skip Cannot connect to check required version");
+
        /* skip cursor test for versions < 50004 */
-       if (mysqli_get_client_version() < 50009) {
-               die("skip Client library doesn't support cursors");     
+       if ((!$IS_MYSQLND && mysqli_get_client_version() < 50009) ||
+            (mysqli_get_server_version($link) < 50009)) {
+                 die(sprintf("skip Client library doesn't support cursors (%s/%s)",
+                     mysqli_get_client_version(), mysqli_get_server_version($link));
        }
+       mysqli_close($link);
 ?>
 --FILE--
 <?php
 
        function open_cursor($mysql, $query) {
-               $stmt = $mysql->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
index c0baeced04aa0ac8532c5423eef0c96b2721c673..446fb2013bebe6efec8b5334cbe103ded5907353 100644 (file)
@@ -1,13 +1,11 @@
 --TEST--
 mysqli get_client_info
 --SKIPIF--
-<?php 
-       require_once('skipif.inc'); 
-?>
+<?php  require_once('skipif.inc'); ?>
 --FILE--
 <?php
-  $s = mysqli_get_client_info();
-  echo gettype($s);
+       $s = mysqli_get_client_info();
+       echo gettype($s);
 ?>
 --EXPECT--
 string
index 49502513ed942919612d6b560d4731a2cab06176..4088fe50b890efffe8f5eff6f9ad21a613f3998d 100644 (file)
@@ -6,29 +6,40 @@ mysqli multi_query, next_result, more_results
 <?php
        include "connect.inc";
 
-       $mysql = new mysqli($host, $user, $passwd, "test");
+       $mysql = new mysqli($host, $user, $passwd, $db, $port, $socket);
        $mysql->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
index 6122589ccad522b5d0a128d9311a835383f91b0b..dd666cc09ab62d9064d2cbf2ae059a817a4ae233 100644 (file)
@@ -6,9 +6,11 @@ mysqli ping
 <?php
        include "connect.inc";
 
-       $mysql = new mysqli($host, $user, $passwd, "test");
+       $mysql = new mysqli($host, $user, $passwd, $db, $port, $socket);
        var_dump($mysql->ping());
        $mysql->close();
+       print "done!";
 ?>
 --EXPECT--
 bool(true)
+done!
\ No newline at end of file
index 75ff3e850dd0c1c0a34eb1e74474add05ffe309d..365e2a8034755fd3d3d13f5d80d215b6aff4e55d 100644 (file)
@@ -7,7 +7,7 @@ mysqli thread_id & kill
 <?php
        include "connect.inc";
 
-       $mysql = new mysqli($host, $user, $passwd, "test");
+       $mysql = new mysqli($host, $user, $passwd, $db, $port, $socket);
 
        var_dump($mysql->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
index b3d847f30eee6f2718072d770b0cb0eb82703c90..df473f6f4f7f68d7e90195e8a3f9c30559debf29 100644 (file)
@@ -6,7 +6,7 @@ mysqli warning_count, get_warnings
 <?php
        include "connect.inc";
 
-       $mysql = new mysqli($host, $user, $passwd, "test");
+       $mysql = new mysqli($host, $user, $passwd, $db, $port, $socket);
 
        $mysql->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
index e4f9e49768b7267274fae723f45887dac61bfab8..80e77c2ad29eef168850b3f28a18922bc6313ac3 100644 (file)
@@ -6,18 +6,27 @@ mysqli_driver properties
 <?php
        include "connect.inc";
 
-    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);
-    
+       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
index 4150e81fe7b85996c5a09ad5027210d88595bed3..794f3572d5200325b09fde4b1e95659aabe3d007 100644 (file)
@@ -1,33 +1,42 @@
 --TEST--
 mysqli_autocommit() tests
 --SKIPIF--
-<?php 
-       require_once('skipif.inc'); 
-?>
+<?php require_once('skipif.inc'); ?>
 --FILE--
 <?php
 
-include "connect.inc";
+       include "connect.inc";
 
-$mysqli = new mysqli($host, $user, $passwd, "test");
+       $mysqli = new mysqli($host, $user, $passwd, $db, $port, $socket);
 
-var_dump($mysqli->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