]> granicus.if.org Git - php/commitdiff
Handle deprecation messages differently in tests to reduce test differences between...
authorUlf Wendel <uw@php.net>
Tue, 25 Jan 2011 14:01:00 +0000 (14:01 +0000)
committerUlf Wendel <uw@php.net>
Tue, 25 Jan 2011 14:01:00 +0000 (14:01 +0000)
ext/mysql/tests/mysql_db_name.phpt
ext/mysql/tests/mysql_deprecated_api.phpt [new file with mode: 0644]
ext/mysql/tests/mysql_escape_string.phpt
ext/mysql/tests/mysql_list_dbs.phpt
ext/mysql/tests/mysql_trace_mode.phpt

index bed98bca52344bf0c85e8b768313f3a147775118..b7f9042209f3d0bfb2aca1358226436f37521457 100644 (file)
@@ -20,7 +20,7 @@ if (NULL !== ($tmp = @mysql_db_name($link, $link)))
 
 require('table.inc');
 
-if (!$res = mysql_list_dbs($link))
+if (!$res = @mysql_list_dbs($link))
        printf("[003] [%d] %s\n", mysql_errno($link), mysql_error($link));
 
 if (!$num = mysql_num_rows($res))
@@ -58,10 +58,6 @@ mysql_close($link);
 print "done!\n";
 ?>
 --EXPECTF--
-Deprecated: Function mysql_list_dbs() is deprecated in %s on line %d
-
-Deprecated: mysql_list_dbs(): This function is deprecated; use mysql_query() with SHOW DATABASES instead in %s on line %d
-
 Warning: mysql_db_name(): Unable to jump to row -1 on MySQL result index %d in %s on line %d
 
 Warning: mysql_db_name(): Unable to jump to row %d on MySQL result index %d in %s on line %d
