]> granicus.if.org Git - php/commitdiff
Starting to merge updated set of tests into 5.3.
authorUlf Wendel <uw@php.net>
Wed, 10 Oct 2007 10:04:46 +0000 (10:04 +0000)
committerUlf Wendel <uw@php.net>
Wed, 10 Oct 2007 10:04:46 +0000 (10:04 +0000)
ext/mysqli/tests/connect.inc
ext/mysqli/tests/local_infile_tools.inc [new file with mode: 0644]
ext/mysqli/tests/reflection_tools.inc [new file with mode: 0644]
ext/mysqli/tests/skipif.inc
ext/mysqli/tests/skipifconnectfailure.inc [new file with mode: 0755]
ext/mysqli/tests/skipifemb.inc
ext/mysqli/tests/skipifnotemb.inc
ext/mysqli/tests/skipifunicode.inc [new file with mode: 0644]
ext/mysqli/tests/table.inc [new file with mode: 0644]

index ea24ff89ae4e8d40c57ce74b16242517acb9151d..5db701d93ba98efca0fec3b5f5aacfda8b11e9d3 100644 (file)
@@ -1,25 +1,54 @@
 <?php
+       /*
+       Default values are "localhost", "root",
+       database "phptest" and empty password.
+       Change the MYSQL_TEST environment values
+       if you want to use another configuration
+       */
 
-  /* default values are localhost, root and empty password 
-     Change the values if you use another configuration   */
-       $driver = new mysqli_driver;
+       $driver    = new mysqli_driver;
 
