[limb-svn] r6000 - in 3.x/trunk/limb/tests_runner: src tests/cases

svn at limb-project.com svn at limb-project.com
Mon Jun 18 18:35:27 MSD 2007


Author: pachanga
Date: 2007-06-18 18:35:27 +0400 (Mon, 18 Jun 2007)
New Revision: 6000
URL: http://fisheye.limb-project.com/changelog/limb/?cs=6000

Added:
   3.x/trunk/limb/tests_runner/src/lmbTestReporterDecorator.class.php
Modified:
   3.x/trunk/limb/tests_runner/src/lmbTestRunner.class.php
   3.x/trunk/limb/tests_runner/src/lmbTestShellUI.class.php
   3.x/trunk/limb/tests_runner/src/lmbTestTree.class.php
   3.x/trunk/limb/tests_runner/tests/cases/lmbTestShellUITest.class.php
Log:
-- lmbTestRunner is now using SimpleTest :: prefer(..), :: preffered(..) utility methods for reporter installation
-- lmbTestReporterDecorator added

Added: 3.x/trunk/limb/tests_runner/src/lmbTestReporterDecorator.class.php
===================================================================
--- 3.x/trunk/limb/tests_runner/src/lmbTestReporterDecorator.class.php	                        (rev 0)
+++ 3.x/trunk/limb/tests_runner/src/lmbTestReporterDecorator.class.php	2007-06-18 14:35:27 UTC (rev 6000)
@@ -0,0 +1,25 @@
+<?php
+/*
+ * Limb PHP Framework
+ *
+ * @link http://limb-project.com
+ * @copyright  Copyright &copy; 2004-2007 BIT(http://bit-creative.com)
+ * @license    LGPL http://www.gnu.org/copyleft/lesser.html
+ */
+
+/**
+ * class lmbTestReporterDecorator.
+ *
+ * @package tests_runner
+ * @version $Id$
+ */
+class lmbTestReporterDecorator extends SimpleReporterDecorator
+{
+  function paintCaseEnd($test_name)
+  {
+    $this->_reporter->paintCaseEnd($test_name);
+
+    echo $this->_reporter->getTestCaseProgress() . " of " . $this->_reporter->getTestCaseCount() . " done({$test_name})\n";
+  }
+}
+?>
\ No newline at end of file

Modified: 3.x/trunk/limb/tests_runner/src/lmbTestRunner.class.php
===================================================================
--- 3.x/trunk/limb/tests_runner/src/lmbTestRunner.class.php	2007-06-18 13:13:08 UTC (rev 5999)
+++ 3.x/trunk/limb/tests_runner/src/lmbTestRunner.class.php	2007-06-18 14:35:27 UTC (rev 6000)
@@ -1,22 +1,22 @@
 <?php
-/*
- * Limb PHP Framework
- *
- * @link http://limb-project.com 
- * @copyright  Copyright &copy; 2004-2007 BIT(http://bit-creative.com)
- * @license    LGPL http://www.gnu.org/copyleft/lesser.html 
- */
-
+/*
+ * Limb PHP Framework
+ *
+ * @link http://limb-project.com
+ * @copyright  Copyright &copy; 2004-2007 BIT(http://bit-creative.com)
+ * @license    LGPL http://www.gnu.org/copyleft/lesser.html
+ */
+
 /**
  * class lmbTestRunner.
  *
  * @package tests_runner
  * @version $Id$
- */
+ */
 class lmbTestRunner
 {
   protected $test_paths = array();
-  protected $test_reporter;
+  protected $reporter;
   protected $coverage;
   protected $coverage_reporter;
   protected $coverage_include;
@@ -33,9 +33,9 @@
       $this->test_paths = $test_path;
   }
 
-  function setTestReporter($reporter)
+  function setReporter($reporter)
   {
-    $this->test_reporter = $reporter;
+    $this->reporter = $reporter;
   }
 
   function useCoverage($coverage_include, $coverage_exclude, $coverage_report_dir)
@@ -68,8 +68,7 @@
         $root_dir = $this->_getRootDir($file);
         $node = $this->_mapFileToNode($root_dir, $file);
         $tree = $this->_initTree($root_dir);
-        //we need fresh reporter every time
-        $res = $res & $tree->perform($node, clone($this->_getReporter()));
+        $res = $res & $tree->perform($node, $this->_getReporter());
       }
     }
     return $res;
@@ -77,21 +76,14 @@
 
   protected function _startTimer()
   {
-    $this->start_time = $this->_getMicrotime();
+    $this->start_time = microtime(true);
   }
 
   protected function _stopTimer()
   {
-    $this->end_time = $this->_getMicrotime();
+    $this->end_time = microtime(true);
   }
 
