[ Index ]

PHP Cross Reference of Limb3

title

Body

[close]

/tests_runner/src/ -> lmbTestTreeFileNode.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  require_once(dirname(__FILE__). '/lmbTestTreeTerminalNode.class.php');
  10  
  11  /**

  12   * class lmbTestTreeFileNode.

  13   *

  14   * @package tests_runner

  15   * @version $Id: lmbTestTreeFileNode.class.php 6022 2007-06-28 13:35:51Z pachanga $

  16   */
  17  class lmbTestTreeFileNode extends lmbTestTreeTerminalNode
  18  {
  19    protected static $class_format = '%s.class.php';
  20    protected $file;
  21    protected $class;
  22  
  23    function __construct($file)
  24    {
  25      $this->file = $file;
  26      $this->class = $this->_extractClassName($file);
  27    }
  28  
  29    static function getClassFormat()
  30    {
  31      return self :: $class_format;
  32    }
  33  
  34    static function setClassFormat($format)
  35    {
  36      $prev = self :: $class_format;
  37      self :: $class_format = $format;
  38      return $prev;
  39    }
  40  
  41    function getFile()
  42    {
  43      return $this->file;
  44    }
  45  
  46    function getClass()
  47    {
  48      return $this->class;
  49    }
  50  
  51    protected function _extractClassName($file)
  52    {
  53      $regex = preg_quote(self :: $class_format);
  54      $regex = '~^' . str_replace('%s', '(.*)', $regex) . '$~';
  55  
  56      if(preg_match($regex, basename($file), $m))
  57        return $m[1];
  58    }
  59  
  60    protected function _doCreateTestCase()
  61    {
  62      $suite = new TestSuite(basename($this->file));
  63  
  64      if(!is_null($this->class))
  65      {
  66        require_once($this->file);
  67        if(!class_exists($this->class))
  68          throw new Exception("Class '{$this->class}' not found in '{$this->file}' file!");
  69  
  70        $test = new $this->class();
  71        $suite->addTestCase($test);
  72      }
  73      else
  74        $suite->addFile($this->file);
  75  
  76      return $suite;
  77    }
  78  }
  79  ?>


Generated: Sat Sep 6 04:46:52 2008 Cross-referenced by PHPXref 0.7