diff --git a/ext/mysql/tests/mysql_deprecated_api.phpt b/ext/mysql/tests/mysql_deprecated_api.phpt
new file mode 100644 (file)
index 0000000..d54307c
--- /dev/null
@@ -0,0 +1,78 @@
+--TEST--
+Check if deprecated API calls bail out
+--SKIPIF--
+<?php
+require_once('skipif.inc');
+require_once('skipifconnectfailure.inc');
+?>
+--INI--
+mysql.trace_mode=1
+error_reporting=E_ALL | E_NOTICE | E_STRICT
+--FILE--
+<?php
+/*
+  We use an extra test to cover deprecation warning.
+  Due to this extra test we can silence deprecation warnings
+  in have other test using @ operator without loosing the information
+  which function is deprecated and, without reducing test portability.
+*/
+include "table.inc";
+
+if (version_compare(PHP_VERSION, '5.3.0') >= 0) {
+       $error = NULL;
+       ob_start();
+       if (!$res = mysql_db_query($db, "SELECT * FROM test", $link))
+               $error .= sprintf("[001] [%d] %s\n", mysql_errno($link), mysql_error($link));
+       else
+         mysql_free_result($res);
+       $output = ob_get_contents();
+       ob_end_clean();
+
+       if (!stristr($output, 'deprecated')) {
+               printf("[002] mysql_db_query has been deprecated in 5.3.0\n");
+       }
+
+       /*
+               Deprecated since 2002 or the like but documented to be deprecated since 5.3.
+               In 5.3 and before the deprecation message was bound to mysql.trace_mode=1.
+               In 5.3.99 the warning will always be thrown, independent of the mysql.trace_mode
+               setting.
+       */
+       $error = NULL;
+       ob_start();
+       if (!$query = mysql_escape_string("charsets will be ignored"))
+               $error .= sprintf("[005] [%d] %s\n", mysql_errno($link), mysql_error($link));
+       $output = ob_get_contents();
+       ob_end_clean();
+
+       if (!stristr($output, 'deprecated')) {
+               printf("[006] mysql_escape_string has been deprecated in 5.3.0\n");
+       }
+
+}
+
+if (version_compare(PHP_VERSION, '5.3.99') >= 0) {
+       $error = NULL;
+       ob_start();
+       if (!$res = mysql_list_dbs($link))
+               $error .= sprintf("[003] [%d] %s\n", mysql_errno($link), mysql_error($link));
+       else
+         mysql_free_result($res);
+       $output = ob_get_contents();
+       ob_end_clean();
+
+  if (!stristr($output, 'deprecated')) {
+       printf("[004] mysql_db_query has been deprecated in 5.3.0\n");
+  }
+}
+
+
+
+print "done!";
+?>
+--CLEAN--
+<?php
+require_once("clean_table.inc");
+?>
+--EXPECTF--
+done!
\ No newline at end of file
index 45bf26978cb8f1abe4d8fc927ef8ad510322b675..8e70da69c92319e0a2123a41c25d0b638e9024dc 100644 (file)
@@ -12,13 +12,13 @@ $link   = NULL;
 if (NULL !== ($tmp = @mysql_escape_string()))
        printf("[001] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp);
 
-var_dump(mysql_escape_string("Am I a unicode string in PHP 6?"));
-var_dump(mysql_escape_string('\\'));
-var_dump(mysql_escape_string('"'));
-var_dump(mysql_escape_string("'"));
-var_dump(mysql_escape_string("\n"));
-var_dump(mysql_escape_string("\r"));
-var_dump(mysql_escape_string("foo" . chr(0) . "bar"));
+var_dump(@mysql_escape_string("Am I a unicode string in PHP 6?"));
+var_dump(@mysql_escape_string('\\'));
+var_dump(@mysql_escape_string('"'));
+var_dump(@mysql_escape_string("'"));
+var_dump(@mysql_escape_string("\n"));
+var_dump(@mysql_escape_string("\r"));
+var_dump(@mysql_escape_string("foo" . chr(0) . "bar"));
 
 print "done!";
 ?>
index 6900ab0e0a2c9a02be227d456cdaf32967591d0c..054e02ef98066038905dc16fb9149baf96fd2388 100644 (file)
@@ -20,7 +20,7 @@ if (NULL !== ($tmp = @mysql_list_dbs($link, $link)))
 
 require('table.inc');
 
-if (!$res = mysql_list_dbs($link))
+if (!$res = @mysql_list_dbs($link))
        printf("[003] [%d] %s\n", mysql_errno($link), mysql_error($link));
 
 if (!$num = mysql_num_rows($res))
@@ -34,7 +34,7 @@ if ((version_compare(PHP_VERSION, '5.9.9', '>') == 1) && !is_unicode($row[0])) {
 
 mysql_free_result($res);
 
-if (!$res2 = mysql_list_dbs())
+if (!$res2 = @mysql_list_dbs())
        printf("[006] [%d] %s\n", mysql_errno(), mysql_error());
 
 $row2 = mysql_fetch_array($res2, MYSQL_NUM);
@@ -51,9 +51,4 @@ print "done!\n";
 require_once("clean_table.inc");
 ?>
 --EXPECTF--
-Deprecated: Function mysql_list_dbs() is deprecated in %s on line 15
-
-Deprecated: mysql_list_dbs(): This function is deprecated; use mysql_query() with SHOW DATABASES instead in %s on line %d
-
-Deprecated: mysql_list_dbs(): This function is deprecated; use mysql_query() with SHOW DATABASES instead in %s on line %d
-done!
+done!
\ No newline at end of file
index 622f413062dbf5c9ca26d9c89816f39fa7aeea40..2b6c61d27bb1ba728d340fb4e436c2961fd80b62 100644 (file)
@@ -14,10 +14,10 @@ require_once('table.inc');
 
 $res1 = mysql_query('SELECT id FROM test', $link);
 
-if (!$res2 = mysql_db_query($db, 'SELECT id FROM test', $link))
+if (!$res2 = @mysql_db_query($db, 'SELECT id FROM test', $link))
        printf("[001] [%d] %s\n", mysql_errno($link), mysql_error($link));
 mysql_free_result($res2);
-print mysql_escape_string("I don't mind character sets, do I?\n");
+print @mysql_escape_string("I don't mind character sets, do I?\n");
 
 $res3 = mysql_query('BOGUS_SQL', $link);
 mysql_close($link);
@@ -29,9 +29,6 @@ print "done!\n";
 require_once("clean_table.inc");
 ?>
 --EXPECTF--
-Deprecated: mysql_db_query(): %s
-
-Deprecated: mysql_escape_string(): %s
 I don\'t mind character sets, do I?\n
 Warning: mysql_query(): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'BOGUS_SQL' at line 1 in %s on line %d
 done!