-  protected function _getMicrotime()
-  {
-    $t_time = explode(' ', microtime());
-    preg_match("~0\.([0-9]+)~", '' . $t_time[0], $t1);
-    return $t_time[1] . '.' . $t1[1];
-  }
-
   function getRunTime()
   {
     return round($this->end_time - $this->start_time, 3);
@@ -175,13 +167,23 @@
 
   protected function _getReporter()
   {
-    if($this->test_reporter)
-      return $this->test_reporter;
+    if(!$this->reporter)
+    {
+      if($this->_simpleTestDefaultReporterInstalled())
+      {
+        require_once(dirname(__FILE__) . '/lmbTestShellReporter.class.php');
+        SimpleTest :: prefer(new lmbTestShellReporter());
+      }
+      return clone(SimpleTest :: preferred(array('SimpleReporter', 'SimpleReporterDecorator')));
+    }
+    else
+      return clone($this->reporter);
+  }
 
-    require_once(dirname(__FILE__) . '/lmbTestShellReporter.class.php');
-    $this->test_reporter = new lmbTestShellReporter();
-
-    return $this->test_reporter;
+  protected function _simpleTestDefaultReporterInstalled()
+  {
+    $reporter = SimpleTest :: preferred(array('SimpleReporter', 'SimpleReporterDecorator'));
+    return get_class($reporter) == 'DefaultReporter';
   }
 }
 

Modified: 3.x/trunk/limb/tests_runner/src/lmbTestShellUI.class.php
===================================================================
--- 3.x/trunk/limb/tests_runner/src/lmbTestShellUI.class.php	2007-06-18 13:13:08 UTC (rev 5999)
+++ 3.x/trunk/limb/tests_runner/src/lmbTestShellUI.class.php	2007-06-18 14:35:27 UTC (rev 6000)
@@ -21,6 +21,7 @@
   protected $argv;
   protected $posix_opts = true;
   protected $call_exit = true;
+  protected $reporter;
 
   function __construct($argv = null)
   {
@@ -34,6 +35,11 @@
     }
   }
 
+  function setReporter($reporter)
+  {
+    $this->reporter = $reporter;
+  }
+
   function setPosixMode($flag = true)
   {
     $this->posix_opts = $flag;
@@ -181,6 +187,9 @@
 
     $runner = new lmbTestRunner($options[1]);
 
+    if($this->reporter)
+      $runner->setReporter($this->reporter);
+
     if($cover_include)
       $runner->useCoverage($cover_include, $cover_exclude, $cover_report_dir);
 

Modified: 3.x/trunk/limb/tests_runner/src/lmbTestTree.class.php
===================================================================
--- 3.x/trunk/limb/tests_runner/src/lmbTestTree.class.php	2007-06-18 13:13:08 UTC (rev 5999)
+++ 3.x/trunk/limb/tests_runner/src/lmbTestTree.class.php	2007-06-18 14:35:27 UTC (rev 6000)
@@ -1,18 +1,18 @@
 <?php
-/*
- * Limb PHP Framework
- *
- * @link http://limb-project.com 
- * @copyright  Copyright &copy; 2004-2007 BIT(http://bit-creative.com)
- * @license    LGPL http://www.gnu.org/copyleft/lesser.html 
- */
-
+/*
+ * Limb PHP Framework
+ *
+ * @link http://limb-project.com
+ * @copyright  Copyright &copy; 2004-2007 BIT(http://bit-creative.com)
+ * @license    LGPL http://www.gnu.org/copyleft/lesser.html
+ */
+
 /**
  * class lmbTestTree.
  *
  * @package tests_runner
  * @version $Id$
- */
+ */
 class lmbTestTree
 {
   protected $root_node;

Modified: 3.x/trunk/limb/tests_runner/tests/cases/lmbTestShellUITest.class.php
===================================================================
--- 3.x/trunk/limb/tests_runner/tests/cases/lmbTestShellUITest.class.php	2007-06-18 13:13:08 UTC (rev 5999)
+++ 3.x/trunk/limb/tests_runner/tests/cases/lmbTestShellUITest.class.php	2007-06-18 14:35:27 UTC (rev 6000)
@@ -1,10 +1,10 @@
 <?php
-/*
- * Limb PHP Framework
- *
- * @link http://limb-project.com 
- * @copyright  Copyright &copy; 2004-2007 BIT(http://bit-creative.com)
- * @license    LGPL http://www.gnu.org/copyleft/lesser.html 
+/*
+ * Limb PHP Framework
+ *
+ * @link http://limb-project.com
+ * @copyright  Copyright &copy; 2004-2007 BIT(http://bit-creative.com)
+ * @license    LGPL http://www.gnu.org/copyleft/lesser.html
  */
 require_once(dirname(__FILE__) . '/../common.inc.php');
 require_once(dirname(__FILE__) . '/../../src/lmbTestShellUI.class.php');
@@ -120,8 +120,10 @@
 define('LIMB_VAR_DIR', dirname(__FILE__) . '/var');
 require_once('$dir/../../common.inc.php');
 require_once('$dir/../../src/lmbTestShellUI.class.php');
+require_once('$dir/../../src/lmbTestShellReporter.class.php');
 
 \$ui = new lmbTestShellUI();
+\$ui->setReporter(new lmbTestShellReporter());
 \$ui->run();
 ?>
 EOD;



More information about the limb-svn mailing list