Annotation of embedaddon/php/ext/mysqli/tests/mysqli_debug_append.phpt, revision 1.1.1.1

1.1       misho       1: --TEST--
                      2: mysqli_debug() - append to trace file
                      3: --SKIPIF--
                      4: <?php
                      5: require_once('skipif.inc');
                      6: require_once('skipifemb.inc');
                      7: require_once('skipifconnectfailure.inc');
                      8: 
                      9: if (!function_exists('mysqli_debug'))
                     10:        die("skip: mysqli_debug() not available");
                     11: 
                     12: if (!defined('MYSQLI_DEBUG_TRACE_ENABLED'))
                     13:        die("skip: can't say for sure if mysqli_debug works");
                     14: 
                     15: if (defined('MYSQLI_DEBUG_TRACE_ENABLED') && !MYSQLI_DEBUG_TRACE_ENABLED)
                     16:        die("skip: debug functionality not enabled");
                     17: 
                     18: if (!$IS_MYSQLND)
                     19:        die("SKIP Libmysql feature not sufficiently spec'd in MySQL C API documentation");
                     20: ?>
                     21: --FILE--
                     22: <?php
                     23:        require_once('connect.inc');;
                     24: 
                     25:        if (true !== ($tmp = mysqli_debug(sprintf('d:t:O,%s/mysqli_debug_phpt.trace', sys_get_temp_dir()))))
                     26:                printf("[001] Expecting boolean/true, got %s/%s\n", gettype($tmp), $tmp);
                     27: 
                     28:        // table.inc will create a database connection and run some SQL queries, therefore
                     29:        // the debug file should have entries
                     30:        require_once('table.inc');
                     31: 
                     32:        clearstatcache();
                     33:        $trace_file = sprintf('%s/mysqli_debug_phpt.trace', sys_get_temp_dir());
                     34:        if (!file_exists($trace_file))
                     35:                printf("[002] Trace file '%s' has not been created\n", $trace_file);
                     36:        if (filesize($trace_file) < 50)
                     37:                printf("[003] Trace file '%s' is very small. filesize() reports only %d bytes. Please check.\n",
                     38:                        $trace_file,
                     39:                        filesize($trace_file));
                     40: 
                     41:        // will mysqli_debug() mind if the trace file gets removed?
                     42:        unlink($trace_file);
                     43:        clearstatcache();
                     44: 
                     45:        if (!$fp = fopen($trace_file, 'w')) {
                     46:                printf("[004] Cannot create trace file to test append mode\n");
                     47:        } else {
                     48: 
                     49:                if (!fwrite($fp, (binary) 'mysqli_debug.phpt test line'))
                     50:                        printf("[005] Cannot write to trace file.\n");
                     51:                fclose($fp);
                     52: 
                     53:                if (true !== ($tmp = mysqli_debug(sprintf('d:a,%s', $trace_file))))
                     54:                        printf("[006] Expecting boolean/true, got %s/%s\n", gettype($tmp), $tmp);
                     55: 
                     56:                if (!$res = mysqli_query($link, 'SELECT * FROM test'))
                     57:                        printf("[007] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
                     58:                else
                     59:                        mysqli_free_result($res);
                     60: 
                     61:                $trace = file_get_contents($trace_file);
                     62:                if (!strstr($trace, 'mysqli_debug.phpt test line'))
                     63:                        printf("[008] Cannot find original file content any more. Seems that the trace file got overwritten and not appended. Please check.");
                     64: 
                     65:                if (true !== ($tmp = mysqli_debug(sprintf('d:A,%s', $trace_file))))
                     66:                        printf("[009] Expecting boolean/true, got %s/%s\n", gettype($tmp), $tmp);
                     67: 
                     68:                if (!$res = mysqli_query($link, 'SELECT * FROM test'))
                     69:                        printf("[010] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
                     70:                else
                     71:                        mysqli_free_result($res);
                     72: 
                     73:                if (!strstr(file_get_contents($trace_file), $trace))
                     74:                        printf("[011] Cannot find original file content any more. Seems that the trace file got overwritten and not appended. Please check.");
                     75:        }
                     76: 
                     77:        // what will happen if we create new trace entries...?
                     78:        unlink($trace_file);
                     79:        clearstatcache();
                     80:        if (file_exists($trace_file))
                     81:                printf("[012] Could not remove trace file '%s'.\n", $trace_file);
                     82: 
                     83:        mysqli_close($link);
                     84:        print "done";
                     85:        if ($IS_MYSQLND)
                     86:                print "libmysql/DBUG package prints some debug info here."
                     87: ?>
                     88: --CLEAN--
                     89: <?php
                     90:        require_once("clean_table.inc");
                     91: ?>
                     92: --EXPECTF--
                     93: done%s

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>