From: Ulf Wendel Date: Wed, 10 Oct 2007 10:55:52 +0000 (+0000) Subject: Adding tests to ext/mysql in HEAD = synching with 5_3 X-Git-Tag: RELEASE_2_0_0a1~1613 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=b67be59f4e8a2b3232582a04f513a6f15856a8f9;p=php Adding tests to ext/mysql in HEAD = synching with 5_3 --- diff --git a/ext/mysql/tests/mysql_max_links.phpt b/ext/mysql/tests/mysql_max_links.phpt new file mode 100644 index 0000000000..fbe3ae0030 --- /dev/null +++ b/ext/mysql/tests/mysql_max_links.phpt @@ -0,0 +1,69 @@ +--TEST-- +mysql_[p]connect() - max_links/max_persistent +--SKIPIF-- + +--INI-- +mysql.max_links=2 +--FILE-- + second open connection +$links[0] = my_connect(50, $host, $user, $passwd, $db, $port, $socket); +$links[2] = my_connect(60, $host, $user, $passwd, $db, $port, $socket); +ksort($links); +var_dump($links); + +mysql_close($links[0]); +mysql_close($links[1]); +print "done!\n"; +?> +--EXPECTF-- +Warning: mysql_connect(): Too many open links (2) in %s on line %s +[030] Cannot connect using host '%s', user '%s', password '****', [0] 0 + +Warning: mysql_connect(): Too many open links (2) in %s on line %s +[060] Cannot connect using host '%s', user '%s', password '****', [0] 0 +array(3) { + [0]=> + resource(%d) of type (mysql link) + [1]=> + resource(%d) of type (mysql link) + [2]=> + bool(false) +} +done! \ No newline at end of file diff --git a/ext/mysql/tests/mysql_max_persistent.phpt b/ext/mysql/tests/mysql_max_persistent.phpt new file mode 100644 index 0000000000..50c8d375e5 --- /dev/null +++ b/ext/mysql/tests/mysql_max_persistent.phpt @@ -0,0 +1,90 @@ +--TEST-- +mysql_[p]connect() - max_links/max_persistent +--SKIPIF-- + +--INI-- +mysql.max_links=2 +mysql.allow_persistent=1 +mysql.max_persistent=1 +--FILE-- + only open connection +$links[0] = my_connect(40, $host, $user, $passwd, $db, $port, $socket); +var_dump($links); + +mysql_query('REVOKE ALL PRIVILEGES, GRANT OPTION FROM pcontest', $links[0]); +mysql_query('DROP USER pcontest', $links[0]); + +mysql_close($links[0]); +print "done!\n"; +?> +--EXPECTF-- +Warning: mysql_pconnect(): Too many open persistent links (1) in %s on line %d +[020] Cannot connect using host '%s', user '%s', password '****', [0] 0 +array(1) { + [0]=> + resource(%d) of type (mysql link persistent) +} +done! \ No newline at end of file diff --git a/ext/mysql/tests/mysql_pconn_disable.phpt b/ext/mysql/tests/mysql_pconn_disable.phpt new file mode 100644 index 0000000000..9ec44234ad --- /dev/null +++ b/ext/mysql/tests/mysql_pconn_disable.phpt @@ -0,0 +1,58 @@ +--TEST-- +mysql_pconnect() - disabling feature +--SKIPIF-- + +--INI-- +mysql.allow_persistent=0 +mysql.max_persistent=1 +mysql.max_links=2 +--FILE-- + +--EXPECTF-- +[001] Can connect to the server. +[002] Can fetch data using persistent connection! Data = '1' +done! \ No newline at end of file diff --git a/ext/mysql/tests/mysql_pconn_kill.phpt b/ext/mysql/tests/mysql_pconn_kill.phpt new file mode 100755 index 0000000000..df863bb791 --- /dev/null +++ b/ext/mysql/tests/mysql_pconn_kill.phpt @@ -0,0 +1,106 @@ +--TEST-- +mysql_pconnect() - killing persitent connection +--SKIPIF-- + +--INI-- +mysql.allow_persistent=1 +mysql.max_persistent=2 +--FILE-- + +--EXPECTF-- +bool(true) +done! diff --git a/ext/mysql/tests/mysql_pconn_max_links.phpt b/ext/mysql/tests/mysql_pconn_max_links.phpt new file mode 100644 index 0000000000..b5b0a3a56c --- /dev/null +++ b/ext/mysql/tests/mysql_pconn_max_links.phpt @@ -0,0 +1,169 @@ +--TEST-- +Persistent connections and mysql.max_persistent +--SKIPIF-- + +--INI-- +mysql.max_links=2 +mysql.max_persistent=1 +mysql.allow_persistent=1 +--FILE-- + enabled'), 500); + if (!preg_match('@Active Persistent Links\s+=>\s+(\d+)@ismU', $phpinfo, $matches)) + printf("[003] Cannot get # active persistent links from phpinfo()"); + $num_plinks = $matches[1]; + + if (!$res = mysql_query('SELECT id, label FROM test WHERE id = 1', $plink)) + printf("[004] Cannot run query on persistent connection of second DB user, [%d] %s\n", + mysql_errno($plink), mysql_error($plink)); + + if (!$row = mysql_fetch_assoc($res)) + printf("[005] Cannot run fetch result, [%d] %s\n", + mysql_errno($plink), mysql_error($plink)); + mysql_free_result($res); + var_dump($row); + + // change the password for the second DB user and kill the persistent connection + if (!mysql_query('SET PASSWORD FOR pcontest = PASSWORD("newpass")', $link)) + printf("[006] Cannot change PW of second DB user, [%d] %s\n", mysql_errno($link), mysql_error($link)); + + // persistent connections cannot be closed but only be killed + $pthread_id = mysql_thread_id($plink); + if (!mysql_query(sprintf('KILL %d', $pthread_id), $link)) + printf("[007] Cannot KILL persistent connection of second DB user, [%d] %s\n", mysql_errno($link), mysql_error($link)); + // give the server a second to really kill the thread + sleep(1); + + if (!$res = mysql_query("SHOW FULL PROCESSLIST", $link)) + printf("[008] [%d] %s\n", mysql_errno($link), mysql_error($link)); + + $running_threads = array(); + while ($row = mysql_fetch_assoc($res)) + $running_threads[$row['Id']] = $row; + mysql_free_result($res); + + if (isset($running_threads[$pthread_id])) + printf("[009] Persistent connection has not been killed"); + + // we might get the old handle + if ($plink = @mysql_pconnect($host, 'pcontest', 'pcontest')) + printf("[010] Can connect using the old password, [%d] %s\n", + mysql_errno(), mysql_error()); + + ob_start(); + phpinfo(); + $phpinfo = strip_tags(ob_get_contents()); + ob_end_clean(); + $phpinfo = substr($phpinfo, strpos($phpinfo, 'MySQL Support => enabled'), 500); + if (!preg_match('@Active Persistent Links\s+=>\s+(\d+)@ismU', $phpinfo, $matches)) + printf("[011] Cannot get # active persistent links from phpinfo()"); + + $num_plinks_kill = $matches[1]; + if ($num_plinks_kill >= $num_plinks) + printf("[012] Statistics seems to be wrong, got %d active persistent links, expecting < %d links", + $num_plinks_kill, $num_plinks); + + // The first connection has been closed, the last pconnect() was unable to connect -> no connection open + // We must be able to connect because max_persistent limit has not been reached + if (!$plink = mysql_pconnect($host, 'pcontest', 'newpass')) + printf("[013] Cannot connect using the second DB, [%d] %s\n", + mysql_errno(), mysql_error()); + + if (!mysql_select_db($db, $plink)) + printf("[014] [%d] %s\n", mysql_errno($plink), mysql_error($plink)); + + if (!$res = mysql_query('SELECT id, label FROM test WHERE id = 1', $plink)) + printf("[015] Cannot run query on persistent connection of second DB user, [%d] %s\n", + mysql_errno($plink), mysql_error($plink)); + + if (!$row = mysql_fetch_assoc($res)) + printf("[016] Cannot run fetch result, [%d] %s\n", + mysql_errno($plink), mysql_error($plink)); + mysql_free_result($res); + var_dump($row); + + mysql_query('REVOKE ALL PRIVILEGES, GRANT OPTION FROM pcontest', $link); + mysql_query('DROP USER pcontest', $link); + mysql_close($link); + print "done!"; +?> +--EXPECTF-- +array(2) { + ["id"]=> + string(1) "1" + ["label"]=> + string(1) "a" +} +array(2) { + ["id"]=> + string(1) "1" + ["label"]=> + string(1) "a" +} +done! +--UEXPECTF-- +array(2) { + [u"id"]=> + unicode(1) "1" + [u"label"]=> + unicode(1) "a" +} +array(2) { + [u"id"]=> + unicode(1) "1" + [u"label"]=> + unicode(1) "a" +} +done! diff --git a/ext/mysql/tests/mysql_pconn_reuse.phpt b/ext/mysql/tests/mysql_pconn_reuse.phpt new file mode 100644 index 0000000000..ffa5f75f1b --- /dev/null +++ b/ext/mysql/tests/mysql_pconn_reuse.phpt @@ -0,0 +1,66 @@ +--TEST-- +mysql_pconnect() - disabling feature +--SKIPIF-- + +--INI-- +mysql.allow_persistent=1 +mysql.max_persistent=1 +mysql.max_links=2 +--FILE-- + +--EXPECTF-- +[001] Can connect to the server. +[002] Can fetch data using persistent connection! Data = '1' + +Warning: mysql_connect(): Too many open links (2) in %s on line %d +done! \ No newline at end of file diff --git a/ext/mysql/tests/mysql_pconnect.phpt b/ext/mysql/tests/mysql_pconnect.phpt index 7a81d2b42f..5a7db93ab3 100644 --- a/ext/mysql/tests/mysql_pconnect.phpt +++ b/ext/mysql/tests/mysql_pconnect.phpt @@ -1,82 +1,85 @@ --TEST-- mysql_pconnect() --SKIPIF-- - +--INI-- +mysql.max_persistent=10 +mysql.allow_persistent=1 --FILE-- --EXPECTF-- Warning: mysql_pconnect(): Access denied for user '%s'@'%s' (using password: YES) in %s on line %d -done! \ No newline at end of file +done! diff --git a/ext/mysql/tests/mysql_query_load_data_openbasedir.phpt b/ext/mysql/tests/mysql_query_load_data_openbasedir.phpt new file mode 100644 index 0000000000..d007080431 --- /dev/null +++ b/ext/mysql/tests/mysql_query_load_data_openbasedir.phpt @@ -0,0 +1,108 @@ +--TEST-- +LOAD DATA INFILE - open_basedir +--SKIPIF-- + +--INI-- +safe_mode=0 +open_basedir="." +--FILE-- + +--EXPECTF-- +[006] [1148] %s +[007] [0] '' +[008] LOAD DATA not run? +[010] [1148] %s +done! \ No newline at end of file diff --git a/ext/mysql/tests/mysql_sql_safe_mode.phpt b/ext/mysql/tests/mysql_sql_safe_mode.phpt new file mode 100644 index 0000000000..6c652fb579 --- /dev/null +++ b/ext/mysql/tests/mysql_sql_safe_mode.phpt @@ -0,0 +1,39 @@ +--TEST-- +mysql_[p]connect() - safe_mode +--SKIPIF-- + +--INI-- +sql.safe_mode=1 +--FILE-- + +--EXPECTF-- +Notice: mysql_connect(): SQL safe mode in effect - ignoring host/user/password information in %s on line %d + +Warning: mysql_connect(): Access denied for user '%s'@'%s' (using password: NO) in %s on line %d + +Notice: mysql_pconnect(): SQL safe mode in effect - ignoring host/user/password information in %s on line %d + +Warning: mysql_pconnect(): Access denied for user '%s'@'%s' (using password: NO) in %s on line %d +done! \ No newline at end of file diff --git a/ext/mysql/tests/mysql_trace_mode.phpt b/ext/mysql/tests/mysql_trace_mode.phpt new file mode 100644 index 0000000000..86fa5e081b --- /dev/null +++ b/ext/mysql/tests/mysql_trace_mode.phpt @@ -0,0 +1,33 @@ +--TEST-- +mysql.trace_mode=1 +--SKIPIF-- + +--INI-- +mysql.trace_mode=1 +error_reporting=E_ALL | E_NOTICE | E_STRICT +--FILE-- + +--EXPECTF-- +Notice: mysql_db_query(): This function is deprecated; use mysql_query() instead%sin %s on line %d + +Warning: mysql_escape_string(): This function is deprecated; use mysql_real_escape_string() instead. in %s on line %d +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! + +Warning: Unknown: 1 result set(s) not freed. Use mysql_free_result to free result sets which were requested using mysql_query() in %s on line %d