[ Index ]

PHP Cross Reference of Web Application Component Toolkit

title

Body

[close]

/tests/ -> remotetests.php (source)

   1  #!/usr/bin/php -q
   2  <?php
   3  /**
   4  * @package WACT_TESTS
   5  * @version $Id: remotetests.php,v 1.5 2004/11/20 18:09:49 jeffmoore Exp $
   6  */
   7  ini_set('memory_limit','128M');
   8  
   9  require_once  'lib/testmanager.php';
  10  require_once  '../framework/common.inc.php';
  11  
  12  TestManager::setTestPathsFromIniFile('tests.ini');
  13  
  14  function usage() {
  15      $usage = <<<EOD
  16  Usage: ./runtests.php [OPTION]...
  17  Run the WACT unit tests remotely executing tests over HTTP and delivering
  18  results to the command line. If ALL of the test cases pass a count of
  19  total passes is printed on STDOUT. If ANY of the test cases fail (or raise
  20  errors) details are printed on STDERR and this script returns a non-zero
  21  exit code.
  22    -u  --url=HTTP_PATH     specify remote server test url (w. index.php)
  23    -f  --file=NAME         specify a test case file
  24    -g  --group=NAME        specify a grouptest. If no grouptest is
  25                            specified, all test cases will be run.
  26    -l  --glist             list available group tests
  27    -c  --clist             list available test case files
  28    -s, --separator=SEP     set the character(s) used to separate fail
  29                            details to SEP
  30    -p, --path              path to SimpleTest installation
  31    -h, --help              display this help and exit
  32  
  33  EOD;
  34      echo $usage;
  35      exit(0);
  36  }
  37  
  38  /* default test options */
  39  $opt_url = FALSE;
  40  $opt_separator = '->';
  41  $opt_group_list = FALSE;
  42  $opt_case_list = FALSE;
  43  $opt_casefile = FALSE;
  44  $opt_groupfile = FALSE;
  45  
  46  /* only allow cmd line options if PEAR Console_Getopt is available */
  47  @include_once 'Console/Getopt.php'; /* PEAR lib */
  48  if (class_exists('Console_Getopt')) {
  49  
  50      $argv = Console_Getopt::readPHPArgv();
  51      if (PEAR::isError($argv)) {
  52          die('Fatal Error: ' . $argv->getMessage()) . "\n";
  53      }
  54  
  55      $short_opts = "u:f:g:hlcs:p:";
  56      $long_opts  = array(
  57          "help", "url=", "file=", "group=",
  58          "glist", "clist", "separator=", "path="
  59          );
  60      $options = Console_Getopt::getopt($argv, $short_opts, $long_opts);
  61      if (PEAR::isError($options)) {
  62          usage($available_grouptests);
  63      }
  64  
  65      foreach ($options[0] as $option) {
  66          switch ($option[0]) {
  67              case 'h':
  68              case '--help':
  69                  usage();
  70                  break;
  71              case 'u':
  72              case '--url':
  73                  $opt_url = $option[1];
  74                  break;                
  75              case 'f':
  76              case '--file':
  77                  $opt_casefile = $option[1];
  78                  break;
  79              case 'g':
  80              case '--group':
  81                  $opt_groupfile = $option[1];
  82                  break;
  83              case 'l':
  84              case '--glist':
  85                  $opt_group_list = TRUE;
  86                  break;
  87              case 'c':
  88              case '--clist':
  89                  $opt_case_list = TRUE;
  90                  break;                
  91              case 's':
  92              case '--separator':
  93                  $opt_separator = $option[1];
  94                  break;
  95              case 'p':
  96              case '--path':
  97                  if (file_exists($option[1])) {
  98                      define('SIMPLE_TEST', $option[1]);
  99                  }
 100                  break;
 101          }
 102      }
 103  }
 104  
 105  
 106  if ( !defined('SIMPLE_TEST') ) {
 107      define('SIMPLE_TEST', ConfigManager::getOptionAsPath('tests', 'simpletest', 'library_path'));
 108  }
 109  if (!@include_once SIMPLE_TEST . 'runner.php') {
 110      RaiseError('runtime', 'LIBRARY_REQUIRED', array(
 111          'library' => 'Simple Test',
 112          'path' => SIMPLE_TEST));
 113  }
 114  require_once  'lib/cli_reporter.php';
 115  
 116  /* list tests */
 117  if ($opt_group_list || $opt_case_list ) {
 118  
 119      if ($opt_group_list) {
 120          $gList = RemoteTestManager::getGroupTestList($opt_url);
 121      
 122          foreach ( $gList as $gName => $gUrl ) {
 123              fwrite(STDOUT,"[$gName] $gUrl\n");
 124          }
 125      }
 126  
 127      if ($opt_case_list) {
 128          $cList = RemoteTestManager::getTestCaseList($opt_url);
 129          
 130          foreach ( $cList as $cName => $cUrl ) {
 131              fwrite(STDOUT,"[$cName] $cUrl\n");
 132          }
 133      }
 134      
 135      exit(0);
 136  }
 137  
 138  /* run a test case */
 139  if ($opt_casefile) {
 140      RemoteTestManager::runTestCase(
 141          $opt_casefile, new CLIReporter($opt_separator), $opt_url
 142          );
 143      exit(0);
 144  }
 145  
 146  /* run a grouptest */
 147  if ($opt_groupfile) {
 148      RemoteTestManager::runGroupTest(
 149          $opt_groupfile, new CLIReporter($opt_separator), $opt_url
 150          );
 151      exit(0);
 152  }
 153  /* run all tests */
 154  RemoteTestManager::runAllTests(new CLIReporter($opt_separator), $opt_url);
 155  exit(0);
 156  ?>


Generated: Sun Nov 28 19:36:09 2004 Cross-referenced by PHPXref 0.5