1#!/usr/bin/env php 2<?php 3if (php_sapi_name() != 'cli') exit(); 4 5//Allow user to select suite 6$selected_test = (isset($argv[1])) ? $argv[1] : false; 7 8require_once 'bootstrap.php'; 9require_once "tests/class.test.php"; 10 11$root = get_osticket_root_path(); 12$fails = array(); 13 14require_once INCLUDE_DIR . 'class.i18n.php'; 15Internationalization::bootstrap(); 16 17require_once INCLUDE_DIR . 'class.signal.php'; 18require_once INCLUDE_DIR . 'class.search.php'; 19 20function show_fails() { 21 global $fails, $root; 22 if ($fails) { 23 echo count($fails) . " FAIL(s)\n"; 24 echo "-------------------------------------------------------\n"; 25 foreach ($fails as $f) { 26 list($test, $script, $line, $message) = $f; 27 $script = str_replace($root.'/', '', $script); 28 print("$test: $message @ $script:$line\n"); 29 } 30 return count($fails); 31 } 32} 33if (function_exists('pcntl_signal')) { 34 declare(ticks=1); 35 function show_fails_on_ctrlc() { 36 while (@ob_end_flush()); 37 print("\n"); 38 exit(show_fails()); 39 } 40 pcntl_signal(SIGINT, 'show_fails_on_ctrlc'); 41} 42 43foreach (glob_recursive(dirname(__file__)."/tests/test.*.php") as $t) { 44 if (strpos($t,"class.") !== false) 45 continue; 46 $class = @(include $t); 47 if (!is_string($class)) 48 continue; 49 if($selected_test && ($class != $selected_test)) 50 continue; 51 $test = new $class(); 52 echo "Running: " . $test->name . "\n"; 53 $test->run(); 54 $fails = array_merge($fails, $test->fails); 55 echo " ok\n"; 56} 57show_fails(); 58 59// If executed directly expose the fail count to a shell script 60global $argv; 61if (!strcasecmp(basename($argv[0]), basename(__file__))) 62 exit(count($fails)); 63else 64 return count($fails); 65?> 66