-       if (!$driver->embedded) {
-               $host = "localhost";
-               $user = "root";
-               $passwd = "";
+       $host      = getenv("MYSQL_TEST_HOST")     ? getenv("MYSQL_TEST_HOST") : "localhost";
+       $port      = getenv("MYSQL_TEST_PORT")     ? getenv("MYSQL_TEST_PORT") : 3306;
+       $user      = getenv("MYSQL_TEST_USER")     ? getenv("MYSQL_TEST_USER") : "root";
+       $passwd    = getenv("MYSQL_TEST_PASSWD")   ? getenv("MYSQL_TEST_PASSWD") : "";
+       $db        = getenv("MYSQL_TEST_DB")       ? getenv("MYSQL_TEST_DB") : "phptest";
+       $engine    = getenv("MYSQL_TEST_ENGINE")   ? getenv("MYSQL_TEST_ENGINE") : "MyISAM";
+       $socket    = getenv("MYSQL_TEST_SOCKET")   ? getenv("MYSQL_TEST_SOCKET") : null;
+
+       /* Development setting: test experimal features and/or feature requests that never worked before? */
+       $TEST_EXPERIMENTAL = (in_array(getenv("MYSQL_TEST_EXPERIMENTAL"), array(0, 1))) ?
+                               ((1 == getenv("MYSQL_TEST_EXPERIMENTAL")) ? true : false) :
+                               false;
+
+       $IS_MYSQLND = stristr(mysqli_get_client_info(), "mysqlnd");
+       if (!$IS_MYSQLND) {
+               $MYSQLND_VERSION = NULL;
        } else {
-               $path =  dirname(__FILE__);
-               $host = ":embedded";
-               $user = $passwd = NULL;
-               $args = array(
-                                       "--datadir=$path", 
-                                       "--innodb_data_home_dir=$path",
-                                       "--innodb_data_file_path=ibdata1:10M:autoextend",
-                                       "--log-error=$path/testrun.log",
-                                        "--init-connect='CREATE DATABASE IF NOT EXISTS test;'"
-                               );
-               $driver->embedded_server_start(TRUE, $args, NULL);
+               if (preg_match('@Revision:\s+(\d+)\s*\$@ism', mysqli_get_client_info(), $matches)) {
+                       $MYSQLND_VERSION = (int)$matches[1];
+               } else {
+                       $MYSQLND_VERSION = -1;
+               }
        }
 
-?>
+       if (!function_exists('sys_get_temp_dir')) {
+               function sys_get_temp_dir() {
+
+                       if (!empty($_ENV['TMP']))
+                               return realpath( $_ENV['TMP'] );
+                       if (!empty($_ENV['TMPDIR']))
+                               return realpath( $_ENV['TMPDIR'] );
+                       if (!empty($_ENV['TEMP']))
+                               return realpath( $_ENV['TEMP'] );
+
+                       $temp_file = tempnam(md5(uniqid(rand(), TRUE)), '');
+                       if ($temp_file) {
+                               $temp_dir = realpath(dirname($temp_file));
+                               unlink($temp_file);
+                               return $temp_dir;
+                       }
+                       return FALSE;
+               }
+       }
+?>
\ No newline at end of file
diff --git a/ext/mysqli/tests/local_infile_tools.inc b/ext/mysqli/tests/local_infile_tools.inc
new file mode 100644 (file)
index 0000000..d740b82
--- /dev/null
@@ -0,0 +1,111 @@
+<?php
+       /* Utility function for mysqli_set_local_infile*.phpt tests */
+       function shutdown_clean($file) {
+               if ($file) {
+                       unlink($file);
+               }
+       }
+
+       function create_standard_csv($offset) {
+               // create a CVS file
+               $file = tempnam(sys_get_temp_dir(), 'mysqli_test');
+               if (!$fp = fopen($file, 'w')) {
+                       printf("[%03d + 1] Cannot create CVS file '%s'\n", $offset, $file);
+                       return NULL;
+               } else {
+                       /* Looks ugly? No, handy if you have crashes... */
+                       register_shutdown_function("shutdown_clean", $file);
+               }
+
+               if (ini_get('unicode.semantics')) {
+                       if (!fwrite($fp, (binary)"'97';'x';\n") ||
+                               !fwrite($fp, (binary)"'98';'y';\n") ||
+                               !fwrite($fp, (binary)"99;'z';\n")) {
+                               printf("[%03d + 2] Cannot write CVS file '%s'\n", $offset, $file);
+                               return NULL;
+                       }
+               } else {
+                       if (!fwrite($fp, "97;'x';\n") ||
+                               !fwrite($fp, "98;'y';\n") ||
+                               !fwrite($fp, "99;'z';\n")) {
+                               printf("[%03d + 3] Cannot write CVS file '%s'\n", $offset, $file);
+                               return NULL;
+                       }
+               }
+
+               fclose($fp);
+
+               if (!chmod($file, 0644)) {
+                       printf("[%03d + 4] Cannot change the file perms of '%s' from 0600 to 0644, MySQL might not be able to read it\n",
+                               $offset, $file);
+                       return NULL;
+               }
+               return $file;
+       }
+
+       function try_handler($offset, $link, $file, $handler, $expected = null) {
+
+               if ('default' == $handler) {
+                       mysqli_set_local_infile_default($link);
+               } else if (!mysqli_set_local_infile_handler($link, $handler)) {
+                       printf("[%03d] Cannot set infile handler to '%s'\n", $offset, $handler);
+                       return false;
+               }
+               printf("Callback set to '%s'\n", $handler);
+
+               if (!mysqli_query($link, sprintf("DELETE FROM test"))) {
+                       printf("[%03d] Cannot remove records, [%d] %s\n", $offset + 1, mysqli_errno($link), mysqli_error($link));
+                       return false;
+               }
+
+               if (!mysqli_query($link, sprintf("LOAD DATA LOCAL INFILE '%s'
+                       INTO TABLE test
+                       FIELDS TERMINATED BY ';' OPTIONALLY ENCLOSED BY '\''
+                       LINES TERMINATED BY '\n'",
+                       mysqli_real_escape_string($link, $file)))) {
+                       printf("[%03d] LOAD DATA failed, [%d] %s\n",
+                               $offset + 2,
+                               mysqli_errno($link), mysqli_error($link));
+               }
+
+               if (!$res = mysqli_query($link, "SELECT id, label FROM test ORDER BY id")) {
+                       printf("[%03d] [%d] %s\n", $offset + 3, mysqli_errno($link), mysqli_error($link));
+                       return false;
+               }
+
+               if (!is_array($expected))
+                       return true;
+
+               foreach ($expected as $k => $values) {
+                       if (!$tmp = mysqli_fetch_assoc($res)) {
+                               printf("[%03d/%d] [%d] '%s'\n", $offset + 4, $k, mysqli_errno($link), mysqli_error($link));
+                               return false;
+                       }
+                       if ($values['id'] != $tmp['id']) {
+                               printf("[%03d/%d] Expecting %s got %s\n",
+                                       $offset + 5, $k,
+                                       $values['id'], $tmp['id']);
+                                       return false;
+                       }
+                       if ($values['label'] != $tmp['label']) {
+                               printf("[%03d/%d] Expecting %s got %s\n",
+                                       $offset + 6, $k,
+                                       $values['label'], $tmp['label']);
+                                       return false;
+                       }
+               }
+
+               if ($res && $tmp = mysqli_fetch_assoc($res)) {
+                       printf("[%03d] More results than expected!\n", $offset + 7);
+                       do {
+                               var_dump($tmp);
+                       } while ($tmp = mysqli_fetch_assoc($res));
+                       return false;
+               }
+
+               if ($res)
+                       mysqli_free_result($res);
+
+               return true;
+       }
+?>
\ No newline at end of file
diff --git a/ext/mysqli/tests/reflection_tools.inc b/ext/mysqli/tests/reflection_tools.inc
new file mode 100644 (file)
index 0000000..a96634b
--- /dev/null
@@ -0,0 +1,121 @@
+<?php
+       function inspectClass($class) {
+
+               /* not used: public ReflectionClass[] getInterfaces()  */
+
+               printf("\nInspecting class '%s'\n", $class->getName());
+               printf("isInternal: %s\n", ($class->isInternal()) ? 'yes' : 'no');
+               printf("isUserDefined: %s\n", ($class->isUserDefined()) ? 'yes' : 'no');
+               printf("isInstantiable: %s\n", ($class->isInstantiable()) ? 'yes' : 'no');
+               printf("isInterface: %s\n", ($class->isInterface()) ? 'yes' : 'no');
+               printf("isAbstract: %s\n", ($class->isAbstract()) ? 'yes' : 'no');
+               printf("isFinal: %s\n", ($class->isFinal()) ? 'yes' : 'no');
+               printf("isIteratable: %s\n", ($class->isIterateable()) ? 'yes' : 'no');
+               printf("Modifiers: '%d'\n", $class->getModifiers());
+               printf("Parent Class: '%s'\n", $class->getParentClass());
+               printf("Extension: '%s'\n", $class->getExtensionName());
+
+               if ($method = $class->getConstructor())
+                       inspectMethod($method);
+
+               if ($methods = $class->getMethods()) {
+                       $tmp = array();
+                       foreach ($methods as $method)
+                               $tmp[$method->getName()] = $method;
+
+                       ksort($tmp, SORT_STRING);
+                       foreach ($tmp as $method)
+                               inspectMethod($method);
+               }
+
+               if ($properties = $class->getProperties()) {
+                       $tmp = array();
+                       foreach ($properties as $prop)
+                               $tmp[$prop->getName()] = $prop;
+                       ksort($tmp, SORT_STRING);
+                       foreach ($tmp as $prop)
+                       inspectProperty($prop);
+               }
+
+
+               if ($properties = $class->getDefaultProperties()) {
+                       ksort($properties, SORT_STRING);
+                       foreach ($properties as $name => $v)
+                               printf("Default property '%s'\n", $name);
+               }
+
+               if ($properties = $class->getStaticProperties()) {
+                       ksort($properties, SORT_STRING);
+                       foreach ($properties as $name => $v)
+                               printf("Static property '%s'\n", $name);
+               }
+
+               if ($constants = $class->getConstants()) {
+                       ksort($constants, SORT_STRING);
+                       foreach ($constant as $name => $value)
+                               printf("Constant '%s' = '%s'\n", $name, $value);
+               }
+
+       }
+
+       function inspectProperty(&$prop) {
+
+               printf("\nInspecting property '%s'\n", $prop->getName());
+               printf("isPublic: %s\n", ($prop->isPublic()) ? 'yes' : 'no');
+               printf("isPrivate: %s\n", ($prop->isPrivate()) ? 'yes' : 'no');
+               printf("isProtected: %s\n", ($prop->isProtected()) ? 'yes' : 'no');
+               printf("isStatic: %s\n", ($prop->isStatic()) ? 'yes' : 'no');
+               printf("isDefault: %s\n", ($prop->isDefault()) ? 'yes' : 'no');
+               printf("Modifiers: %d\n", $prop->getModifiers());
+               // printf("Value\n"); var_export($prop->getValue());
+
+       }
+
+       function inspectMethod(&$method) {
+
+               printf("\nInspecting method '%s'\n", $method->getName());
+               printf("isFinal: %s\n", ($method->isFinal()) ? 'yes' : 'no');
+               printf("isAbstract: %s\n", ($method->isAbstract()) ? 'yes' : 'no');
+               printf("isPublic: %s\n", ($method->isPublic()) ? 'yes' : 'no');
+               printf("isPrivate: %s\n", ($method->isPrivate()) ? 'yes' : 'no');
+               printf("isProtected: %s\n", ($method->isProtected()) ? 'yes' : 'no');
+               printf("isStatic: %s\n", ($method->isStatic()) ? 'yes' : 'no');
+               printf("isConstructor: %s\n", ($method->isConstructor()) ? 'yes' : 'no');
+               printf("isDestructor: %s\n", ($method->isDestructor()) ? 'yes' : 'no');
+               printf("isInternal: %s\n", ($method->isInternal()) ? 'yes' : 'no');
+               printf("isUserDefined: %s\n", ($method->isUserDefined()) ? 'yes' : 'no');
+               printf("returnsReference: %s\n", ($method->returnsReference()) ? 'yes' : 'no');
+               printf("Modifiers: %d\n", $method->getModifiers());
+               printf("Number of Parameters: %d\n", $method->getNumberOfParameters());
+               printf("Number of Required Parameters: %d\n", $method->getNumberOfRequiredParameters());
+
+               if ($params = $method->getParameters()) {
+                       $tmp = array();
+                       foreach ($params as $k => $param)
+                               $tmp[$param->getName()] = $param;
+
+                       ksort($tmp, SORT_STRING);
+                       foreach ($tmp as $param)
+                               inspectParameter($method, $param);
+               }
+
+               if ($static = $method->getStaticVariables()) {
+                       sort($static, SORT_STRING);
+                       printf("Static variables: %s\n", implode('/', $static));
+               }
+
+       }
+
+       function inspectParameter(&$method, &$param) {
+
+               printf("\nInspecting parameter '%s' of method '%s'\n",
+               $param->getName(), $method->getName());
+               printf("isArray: %s\n", ($param->isArray()) ? 'yes': 'no');
+               printf("allowsNull: %s\n", ($param->allowsNull()) ? 'yes' : 'no');
+               printf("isPassedByReference: %s\n", ($param->isPassedByReference()) ? 'yes' : 'no');
+               printf("isOptional: %s\n", ($param->isOptional()) ? 'yes' : 'no');
+               printf("isDefaultValueAvailable: %s\n", ($param->isDefaultValueAvailable()) ? 'yes' : 'no');
+               // printf("getDefaultValue: %s\n", ($param->getDefaultValue()) ? 'yes' : 'no');
+
+       }
+?>
\ No newline at end of file
index 38c438738c7f4d0240215e9c2cd346739c138c57..a7581fb4806478fd252583698771979a4e3d87ed 100644 (file)
@@ -2,9 +2,4 @@
 if (!extension_loaded('mysqli')){
        die('skip mysqli extension not available');
 }
-include "connect.inc";
-$driver = new mysqli_driver();
-if (!$driver->embedded && !($con = @mysqli_connect($host, $user, $passwd, "", 3306))) {
-       die('skip could not connect to MySQL');
-}
-?>
+?>
\ No newline at end of file
diff --git a/ext/mysqli/tests/skipifconnectfailure.inc b/ext/mysqli/tests/skipifconnectfailure.inc
new file mode 100755 (executable)
index 0000000..f2b193d
--- /dev/null
@@ -0,0 +1,10 @@
+<?php
+$skip_on_connect_failure  = getenv("MYSQL_TEST_SKIP_CONNECT_FAILURE") ? getenv("MYSQL_TEST_SKIP_CONNECT_FAILURE") : false;
+if ($skip_on_connect_failure) {
+       include_once('connect.inc');
+       $link = @mysqli_connect($host, $user, $passwd, $db, $port, $socket);
+       if (!is_object($link))
+               die(sprintf("skip Can't connect to MySQL Server - [%d] %s", mysqli_connect_errno(), mysqli_connect_error()));
+       mysqli_close($link);
+}
+?>
index 298c7219a6216a5112d548a8a965fa6de4d54a26..254a4ccece778564fdf9071a67ddd857ed451c75 100644 (file)
@@ -1,5 +1,5 @@
 <?php
-  $driver = new mysqli_driver();
-  if ($driver->embedded) 
-    die("skip test doesn't run with embedded server");
-?>
+       $driver = new mysqli_driver();
+       if ($driver->embedded)
+               die("skip test doesn't run with embedded server");
+?>
\ No newline at end of file
index 8639130cbe38df8e2ec8adf67065a48d7db5e74c..d73d185bc4c9356e1bdaf42f57c2dd26311a22c4 100644 (file)
@@ -1,5 +1,5 @@
 <?php
-  $driver = new mysqli_driver();
-  if (!$driver->embedded) 
-    die("skip test for with embedded server only");
-?>
+       $driver = new mysqli_driver();
+       if (!$driver->embedded)
+               die("skip test for with embedded server only");
+?>
\ No newline at end of file
diff --git a/ext/mysqli/tests/skipifunicode.inc b/ext/mysqli/tests/skipifunicode.inc
new file mode 100644 (file)
index 0000000..23cd79d
--- /dev/null
@@ -0,0 +1,5 @@
+<?php
+if (ini_get("unicode.semantics")){
+       die('skip Test doesn't work in Unicode mode');
+}
+?>
diff --git a/ext/mysqli/tests/table.inc b/ext/mysqli/tests/table.inc
new file mode 100644 (file)
index 0000000..bfbbed7
--- /dev/null
@@ -0,0 +1,23 @@
+<?PHP
+require_once('connect.inc');
+
+if (!$link = mysqli_connect($host, $user, $passwd, $db, $port, $socket)) {
+       printf("Cannot connect to the server using host=%s, user=%s, passwd=***, dbname=%s, port=%s, socket=%s\n",
+               $host, $user, $db, $port, $socket);
+       exit(1);
+}
+
+if (!mysqli_query($link, 'DROP TABLE IF EXISTS test')) {
+       printf("Failed to drop old test table: [%d] %s\n", mysqli_errno($link), mysqli_error($link));
+       exit(1);
+}
+
+if (!mysqli_query($link, 'CREATE TABLE test(id INT, label CHAR(1), PRIMARY KEY(id)) ENGINE=' . $engine)) {
+       printf("Failed to create test table: [%d] %s\n", mysqli_errno($link), mysqli_error($link));
+       exit(1);
+}
+
+if (!mysqli_query($link, 'INSERT INTO test(id, label) VALUES (1, "a"), (2, "b"), (3, "c"), (4, "d"), (5, "e"), (6, "f")')) {
+       printf("[%d] %s\n",  mysqli_errno($link), mysqli_error($link));
+}
+?>
\ No newline at end of file