uw Wed Jul 11 11:12:11 2007 UTC
Modified files:
/php-src/ext/mysql/tests connect.inc table.inc skipif.inc 001.phpt
002.phpt 003.phpt
Log:
Trying to fix broken tests. The last set of files committed a few weeks ago
broke almost all tests. I'll try to merge the CVS with a working set of
tests from the mysqlnd development repository. With this first set of
changes most tests should run (and pass) again.
Note the additional environment variables in connect.inc that you can
use to control a test run.
More changes to come.
http://cvs.php.net/viewvc.cgi/php-src/ext/mysql/tests/connect.inc?r1=1.1&r2=1.2&diff_format=u
Index: php-src/ext/mysql/tests/connect.inc
diff -u php-src/ext/mysql/tests/connect.inc:1.1
php-src/ext/mysql/tests/connect.inc:1.2
--- php-src/ext/mysql/tests/connect.inc:1.1 Mon Jan 12 02:31:08 2004
+++ php-src/ext/mysql/tests/connect.inc Wed Jul 11 11:12:10 2007
@@ -1,10 +1,64 @@
<?php
+if (!function_exists('sys_get_temp_dir')) {
+ function sys_get_temp_dir() {
- /* default values are localhost, root and empty password
- Change the values if you use another configuration */
+ if (!empty($_ENV['TMP']))
+ return realpath( $_ENV['TMP'] );
+ if (!empty($_ENV['TMPDIR']))
+ return realpath( $_ENV['TMPDIR'] );
+ if (!empty($_ENV['TEMP']))
+ return realpath( $_ENV['TEMP'] );
- $host = "localhost";
- $user = "root";
- $passwd = "";
+ $temp_file = tempnam(md5(uniqid(rand(), TRUE)), '');
+ if ($temp_file) {
+ $temp_dir = realpath(dirname($temp_file));
+ unlink($temp_file);
+ return $temp_dir;
+ }
+ return FALSE;
+ }
+}
+/* wrapper to simplify test porting */
+function my_mysql_connect($host, $user, $passwd, $db, $port, $socket) {
+
+ if ($socket)
+ $host = sprintf("%s:%s", $host, $socket);
+ else if ($port)
+ $host = sprintf("%s:%s", $host, $port);
+
+ if (!$link = mysql_connect($host, $user, $passwd, true)) {
+ printf("[000-a] Cannot connect using host '%s', user '%s',
password '****', [%d] %s\n",
+ $host, $user, $passwd,
+ mysql_errno(), mysql_error());
+ return false;
+ }
+
+ if (!mysql_select_db($db, $link)) {
+ printf("[000-b] [%d] %s\n", mysql_errno($link),
mysql_error($link));
+ return false;
+ }
+
+ return $link;
+}
+
+/*
+Default values are "localhost", "root", database "test" and empty password.
+Change the MYSQL_TEST environment values if you want to use another
configuration.
+*/
+
+$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")
: "test";
+$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(mysql_get_client_info(), "mysqlnd");
?>
http://cvs.php.net/viewvc.cgi/php-src/ext/mysql/tests/table.inc?r1=1.1&r2=1.2&diff_format=u
Index: php-src/ext/mysql/tests/table.inc
diff -u php-src/ext/mysql/tests/table.inc:1.1
php-src/ext/mysql/tests/table.inc:1.2
--- php-src/ext/mysql/tests/table.inc:1.1 Sun Nov 19 12:14:44 2006
+++ php-src/ext/mysql/tests/table.inc Wed Jul 11 11:12:10 2007
@@ -1,4 +1,4 @@
-<?PHP
+<?PHP
require_once('connect.inc');
// connect + select_db
@@ -6,19 +6,19 @@
printf("Cannot connect to the server using host=%s/%s, user=%s,
passwd=***, dbname=%s, port=%s, socket=%s\n",
$host, $myhost, $user, $db, $port, $socket);
exit(1);
-}
+}
if (!mysql_query('DROP TABLE IF EXISTS test', $link)) {
printf("Failed to drop old test table: [%d] %s\n", mysql_errno($link),
mysql_error($link));
exit(1);
-}
-
+}
+
if (!mysql_query('CREATE TABLE test(id INT, label CHAR(1), PRIMARY KEY(id))
ENGINE=' . $engine, $link)) {
printf("Failed to create test table: [%d] %s\n", mysql_errno($link),
mysql_error($link));
exit(1);
}
if (!mysql_query('INSERT INTO test(id, label) VALUES (1, "a"), (2, "b"), (3,
"c"), (4, "d"), (5, "e"), (6, "f")', $link)) {
- printf("[%d] %s\n", mysql_errno($link), mysql_error($link));
+ printf("[%d] %s\n", mysql_errno($link), mysql_error($link));
}
?>
\ No newline at end of file
http://cvs.php.net/viewvc.cgi/php-src/ext/mysql/tests/skipif.inc?r1=1.3&r2=1.4&diff_format=u
Index: php-src/ext/mysql/tests/skipif.inc
diff -u php-src/ext/mysql/tests/skipif.inc:1.3
php-src/ext/mysql/tests/skipif.inc:1.4
--- php-src/ext/mysql/tests/skipif.inc:1.3 Tue Jun 27 00:09:23 2006
+++ php-src/ext/mysql/tests/skipif.inc Wed Jul 11 11:12:10 2007
@@ -1,11 +1,6 @@
<?php
-
-include 'connect.inc';
+require_once('connect.inc');
if (!extension_loaded("mysql")) {
die('skip mysql extension not available');
}
-$link = @mysql_connect($host, $user, $passwd);
-if (!$link) die('skip cannot connect');
-mysql_close($link);
-
?>
http://cvs.php.net/viewvc.cgi/php-src/ext/mysql/tests/001.phpt?r1=1.4&r2=1.5&diff_format=u
Index: php-src/ext/mysql/tests/001.phpt
diff -u php-src/ext/mysql/tests/001.phpt:1.4
php-src/ext/mysql/tests/001.phpt:1.5
--- php-src/ext/mysql/tests/001.phpt:1.4 Mon Feb 6 14:25:28 2006
+++ php-src/ext/mysql/tests/001.phpt Wed Jul 11 11:12:10 2007
@@ -4,22 +4,30 @@
<?php include 'skipif.inc'; ?>
--FILE--
<?php
-
-include 'connect.inc';
+require_once('connect.inc');
$test = '';
+if ($socket)
+ $host = sprintf("%s:%s", $host, $socket);
+else if ($port)
+ $host = sprintf("%s:%s", $host, $port);
+
/*** test mysql_connect localhost ***/
$db = mysql_connect($host, $user, $passwd);
$test .= ($db) ? '1' : '0';
mysql_close($db);
/*** test mysql_connect localhost:port ***/
-$db = mysql_connect("{$host}:3306", $user, $passwd, '');
+$db = mysql_connect($host, $user, $passwd, true);
$test .= ($db) ? '1' : '0';
mysql_close($db);
var_dump($test);
-
+print "done!";
?>
--EXPECT--
string(2) "11"
+done!
+--UEXPECTF--
+unicode(2) "11"
+done!
\ No newline at end of file
http://cvs.php.net/viewvc.cgi/php-src/ext/mysql/tests/002.phpt?r1=1.1&r2=1.2&diff_format=u
Index: php-src/ext/mysql/tests/002.phpt
diff -u php-src/ext/mysql/tests/002.phpt:1.1
php-src/ext/mysql/tests/002.phpt:1.2
--- php-src/ext/mysql/tests/002.phpt:1.1 Mon Jan 12 02:31:08 2004
+++ php-src/ext/mysql/tests/002.phpt Wed Jul 11 11:12:10 2007
@@ -4,14 +4,13 @@
<?php include 'skipif.inc'; ?>
--FILE--
<?php
+require_once('connect.inc');
-include 'connect.inc';
+if (!$link = my_mysql_connect($host, $user, $passwd, $db, $port, $socket))
+ printf("[001] Cannot connect to the server using host=%s, user=%s,
passwd=***, dbname=%s, port=%s, socket=%s\n",
+ $host, $user, $db, $port, $socket);
-$db = mysql_connect($host, $user, $passwd);
-
-var_dump($db);
-
-var_dump(mysql_select_db('test'));
+var_dump($link);
var_dump(mysql_query('DROP TABLE IF EXISTS test'));
@@ -25,15 +24,16 @@
var_dump($data);
}
-mysql_close($db);
+mysql_free_result($res);
+mysql_close($link);
+print "done!";
?>
--EXPECTF--
resource(%d) of type (mysql link)
bool(true)
bool(true)
bool(true)
-bool(true)
resource(%d) of type (mysql result)
array(3) {
["col1"]=>
@@ -51,3 +51,27 @@
["col3"]=>
string(3) "bar"
}
+done!
+--UEXPECTF--
+resource(%d) of type (mysql link)
+bool(true)
+bool(true)
+bool(true)
+resource(%d) of type (mysql result)
+array(3) {
+ [u"col1"]=>
+ unicode(1) "1"
+ [u"col2"]=>
+ unicode(3) "foo"
+ [u"col3"]=>
+ unicode(3) "bar"
+}
+array(3) {
+ [u"col1"]=>
+ unicode(1) "2"
+ [u"col2"]=>
+ unicode(3) "foo"
+ [u"col3"]=>
+ unicode(3) "bar"
+}
+done!
\ No newline at end of file
http://cvs.php.net/viewvc.cgi/php-src/ext/mysql/tests/003.phpt?r1=1.1&r2=1.2&diff_format=u
Index: php-src/ext/mysql/tests/003.phpt
diff -u php-src/ext/mysql/tests/003.phpt:1.1
php-src/ext/mysql/tests/003.phpt:1.2
--- php-src/ext/mysql/tests/003.phpt:1.1 Mon Jan 12 02:34:55 2004
+++ php-src/ext/mysql/tests/003.phpt Wed Jul 11 11:12:10 2007
@@ -4,8 +4,7 @@
<?php include 'skipif.inc'; ?>
--FILE--
<?php
-
-include 'connect.inc';
+include_once('connect.inc');
class class24 {
function __construct() {
@@ -13,45 +12,44 @@
}
}
-$data = array(
- "one",
- "two",
- "three"
- );
-
-$db = mysql_connect($host, $user, $passwd);
+$data = array("one", "two", "three");
-mysql_select_db("test");
+if (!$link = my_mysql_connect($host, $user, $passwd, $db, $port, $socket))
+ printf("[001] Cannot connect to the server using host=%s, user=%s,
passwd=***, dbname=%s, port=%s, socket=%s\n",
+ $host, $user, $db, $port, $socket);
-mysql_query('DROP TABLE IF EXISTS test');
+if (!mysql_query('DROP TABLE IF EXISTS test', $link))
+ printf("[002] [%d] %s\n", mysql_errno($link), mysql_error($link));
-mysql_query("CREATE TABLE test(a varchar(10))");
+if (!mysql_query("CREATE TABLE test(a varchar(10))", $link))
+ printf("[003] [%d] %s\n", mysql_errno($link), mysql_error($link));
foreach ($data as $str) {
- mysql_query("INSERT INTO test VALUES('$str')");
- var_dump($str);
+ if (!mysql_query(sprintf("INSERT INTO test VALUES('%s')", $str), $link))
+ printf("[004 - %s] [%d] %s\n", $str, mysql_errno($link),
mysql_error($link));
}
echo "==stdClass==\n";
-$res = mysql_query("SELECT a FROM test");
+if (!$res = mysql_query("SELECT a FROM test", $link))
+ printf("[005] [%d] %s\n", mysql_errno($link), mysql_error($link));
+
while ($obj = mysql_fetch_object($res)) {
var_dump($obj);
}
+mysql_free_result($res);
echo "==class24==\n";
-$res = mysql_query("SELECT a FROM test");
+if (!$res = mysql_query("SELECT a FROM test", $link))
+ printf("[006] [%d] %s\n", mysql_errno($link), mysql_error($link));
+
while ($obj = mysql_fetch_object($res, 'class24')) {
var_dump($obj);
}
-
-mysql_close($db);
-
+mysql_free_result($res);
+mysql_close($link);
+print "done!";
?>
-==DONE==
--EXPECTF--
-string(3) "one"
-string(3) "two"
-string(5) "three"
==stdClass==
object(stdClass)#%d (1) {
["a"]=>
@@ -81,4 +79,35 @@
["a"]=>
string(5) "three"
}
-==DONE==
+done!
+--UEXPECTF--
+==stdClass==
+object(stdClass)#%d (1) {
+ [u"a"]=>
+ unicode(3) "one"
+}
+object(stdClass)#%d (1) {
+ [u"a"]=>
+ unicode(3) "two"
+}
+object(stdClass)#%d (1) {
+ [u"a"]=>
+ unicode(5) "three"
+}
+==class24==
+class24::__construct
+object(class24)#%d (1) {
+ [u"a"]=>
+ unicode(3) "one"
+}
+class24::__construct
+object(class24)#%d (1) {
+ [u"a"]=>
+ unicode(3) "two"
+}
+class24::__construct
+object(class24)#%d (1) {
+ [u"a"]=>
+ unicode(5) "three"
+}
+done!
\ No newline at end of file
--
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php