]> granicus.if.org Git - php/commitdiff
Last bunch of new tests.
authorUlf Wendel <uw@php.net>
Wed, 10 Oct 2007 10:20:11 +0000 (10:20 +0000)
committerUlf Wendel <uw@php.net>
Wed, 10 Oct 2007 10:20:11 +0000 (10:20 +0000)
ext/mysqli/tests/mysqli_thread_id.phpt [new file with mode: 0644]
ext/mysqli/tests/mysqli_thread_safe.phpt [new file with mode: 0644]
ext/mysqli/tests/mysqli_unclonable.phpt [new file with mode: 0644]
ext/mysqli/tests/mysqli_use_result.phpt [new file with mode: 0644]
ext/mysqli/tests/mysqli_warning_count.phpt [new file with mode: 0644]
ext/mysqli/tests/mysqli_warning_unclonable.phpt [new file with mode: 0644]

diff --git a/ext/mysqli/tests/mysqli_thread_id.phpt b/ext/mysqli/tests/mysqli_thread_id.phpt
new file mode 100644 (file)
index 0000000..6735489
--- /dev/null
@@ -0,0 +1,40 @@
+--TEST--
+mysqli_thread_id()
+--SKIPIF--
+<?php
+require_once('skipif.inc');
+require_once('skipifemb.inc');
+require_once('skipifconnectfailure.inc');
+?>
+--FILE--
+<?php
+       include "connect.inc";
+
+       $tmp    = NULL;
+       $link   = NULL;
+
+       if (!is_null($tmp = @mysqli_thread_id()))
+               printf("[001] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp);
+
+       if (!is_null($tmp = @mysqli_thread_id($link)))
+               printf("[002] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp);
+
+       require('table.inc');
+
+       if (!is_int($tmp = mysqli_thread_id($link)) || (0 === $tmp))
+               printf("[003] Expecting int/any but zero, got %s/%s. [%d] %s\n",
+                       gettype($tmp), $tmp, mysqli_errno($link), mysqli_error($link));
+
+       // should work if the thread id is correct
+       mysqli_kill($link, mysqli_thread_id($link));
+
+       mysqli_close($link);
+
+       if (NULL !== ($tmp = mysqli_thread_id($link)))
+               printf("[005] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp);
+
+       print "done!";
+?>
+--EXPECTF--
+Warning: mysqli_thread_id(): Couldn't fetch mysqli in %s on line %d
+done!
\ No newline at end of file
diff --git a/ext/mysqli/tests/mysqli_thread_safe.phpt b/ext/mysqli/tests/mysqli_thread_safe.phpt
new file mode 100644 (file)
index 0000000..0777c2a
--- /dev/null
@@ -0,0 +1,16 @@
+--TEST--
+mysqli_thread_safe()
+--SKIPIF--
+<?php
+require_once('skipif.inc');
+require_once('skipifemb.inc');
+?>
+--FILE--
+<?php
+       if (!is_bool($tmp = mysqli_thread_safe()))
+               printf("[001] Expecting boolean/any, got %s/%s.\n", gettype($tmp), $tmp);
+
+       print "done!";
+?>
+--EXPECTF--
+done!
\ No newline at end of file
diff --git a/ext/mysqli/tests/mysqli_unclonable.phpt b/ext/mysqli/tests/mysqli_unclonable.phpt
new file mode 100644 (file)
index 0000000..73894f4
--- /dev/null
@@ -0,0 +1,23 @@
+--TEST--
+Trying to clone mysqli object
+--SKIPIF--
+<?php
+require_once('skipif.inc');
+require_once('skipifemb.inc');
+require_once('skipifconnectfailure.inc');
+?>
+--FILE--
+<?php
+       include "connect.inc";
+
+       if (!$link = mysqli_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);
+
+       $link_clone = clone $link;
+       mysqli_close($link);
+
+       print "done!";
+?>
+--EXPECTF--
+Fatal error: Trying to clone an uncloneable object of class mysqli in %s on line %d
\ No newline at end of file
diff --git a/ext/mysqli/tests/mysqli_use_result.phpt b/ext/mysqli/tests/mysqli_use_result.phpt
new file mode 100644 (file)
index 0000000..2f53aea
--- /dev/null
@@ -0,0 +1,62 @@
+--TEST--
+mysqli_use_result()
+--SKIPIF--
+<?php
+require_once('skipif.inc');
+require_once('skipifemb.inc');
+require_once('skipifconnectfailure.inc');
+?>
+--FILE--
+<?php
+       include "connect.inc";
+
+       $tmp    = NULL;
+       $link   = NULL;
+
+       if (!is_null($tmp = @mysqli_use_result()))
+               printf("[001] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp);
+
+       if (!is_null($tmp = @mysqli_use_result($link)))
+               printf("[002] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp);
+
+       require('table.inc');
+
+       if (!$res = mysqli_real_query($link, "SELECT id, label FROM test ORDER BY id"))
+               printf("[003] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
+
+       if (!is_object($res = mysqli_use_result($link)))
+               printf("[004] Expecting object, got %s/%s. [%d] %s\n",
+                       gettype($res), $res, mysqli_errno($link), mysqli_error($link));
+
+       if (false !== ($tmp = mysqli_data_seek($res, 2)))
+               printf("[005] Expecting boolean/true, got %s/%s. [%d] %s\n",
+                       gettype($tmp), $tmp, mysqli_errno($link), mysqli_error($link));
+
+       mysqli_free_result($res);
+
+       if (!mysqli_query($link, "DELETE FROM test"))
+               printf("[006] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
+
+       if (false !== ($res = mysqli_use_result($link)))
+               printf("[007] Expecting boolean/false, got %s/%s. [%d] %s\n",
+                       gettype($res), $res, mysqli_errno($link), mysqli_error($link));
+
+       if (!$res = mysqli_query($link, "SELECT id, label FROM test ORDER BY id"))
+               printf("[008] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
+
+       if (false !== ($tmp = mysqli_data_seek($res, 1)))
+               printf("[009] Expecting boolean/false, got %s/%s\n",
+                       gettype($tmp), $tmp);
+
+       mysqli_close($link);
+
+       if (NULL !== ($tmp = mysqli_use_result($link)))
+               printf("[010] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp);
+
+       print "done!";
+?>
+--EXPECTF--
+Warning: mysqli_data_seek(): Function cannot be used with MYSQL_USE_RESULT in %s on line %d
+
+Warning: mysqli_use_result(): Couldn't fetch mysqli in %s on line %d
+done!
\ No newline at end of file
diff --git a/ext/mysqli/tests/mysqli_warning_count.phpt b/ext/mysqli/tests/mysqli_warning_count.phpt
new file mode 100644 (file)
index 0000000..c166313
--- /dev/null
@@ -0,0 +1,48 @@
+--TEST--
+mysqli_warning_count()
+--SKIPIF--
+<?php
+require_once('skipif.inc');
+require_once('skipifemb.inc');
+require_once('skipifconnectfailure.inc');
+?>
+--FILE--
+<?php
+       include "connect.inc";
+
+       $tmp    = NULL;
+       $link   = NULL;
+
+       if (!is_null($tmp = @mysqli_warning_count()))
+               printf("[001] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp);
+
+       if (!is_null($tmp = @mysqli_warning_count($link)))
+               printf("[002] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp);
+
+       require('table.inc');
+
+       if (NULL !== ($tmp = @mysqli_warning_count($link, "too_many")))
+               printf("[003] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp);
+
+       if (!$res = mysqli_query($link, "SELECT id, label FROM test"))
+               printf("[004] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
+
+       if (0 !== ($tmp = mysqli_warning_count($link)))
+               printf("[005] Expecting int/0, got %s/%s\n", gettype($tmp), $tmp);
+
+       if (!mysqli_query($link, "DROP TABLE IF EXISTS this_table_does_not_exist"))
+               printf("[006] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
+
+       if (1 !== ($tmp = mysqli_warning_count($link)))
+               printf("[007] Expecting int/1, got %s/%s\n", gettype($tmp), $tmp);
+
+       mysqli_close($link);
+
+       if (NULL !== ($tmp = mysqli_warning_count($link)))
+               printf("[010] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp);
+
+       print "done!";
+?>
+--EXPECTF--
+Warning: mysqli_warning_count(): Couldn't fetch mysqli in %s on line %d
+done!
\ No newline at end of file
diff --git a/ext/mysqli/tests/mysqli_warning_unclonable.phpt b/ext/mysqli/tests/mysqli_warning_unclonable.phpt
new file mode 100644 (file)
index 0000000..bdbc0e2
--- /dev/null
@@ -0,0 +1,37 @@
+--TEST--
+Trying to clone mysqli_warning object
+--SKIPIF--
+<?php
+require_once('skipif.inc');
+require_once('skipifemb.inc');
+require_once('skipifconnectfailure.inc');
+require_once('connect.inc');
+if (!$TEST_EXPERIMENTAL)
+       die("skip - experimental (= unsupported) feature");
+?>
+--FILE--
+<?php
+       include "connect.inc";
+
+       if (!$link = mysqli_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);
+
+       if (!mysqli_query($link, "DROP TABLE IF EXISTS test"))
+               printf("[002] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
+
+       if (!mysqli_query($link, "CREATE TABLE test (id SMALLINT)"))
+               printf("[003] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
+
+       if (!mysqli_query($link, "INSERT INTO test (id) VALUES (1000000)"))
+               printf("[004] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
+
+       if (!is_object($warning = mysqli_get_warnings($link)) || 'mysqli_warning' != get_class($warning)) {
+               printf("[005] Expecting object/mysqli_warning, got %s/%s\n", gettype($tmp), (is_object($tmp) ? var_dump($tmp, true) : $tmp));
+       }
+
+       $warning_clone = clone $warning;
+       print "done!";
+?>
+--EXPECTF--
+Fatal error: Trying to clone an uncloneable object of class mysqli_warning in %s on line %d
\ No newline at end of file