[ Index ]

PHP Cross Reference of Limb3

title

Body

[close]

/tests_runner/lib/simpletest/ -> autorun.php (source)

   1  <?php
   2      /**

   3       *    Autorunner which runs all tests cases found in a file

   4       *    that includes this module.

   5       *    @package    SimpleTest

   6       *    @version    $Id: autorun.php,v 1.8 2007/05/08 22:08:06 lastcraft Exp $

   7       */
   8      require_once dirname(__FILE__) . '/unit_tester.php';
   9      require_once dirname(__FILE__) . '/mock_objects.php';
  10      require_once dirname(__FILE__) . '/collector.php';
  11      require_once dirname(__FILE__) . '/default_reporter.php';
  12  
  13      $GLOBALS['SIMPLETEST_AUTORUNNER_INITIAL_CLASSES'] = get_declared_classes();
  14      register_shutdown_function('simpletest_autorun');
  15  
  16      function simpletest_autorun() {
  17          if (tests_have_run()) {
  18              return;
  19          }
  20          $candidates = array_intersect(
  21                  capture_new_classes(),
  22                  classes_defined_in_initial_file());
  23          $loader = new SimpleFileLoader();
  24          $suite = $loader->createSuiteFromClasses(
  25                  basename(initial_file()),
  26                  $loader->selectRunnableTests($candidates));
  27          $result = $suite->run(SimpleTest::preferred(
  28                  array('SimpleReporter', 'SimpleReporterDecorator')));
  29          if (SimpleReporter::inCli()) {
  30              exit($result ? 0 : 1);
  31          }
  32      }
  33  
  34  	function tests_have_run() {
  35          if ($context = SimpleTest::getContext()) {
  36              if ($context->getTest()) {
  37                  return true;
  38              }
  39          }
  40          return false;
  41      }
  42      
  43  	function initial_file() {
  44          static $file = false;
  45          if (! $file) {
  46              $file = reset(get_included_files());
  47          }
  48          return $file;
  49      }
  50      
  51  	function classes_defined_in_initial_file() {
  52          if (! preg_match_all('~class\s+(\w+)~', file_get_contents(initial_file()), $matches)) {
  53              return array();
  54          }
  55          return array_map('strtolower', $matches[1]);
  56      }
  57      
  58  	function capture_new_classes() {
  59          global $SIMPLETEST_AUTORUNNER_INITIAL_CLASSES;
  60          return array_map('strtolower', array_diff(get_declared_classes(),
  61                                $SIMPLETEST_AUTORUNNER_INITIAL_CLASSES ?
  62                                $SIMPLETEST_AUTORUNNER_INITIAL_CLASSES : array()));
  63      }
  64  ?>


Generated: Sat Nov 22 03:48:54 2008 Cross-referenced by PHPXref 0.7