[ Index ]

PHP Cross Reference of Limb3

title

Body

[close]

/tests_runner/src/ -> lmbTestRunner.class.php (source)

   1  <?php
   2  /*

   3   * Limb PHP Framework

   4   *

   5   * @link http://limb-project.com

   6   * @copyright  Copyright &copy; 2004-2007 BIT(http://bit-creative.com)

   7   * @license    LGPL http://www.gnu.org/copyleft/lesser.html

   8   */
   9  
  10  /**

  11   * class lmbTestRunner.

  12   *

  13   * @package tests_runner

  14   * @version $Id$

  15   */
  16  class lmbTestRunner
  17  {
  18    protected $reporter;
  19    protected $coverage;
  20    protected $coverage_reporter;
  21    protected $coverage_include;
  22    protected $coverage_exclude;
  23    protected $coverage_report_dir;
  24    protected $start_time = 0;
  25    protected $end_time = 0;
  26  
  27    function setReporter($reporter)
  28    {
  29      $this->reporter = $reporter;
  30    }
  31  
  32    function useCoverage($coverage_include, $coverage_exclude, $coverage_report_dir)
  33    {
  34      $this->coverage_include = $coverage_include;
  35      $this->coverage_exclude = $coverage_exclude;
  36      $this->coverage_report_dir = $coverage_report_dir;
  37    }
  38  
  39    function run($root_node, $path='/')
  40    {
  41      require_once(dirname(__FILE__) . '/../simpletest.inc.php');
  42  
  43      $this->_startTimer();
  44      $this->_startCoverage();
  45  
  46      $res = $this->_doRun($root_node, $path);
  47  
  48      $this->_endCoverage();
  49      $this->_stopTimer();
  50      return $res;
  51    }
  52  
  53    protected function _doRun($node, $path)
  54    {
  55      if(!$sub_node = $node->findChildByPath($path))
  56        throw new Exception("Test node '$path' not found!");
  57  
  58      $test = $sub_node->createTestCase();
  59      return $test->run($this->_getReporter());
  60    }
  61  
  62    protected function _startTimer()
  63    {
  64      $this->start_time = microtime(true);
  65    }
  66  
  67    protected function _stopTimer()
  68    {
  69      $this->end_time = microtime(true);
  70    }
  71  
  72    function getRunTime()
  73    {
  74      return round($this->end_time - $this->start_time, 3);
  75    }
  76  
  77    protected function _startCoverage()
  78    {
  79      if(!$this->coverage_include)
  80        return;
  81  
  82      @define('__PHPCOVERAGE_HOME', dirname(__FILE__) . '/../lib/spikephpcoverage/src/');
  83      require_once(__PHPCOVERAGE_HOME . '/CoverageRecorder.php');
  84      require_once(__PHPCOVERAGE_HOME . '/reporter/HtmlCoverageReporter.php');
  85  
  86      $this->coverage_reporter = new HtmlCoverageReporter("Code Coverage Report", "",
  87                                                          $this->coverage_report_dir);
  88  
  89      $include_paths = explode(';', $this->coverage_include);
  90      $exclude_paths = explode(';', $this->coverage_exclude);
  91      $this->coverage = new CoverageRecorder($include_paths, $exclude_paths, $this->coverage_reporter);
  92      $this->coverage->startInstrumentation();
  93    }
  94  
  95    protected function _endCoverage()
  96    {
  97      if($this->coverage)
  98      {
  99        $this->coverage->stopInstrumentation();
 100        $this->coverage->generateReport();
 101        $this->coverage_reporter->printTextSummary();
 102      }
 103    }
 104  
 105    protected function _getReporter()
 106    {
 107      if(!$this->reporter)
 108      {
 109        if($this->_simpleTestDefaultReporterInstalled())
 110        {
 111          require_once(dirname(__FILE__) . '/lmbTestShellReporter.class.php');
 112          SimpleTest :: prefer(new lmbTestShellReporter());
 113        }
 114        return clone(SimpleTest :: preferred(array('SimpleReporter', 'SimpleReporterDecorator')));
 115      }
 116      else
 117        return clone($this->reporter);
 118    }
 119  
 120    protected function _simpleTestDefaultReporterInstalled()
 121    {
 122      $reporter = SimpleTest :: preferred(array('SimpleReporter', 'SimpleReporterDecorator'));
 123      return get_class($reporter) == 'DefaultReporter';
 124    }
 125  }
 126  
 127  ?>


Generated: Tue Dec 2 03:54:09 2008 Cross-referenced by PHPXref 0.7