[limb-svn] r6230 - in 3.x/trunk/limb/tests_runner: src tests
svn at limb-project.com
svn at limb-project.com
Fri Aug 10 10:03:04 MSD 2007
Author: pachanga
Date: 2007-08-10 10:03:04 +0400 (Fri, 10 Aug 2007)
New Revision: 6230
URL: http://fisheye.limb-project.com/changelog/limb/?cs=6230
Modified:
3.x/trunk/limb/tests_runner/src/lmbTestFileFilter.class.php
3.x/trunk/limb/tests_runner/src/lmbTestGroup.class.php
3.x/trunk/limb/tests_runner/src/lmbTestHTMLReporter.class.php
3.x/trunk/limb/tests_runner/src/lmbTestReporterDecorator.class.php
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/lmbTestTreeDirNode.class.php
3.x/trunk/limb/tests_runner/src/lmbTestTreeFileNode.class.php
3.x/trunk/limb/tests_runner/src/lmbTestTreeFilePathNode.class.php
3.x/trunk/limb/tests_runner/src/lmbTestTreeGlobNode.class.php
3.x/trunk/limb/tests_runner/src/lmbTestTreeNode.class.php
3.x/trunk/limb/tests_runner/src/lmbTestTreePath.class.php
3.x/trunk/limb/tests_runner/src/lmbTestTreeShallowDirNode.class.php
3.x/trunk/limb/tests_runner/src/lmbTestTreeTerminalNode.class.php
3.x/trunk/limb/tests_runner/src/lmbTestUserException.class.php
3.x/trunk/limb/tests_runner/src/lmbTestWebUI.class.php
3.x/trunk/limb/tests_runner/tests/common.inc.php
3.x/trunk/limb/tests_runner/tests/test_self.php
Log:
-- lmbTestTreeNode :: getTestLabel() now simply returns a label without asking the test case, this allows to output more user friendly labels
-- lmbTetsTreeNode :: _doCreateTestCase() now passes getTestLabel() as a label of the new test case, this allowed to remove code duplication in lmbTestTreeShallowDirNode and lmbTestTreeFileNode
-- lmbTestTreeFileNode uses _prepareTestCase() to customize the test case instead of _doCreateTestCase
Modified: 3.x/trunk/limb/tests_runner/src/lmbTestFileFilter.class.php
===================================================================
--- 3.x/trunk/limb/tests_runner/src/lmbTestFileFilter.class.php 2007-08-09 08:49:12 UTC (rev 6229)
+++ 3.x/trunk/limb/tests_runner/src/lmbTestFileFilter.class.php 2007-08-10 06:03:04 UTC (rev 6230)
@@ -1,4 +1,4 @@
-<?php
+<?php
/*
* Limb PHP Framework
*
@@ -7,33 +7,33 @@
* @license LGPL http://www.gnu.org/copyleft/lesser.html
*/
-/**
- * class lmbTestFileFilter.
- *
- * @package tests_runner
- * @version $Id$
+/**
+ * class lmbTestFileFilter.
+ *
+ * @package tests_runner
+ * @version $Id$
*/
-class lmbTestFileFilter
-{
- protected $regex;
-
- function __construct($filters)
- {
- $this->regex = $this->_createRegex($filters);
- }
-
- function match($item)
- {
- return preg_match($this->regex, basename($item));
- }
-
- protected function _createRegex($filters)
- {
- $regex = implode('|', $filters);
- $regex = preg_quote($regex);
- $regex = str_replace(array('\*', '\|'), array('.*', '|'), $regex);
- return '~^(?:' . $regex. ')$~';
- }
-}
-
-
+class lmbTestFileFilter
+{
+ protected $regex;
+
+ function __construct($filters)
+ {
+ $this->regex = $this->_createRegex($filters);
+ }
+
+ function match($item)
+ {
+ return preg_match($this->regex, basename($item));
+ }
+
+ protected function _createRegex($filters)
+ {
+ $regex = implode('|', $filters);
+ $regex = preg_quote($regex);
+ $regex = str_replace(array('\*', '\|'), array('.*', '|'), $regex);
+ return '~^(?:' . $regex. ')$~';
+ }
+}
+
+
Modified: 3.x/trunk/limb/tests_runner/src/lmbTestGroup.class.php
===================================================================
--- 3.x/trunk/limb/tests_runner/src/lmbTestGroup.class.php 2007-08-09 08:49:12 UTC (rev 6229)
+++ 3.x/trunk/limb/tests_runner/src/lmbTestGroup.class.php 2007-08-10 06:03:04 UTC (rev 6230)
@@ -1,43 +1,43 @@
-<?php
-/*
- * Limb PHP Framework
- *
- * @link http://limb-project.com
- * @copyright Copyright © 2004-2007 BIT(http://bit-creative.com)
- * @license LGPL http://www.gnu.org/copyleft/lesser.html
- */
-
-/**
- * class lmbTestGroup.
- *
- * @package tests_runner
- * @version $Id$
- */
-class lmbTestGroup extends TestSuite
-{
- protected $_fixtures = array();
-
- function addFixture($fixture)
- {
- $this->_fixtures[] = $fixture;
- //fixture is setup once added, since fixture may contain some stuff
- //required even before actual tests execution
- $fixture->setup();
- }
-
- function run($reporter)
- {
- $res = parent :: run($reporter);
-
- $this->_tearDownFixture();
-
- return $res;
- }
-
- protected function _tearDownFixture()
- {
- foreach(array_reverse($this->_fixtures) as $fixture)
- $fixture->tearDown();
- }
-}
-
+<?php
+/*
+ * Limb PHP Framework
+ *
+ * @link http://limb-project.com
+ * @copyright Copyright © 2004-2007 BIT(http://bit-creative.com)
+ * @license LGPL http://www.gnu.org/copyleft/lesser.html
+ */
+
+/**
+ * class lmbTestGroup.
+ *
+ * @package tests_runner
+ * @version $Id$
+ */
+class lmbTestGroup extends TestSuite
+{
+ protected $_fixtures = array();
+
+ function addFixture($fixture)
+ {
+ $this->_fixtures[] = $fixture;
+ //fixture is setup once added, since fixture may contain some stuff
+ //required even before actual tests execution
+ $fixture->setup();
+ }
+
+ function run($reporter)
+ {
+ $res = parent :: run($reporter);
+
+ $this->_tearDownFixture();
+
+ return $res;
+ }
+
+ protected function _tearDownFixture()
+ {
+ foreach(array_reverse($this->_fixtures) as $fixture)
+ $fixture->tearDown();
+ }
+}
+
Modified: 3.x/trunk/limb/tests_runner/src/lmbTestHTMLReporter.class.php
===================================================================
--- 3.x/trunk/limb/tests_runner/src/lmbTestHTMLReporter.class.php 2007-08-09 08:49:12 UTC (rev 6229)
+++ 3.x/trunk/limb/tests_runner/src/lmbTestHTMLReporter.class.php 2007-08-10 06:03:04 UTC (rev 6230)
@@ -1,4 +1,4 @@
-<?php
+<?php
/*
* Limb PHP Framework
*
@@ -7,12 +7,12 @@
* @license LGPL http://www.gnu.org/copyleft/lesser.html
*/
-/**
- * class lmbTestHTMLReporter.
- *
- * @package tests_runner
- * @version $Id$
+/**
+ * class lmbTestHTMLReporter.
+ *
+ * @package tests_runner
+ * @version $Id$
*/
-class lmbTestHTMLReporter extends HTMLReporter{}
-
-
+class lmbTestHTMLReporter extends HTMLReporter{}
+
+
Modified: 3.x/trunk/limb/tests_runner/src/lmbTestReporterDecorator.class.php
===================================================================
--- 3.x/trunk/limb/tests_runner/src/lmbTestReporterDecorator.class.php 2007-08-09 08:49:12 UTC (rev 6229)
+++ 3.x/trunk/limb/tests_runner/src/lmbTestReporterDecorator.class.php 2007-08-10 06:03:04 UTC (rev 6230)
@@ -1,25 +1,25 @@
-<?php
-/*
- * Limb PHP Framework
- *
- * @link http://limb-project.com
- * @copyright Copyright © 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";
- }
-}
-
+<?php
+/*
+ * Limb PHP Framework
+ *
+ * @link http://limb-project.com
+ * @copyright Copyright © 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";
+ }
+}
+
Modified: 3.x/trunk/limb/tests_runner/src/lmbTestRunner.class.php
===================================================================
--- 3.x/trunk/limb/tests_runner/src/lmbTestRunner.class.php 2007-08-09 08:49:12 UTC (rev 6229)
+++ 3.x/trunk/limb/tests_runner/src/lmbTestRunner.class.php 2007-08-10 06:03:04 UTC (rev 6230)
@@ -1,130 +1,130 @@
-<?php
-/*
- * Limb PHP Framework
- *
- * @link http://limb-project.com
- * @copyright Copyright © 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 $reporter;
- protected $coverage;
- protected $coverage_reporter;
- protected $coverage_include;
- protected $coverage_exclude;
- protected $coverage_report_dir;
- protected $start_time = 0;
- protected $end_time = 0;
-
- function setReporter($reporter)
- {
- $this->reporter = $reporter;
- }
-
- function useCoverage($coverage_include, $coverage_exclude, $coverage_report_dir)
- {
- if(is_string($coverage_include))
- $this->coverage_include = explode(';', $coverage_include);
-
- if(is_string($coverage_exclude))
- $this->coverage_exclude = explode(';', $coverage_exclude);
-
- $this->coverage_report_dir = $coverage_report_dir;
- }
-
- function run($root_node, $path='/')
- {
- require_once(dirname(__FILE__) . '/../simpletest.inc.php');
-
- $this->_startTimer();
- $this->_startCoverage();
-
- $res = $this->_doRun($root_node, $path);
-
- $this->_endCoverage();
- $this->_stopTimer();
- return $res;
- }
-
- protected function _doRun($node, $path)
- {
- if(!$sub_node = $node->findChildByPath($path))
- throw new Exception("Test node '$path' not found!");
-
- $test = $sub_node->createTestCase();
- return $test->run($this->_getReporter());
- }
-
- protected function _startTimer()
- {
- $this->start_time = microtime(true);
- }
-
- protected function _stopTimer()
- {
- $this->end_time = microtime(true);
- }
-
- function getRunTime()
- {
- return round($this->end_time - $this->start_time, 3);
- }
-
- protected function _startCoverage()
- {
- if(!$this->coverage_include)
- return;
-
- @define('__PHPCOVERAGE_HOME', dirname(__FILE__) . '/../lib/spikephpcoverage/src/');
- require_once(__PHPCOVERAGE_HOME . '/CoverageRecorder.php');
- require_once(__PHPCOVERAGE_HOME . '/reporter/HtmlCoverageReporter.php');
-
- $this->coverage_reporter = new HtmlCoverageReporter("Code Coverage Report", "",
- $this->coverage_report_dir);
-
- $this->coverage = new CoverageRecorder($this->coverage_include, $this->coverage_exclude, $this->coverage_reporter);
- $this->coverage->startInstrumentation();
- }
-
- protected function _endCoverage()
- {
- if($this->coverage)
- {
- $this->coverage->stopInstrumentation();
- if($this->coverage_report_dir)
- $this->coverage->generateReport();
- $this->coverage_reporter->printTextSummary();
- }
- }
-
- protected function _getReporter()
- {
- 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);
- }
-
- protected function _simpleTestDefaultReporterInstalled()
- {
- $reporter = SimpleTest :: preferred(array('SimpleReporter', 'SimpleReporterDecorator'));
- return get_class($reporter) == 'DefaultReporter';
- }
-}
-
-
+<?php
+/*
+ * Limb PHP Framework
+ *
+ * @link http://limb-project.com
+ * @copyright Copyright © 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 $reporter;
+ protected $coverage;
+ protected $coverage_reporter;
+ protected $coverage_include;
+ protected $coverage_exclude;
+ protected $coverage_report_dir;
+ protected $start_time = 0;
+ protected $end_time = 0;
+
+ function setReporter($reporter)
+ {
+ $this->reporter = $reporter;
+ }
+
+ function useCoverage($coverage_include, $coverage_exclude, $coverage_report_dir)
+ {
+ if(is_string($coverage_include))
+ $this->coverage_include = explode(';', $coverage_include);
+
+ if(is_string($coverage_exclude))
+ $this->coverage_exclude = explode(';', $coverage_exclude);
+
+ $this->coverage_report_dir = $coverage_report_dir;
+ }
+
+ function run($root_node, $path='/')
+ {
+ require_once(dirname(__FILE__) . '/../simpletest.inc.php');
+
+ $this->_startTimer();
+ $this->_startCoverage();
+
+ $res = $this->_doRun($root_node, $path);
+
+ $this->_endCoverage();
+ $this->_stopTimer();
+ return $res;
+ }
+
+ protected function _doRun($node, $path)
+ {
+ if(!$sub_node = $node->findChildByPath($path))
+ throw new Exception("Test node '$path' not found!");
+
+ $test = $sub_node->createTestCase();
+ return $test->run($this->_getReporter());
+ }
+
+ protected function _startTimer()
+ {
+ $this->start_time = microtime(true);
+ }
+
+ protected function _stopTimer()
+ {
+ $this->end_time = microtime(true);
+ }
+
+ function getRunTime()
+ {
+ return round($this->end_time - $this->start_time, 3);
+ }
+
+ protected function _startCoverage()
+ {
+ if(!$this->coverage_include)
+ return;
+
+ @define('__PHPCOVERAGE_HOME', dirname(__FILE__) . '/../lib/spikephpcoverage/src/');
+ require_once(__PHPCOVERAGE_HOME . '/CoverageRecorder.php');
+ require_once(__PHPCOVERAGE_HOME . '/reporter/HtmlCoverageReporter.php');
+
+ $this->coverage_reporter = new HtmlCoverageReporter("Code Coverage Report", "",
+ $this->coverage_report_dir);
+
+ $this->coverage = new CoverageRecorder($this->coverage_include, $this->coverage_exclude, $this->coverage_reporter);
+ $this->coverage->startInstrumentation();
+ }
+
+ protected function _endCoverage()
+ {
+ if($this->coverage)
+ {
+ $this->coverage->stopInstrumentation();
+ if($this->coverage_report_dir)
+ $this->coverage->generateReport();
+ $this->coverage_reporter->printTextSummary();
+ }
+ }
+
+ protected function _getReporter()
+ {
+ 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);
+ }
+
+ 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-08-09 08:49:12 UTC (rev 6229)
+++ 3.x/trunk/limb/tests_runner/src/lmbTestShellUI.class.php 2007-08-10 06:03:04 UTC (rev 6230)
@@ -1,239 +1,239 @@
-<?php
-/*
- * Limb PHP Framework
- *
- * @link http://limb-project.com
- * @copyright Copyright © 2004-2007 BIT(http://bit-creative.com)
- * @license LGPL http://www.gnu.org/copyleft/lesser.html
- */
-require_once(dirname(__FILE__) . '/lmbTestGetopt.class.php');
-
-/**
- * class lmbTestShellUI.
- *
- * @package tests_runner
- * @version $Id$
- */
-class lmbTestShellUI
-{
- protected $test_path;
- protected $argv;
- protected $posix_opts = true;
- protected $call_exit = true;
- protected $reporter;
-
- function __construct($argv = null)
- {
- try
- {
- $this->argv = is_array($argv) ? $argv : lmbTestGetopt::readPHPArgv();
- }
- catch(Exception $e)
- {
- $this->_error($e->getMessage() . "\n");
- }
- }
-
- function setReporter($reporter)
- {
- $this->reporter = $reporter;
- }
-
- function setPosixMode($flag = true)
- {
- $this->posix_opts = $flag;
- }
-
- function exitAfterRun($flag = true)
- {
- $this->call_exit = $flag;
- }
-
- function help($script = '')
- {
- $version = $this->_getVersion();
-
- $usage = <<<EOD
-Usage:
- limb_unit [OPTIONS] <file|dir> [<file1|dir1>, ... <fileN|dirN>]
- Advanced SimpleTest unit tests runner. Finds and executes unit tests within filesystem.
-Arguments:
- <file|dir> [<file1|dir1>, ... <fileN|dirN>] - a list of files/directories, globs are supported(e.g. '*')
-Options:
- -h, --help Displays this help and exit
- -c, --config=/file.php PHP configuration file path
- -I, --include='filter1;filter2' Sets file filters used for including test files during
- recursive traversal of directories.
- '*Test.class.php;*test.php;*Test.php' by default.
- -C, --cover=path1;path2 Sets paths delimitered with ';' which should be analyzed
- for test coverage(requires XDebug extension!)
- --cover-report=dir Sets coverage report directory
- --cover-exclude=path1;path2 Sets paths delimitered with ';' which should be excluded
- from coverage analysis
-
-$version
-
-EOD;
- return $usage;
- }
-
- protected function _help($code = 0)
- {
- echo $this->help();
- exit($code);
- }
-
- protected function _error($message, $code = 1)
- {
- echo "ERROR: $message\n\n";
- echo $this->_getVersion();
- echo "\n";
- exit($code);
- }
-
- protected function _version()
- {
- echo $this->_getVersion() . "\n";
- exit();
- }
-
- protected function _getVersion()
- {
- list(, $number, $status) = explode('-', trim(file_get_contents(dirname(__FILE__) . '/../VERSION')));
- return "limb_unit-$number-$status";
- }
-
- static function getShortOpts()
- {
- return 'hvI:c:C:';
- }
-
- static function getLongOpts()
- {
- return array('help', 'version', 'include=', 'config=', 'cover=', 'cover-report=', 'cover-exclude=');
- }
-
- function run()
- {
- $res = $this->_doRun();
-
- if($this->call_exit)
- exit($res ? 0 : 1);
- else
- return $res;
- }
-
- function runEmbedded()
- {
- return $this->_doRun();
- }
-
- protected function _doRun()
- {
- $short_opts = self :: getShortOpts();
- $long_opts = self :: getLongOpts();
-
- try
- {
- if($this->posix_opts)
- $options = lmbTestGetopt :: getopt($this->argv, $short_opts, $long_opts);
- else
- $options = lmbTestGetopt :: getopt2($this->argv, $short_opts, $long_opts);
- }
- catch(Exception $e)
- {
- $this->_help(1);
- }
-
- lmbTestGetopt :: defineConstants($this->argv);
-
- $config_file = null;
- $cover_include = '';
- $cover_exclude = '';
- $cover_report_dir = null;
-
- foreach($options[0] as $option)
- {
- switch($option[0])
- {
- case 'h':
- case '--help':
- $this->_help(0);
- break;
- case 'v':
- case '--version':
- $this->_version();
- break;
- case 'c':
- case '--config':
- $config_file = $option[1];
- break;
- case 'I':
- case '--include':
- @define('LIMB_TESTS_RUNNER_FILE_FILTER', $option[1]);
- break;
- case 'C':
- case '--cover':
- $cover_include = $option[1];
- break;
- case '--cover-report':
- $cover_report_dir = $option[1];
- break;
- case '--cover-exclude':
- $cover_exclude = $option[1];
- break;
- }
- }
-
- if($config_file)
- {
- if(!@include_once(realpath($config_file)))
- $this->_error("Could not include configuration file '$config_file'\n");
- }
- else if($config_file = getenv('LIMB_TESTS_RUNNER_CONFIG'))
- {
- if(!@include_once($config_file))
- $this->_error("Could not include configuration file specified in LIMB_TESTS_RUNNER_CONFIG env. variable as '$config_file'\n");
- }
-
- if(!is_array($options[1]) || !count($options[1]))
- $paths = array('.');
- else
- $paths = $options[1];
-
- if(!$cover_report_dir && defined('LIMB_TESTS_RUNNER_COVERAGE_REPORT_DIR'))
- $cover_report_dir = LIMB_TESTS_RUNNER_COVERAGE_REPORT_DIR;
-
- require_once(dirname(__FILE__) . '/lmbTestRunner.class.php');
- $runner = new lmbTestRunner();
-
- if($this->reporter)
- $runner->setReporter($this->reporter);
-
- if($cover_include)
- $runner->useCoverage($cover_include, $cover_exclude, $cover_report_dir);
-
- try
- {
- require_once(dirname(__FILE__) . '/lmbTestTreeGlobNode.class.php');
- $node = new lmbTestTreeGlobNode($paths);
- $res = $runner->run($node);
- }
- //it's an exception which is used to pass user errors up to the interface,
- //we don't need to show backtrace in this case, only error message
- catch(lmbTestUserException $e)
- {
- $this->_error($e->getMessage());
- }
- catch(Exception $e)
- {
- $this->_error($e->__toString());
- }
-
- echo $runner->getRuntime() . " sec.\n";
-
- return $res;
- }
-}
-
-
+<?php
+/*
+ * Limb PHP Framework
+ *
+ * @link http://limb-project.com
+ * @copyright Copyright © 2004-2007 BIT(http://bit-creative.com)
+ * @license LGPL http://www.gnu.org/copyleft/lesser.html
+ */
+require_once(dirname(__FILE__) . '/lmbTestGetopt.class.php');
+
+/**
+ * class lmbTestShellUI.
+ *
+ * @package tests_runner
+ * @version $Id$
+ */
+class lmbTestShellUI
+{
+ protected $test_path;
+ protected $argv;
+ protected $posix_opts = true;
+ protected $call_exit = true;
+ protected $reporter;
+
+ function __construct($argv = null)
+ {
+ try
+ {
+ $this->argv = is_array($argv) ? $argv : lmbTestGetopt::readPHPArgv();
+ }
+ catch(Exception $e)
+ {
+ $this->_error($e->getMessage() . "\n");
+ }
+ }
+
+ function setReporter($reporter)
+ {
+ $this->reporter = $reporter;
+ }
+
+ function setPosixMode($flag = true)
+ {
+ $this->posix_opts = $flag;
+ }
+
+ function exitAfterRun($flag = true)
+ {
+ $this->call_exit = $flag;
+ }
+
+ function help($script = '')
+ {
+ $version = $this->_getVersion();
+
+ $usage = <<<EOD
+Usage:
+ limb_unit [OPTIONS] <file|dir> [<file1|dir1>, ... <fileN|dirN>]
+ Advanced SimpleTest unit tests runner. Finds and executes unit tests within filesystem.
+Arguments:
+ <file|dir> [<file1|dir1>, ... <fileN|dirN>] - a list of files/directories, globs are supported(e.g. '*')
+Options:
+ -h, --help Displays this help and exit
+ -c, --config=/file.php PHP configuration file path
+ -I, --include='filter1;filter2' Sets file filters used for including test files during
+ recursive traversal of directories.
+ '*Test.class.php;*test.php;*Test.php' by default.
+ -C, --cover=path1;path2 Sets paths delimitered with ';' which should be analyzed
+ for test coverage(requires XDebug extension!)
+ --cover-report=dir Sets coverage report directory
+ --cover-exclude=path1;path2 Sets paths delimitered with ';' which should be excluded
+ from coverage analysis
+
+$version
+
+EOD;
+ return $usage;
+ }
+
+ protected function _help($code = 0)
+ {
+ echo $this->help();
+ exit($code);
+ }
+
+ protected function _error($message, $code = 1)
+ {
+ echo "ERROR: $message\n\n";
+ echo $this->_getVersion();
+ echo "\n";
+ exit($code);
+ }
+
+ protected function _version()
+ {
+ echo $this->_getVersion() . "\n";
+ exit();
+ }
+
+ protected function _getVersion()
+ {
+ list(, $number, $status) = explode('-', trim(file_get_contents(dirname(__FILE__) . '/../VERSION')));
+ return "limb_unit-$number-$status";
+ }
+
+ static function getShortOpts()
+ {
+ return 'hvI:c:C:';
+ }
+
+ static function getLongOpts()
+ {
+ return array('help', 'version', 'include=', 'config=', 'cover=', 'cover-report=', 'cover-exclude=');
+ }
+
+ function run()
+ {
+ $res = $this->_doRun();
+
+ if($this->call_exit)
+ exit($res ? 0 : 1);
+ else
+ return $res;
+ }
+
+ function runEmbedded()
+ {
+ return $this->_doRun();
+ }
+
+ protected function _doRun()
+ {
+ $short_opts = self :: getShortOpts();
+ $long_opts = self :: getLongOpts();
+
+ try
+ {
+ if($this->posix_opts)
+ $options = lmbTestGetopt :: getopt($this->argv, $short_opts, $long_opts);
+ else
+ $options = lmbTestGetopt :: getopt2($this->argv, $short_opts, $long_opts);
+ }
+ catch(Exception $e)
+ {
+ $this->_help(1);
+ }
+
+ lmbTestGetopt :: defineConstants($this->argv);
+
+ $config_file = null;
+ $cover_include = '';
+ $cover_exclude = '';
+ $cover_report_dir = null;
+
+ foreach($options[0] as $option)
+ {
+ switch($option[0])
+ {
+ case 'h':
+ case '--help':
+ $this->_help(0);
+ break;
+ case 'v':
+ case '--version':
+ $this->_version();
+ break;
+ case 'c':
+ case '--config':
+ $config_file = $option[1];
+ break;
+ case 'I':
+ case '--include':
+ @define('LIMB_TESTS_RUNNER_FILE_FILTER', $option[1]);
+ break;
+ case 'C':
+ case '--cover':
+ $cover_include = $option[1];
+ break;
+ case '--cover-report':
+ $cover_report_dir = $option[1];
+ break;
+ case '--cover-exclude':
+ $cover_exclude = $option[1];
+ break;
+ }
+ }
+
+ if($config_file)
+ {
+ if(!@include_once(realpath($config_file)))
+ $this->_error("Could not include configuration file '$config_file'\n");
+ }
+ else if($config_file = getenv('LIMB_TESTS_RUNNER_CONFIG'))
+ {
+ if(!@include_once($config_file))
+ $this->_error("Could not include configuration file specified in LIMB_TESTS_RUNNER_CONFIG env. variable as '$config_file'\n");
+ }
+
+ if(!is_array($options[1]) || !count($options[1]))
+ $paths = array('.');
+ else
+ $paths = $options[1];
+
+ if(!$cover_report_dir && defined('LIMB_TESTS_RUNNER_COVERAGE_REPORT_DIR'))
+ $cover_report_dir = LIMB_TESTS_RUNNER_COVERAGE_REPORT_DIR;
+
+ require_once(dirname(__FILE__) . '/lmbTestRunner.class.php');
+ $runner = new lmbTestRunner();
+
+ if($this->reporter)
+ $runner->setReporter($this->reporter);
+
+ if($cover_include)
+ $runner->useCoverage($cover_include, $cover_exclude, $cover_report_dir);
+
+ try
+ {
+ require_once(dirname(__FILE__) . '/lmbTestTreeGlobNode.class.php');
+ $node = new lmbTestTreeGlobNode($paths);
+ $res = $runner->run($node);
+ }
+ //it's an exception which is used to pass user errors up to the interface,
+ //we don't need to show backtrace in this case, only error message
+ catch(lmbTestUserException $e)
+ {
+ $this->_error($e->getMessage());
+ }
+ catch(Exception $e)
+ {
+ $this->_error($e->__toString());
+ }
+
+ echo $runner->getRuntime() . " sec.\n";
+
+ return $res;
+ }
+}
+
+
Modified: 3.x/trunk/limb/tests_runner/src/lmbTestTreeDirNode.class.php
===================================================================
--- 3.x/trunk/limb/tests_runner/src/lmbTestTreeDirNode.class.php 2007-08-09 08:49:12 UTC (rev 6229)
+++ 3.x/trunk/limb/tests_runner/src/lmbTestTreeDirNode.class.php 2007-08-10 06:03:04 UTC (rev 6230)
@@ -1,107 +1,107 @@
-<?php
-/*
- * Limb PHP Framework
- *
- * @link http://limb-project.com
- * @copyright Copyright © 2004-2007 BIT(http://bit-creative.com)
- * @license LGPL http://www.gnu.org/copyleft/lesser.html
- */
-require_once(dirname(__FILE__) . '/lmbTestTreeShallowDirNode.class.php');
-require_once(dirname(__FILE__) . '/lmbTestTreeFileNode.class.php');
-require_once(dirname(__FILE__) . '/lmbDetachedFixture.class.php');
-require_once(dirname(__FILE__) . '/lmbTestFileFilter.class.php');
-
- at define('LIMB_TESTS_RUNNER_FILE_FILTER', '*Test.class.php;*test.php;*Test.php');
-
-/**
- * class lmbTestTreeDirNode.
- *
- * @package tests_runner
- * @version $Id$
- */
-class lmbTestTreeDirNode extends lmbTestTreeShallowDirNode
-{
- protected static $file_filter;
- protected $loaded;
-
- function createTestCase($is_first = true)
- {
- $this->_loadChildren();
- return parent :: createTestCase($is_first);
- }
-
- static function getFileFilter()
- {
- if(!is_object(self :: $file_filter))
- self :: setFileFilter(LIMB_TESTS_RUNNER_FILE_FILTER);
- return self :: $file_filter;
- }
-
- static function setFileFilter($filter)
- {
- $prev = self :: $file_filter;
-
- if(is_object($filter))
- $obj = $filter;
- elseif(is_array($filter))
- $obj = new lmbTestFileFilter($filter);
- else
- $obj = new lmbTestFileFilter(explode(';', $filter));
-
- self :: $file_filter = $obj;
- return $prev;
- }
-
- function _loadChildren()
- {
- if(!is_null($this->loaded) && $this->loaded)
- return;
-
- $dir_items = $this->getDirItems();
-
- foreach($dir_items as $item)
- {
- if(is_dir($item))
- $this->addChild(new lmbTestTreeDirNode($item));
- else
- $this->addChild(new lmbTestTreeFileNode($item));
- }
- $this->loaded = true;
- }
-
- function getDirItems()
- {
- $clean_and_sorted = array();
- $dir_items = scandir($this->dir);
-
- foreach($dir_items as $item)
- {
- if($item{0} == '.' || (!is_dir($this->dir . '/' . $item) && !$this->_isFileAllowed($item)))
- continue;
- $clean_and_sorted[$item] = $this->dir . '/' . $item;
- }
-
- uasort($clean_and_sorted, array($this, '_dirSorter'));
- return $clean_and_sorted;
- }
-
- protected function _isFileAllowed($file)
- {
- $filter = self :: getFileFilter();
-
- if($filter && !$filter->match($file))
- return false;
- return true;
- }
-
- protected function _dirSorter($a, $b)
- {
- if(is_dir($a) && !is_dir($b))
- return -1;
- elseif(!is_dir($a) && is_dir($b))
- return 1;
- return strcmp($a, $b);
- }
-}
-
-
+<?php
+/*
+ * Limb PHP Framework
+ *
+ * @link http://limb-project.com
+ * @copyright Copyright © 2004-2007 BIT(http://bit-creative.com)
+ * @license LGPL http://www.gnu.org/copyleft/lesser.html
+ */
+require_once(dirname(__FILE__) . '/lmbTestTreeShallowDirNode.class.php');
+require_once(dirname(__FILE__) . '/lmbTestTreeFileNode.class.php');
+require_once(dirname(__FILE__) . '/lmbDetachedFixture.class.php');
+require_once(dirname(__FILE__) . '/lmbTestFileFilter.class.php');
+
+ at define('LIMB_TESTS_RUNNER_FILE_FILTER', '*Test.class.php;*test.php;*Test.php');
+
+/**
+ * class lmbTestTreeDirNode.
+ *
+ * @package tests_runner
+ * @version $Id$
+ */
+class lmbTestTreeDirNode extends lmbTestTreeShallowDirNode
+{
+ protected static $file_filter;
+ protected $loaded;
+
+ function createTestCase($is_first = true)
+ {
+ $this->_loadChildren();
+ return parent :: createTestCase($is_first);
+ }
+
+ static function getFileFilter()
+ {
+ if(!is_object(self :: $file_filter))
+ self :: setFileFilter(LIMB_TESTS_RUNNER_FILE_FILTER);
+ return self :: $file_filter;
+ }
+
+ static function setFileFilter($filter)
+ {
+ $prev = self :: $file_filter;
+
+ if(is_object($filter))
+ $obj = $filter;
+ elseif(is_array($filter))
+ $obj = new lmbTestFileFilter($filter);
+ else
+ $obj = new lmbTestFileFilter(explode(';', $filter));
+
+ self :: $file_filter = $obj;
+ return $prev;
+ }
+
+ function _loadChildren()
+ {
+ if(!is_null($this->loaded) && $this->loaded)
+ return;
+
+ $dir_items = $this->getDirItems();
+
+ foreach($dir_items as $item)
+ {
+ if(is_dir($item))
+ $this->addChild(new lmbTestTreeDirNode($item));
+ else
+ $this->addChild(new lmbTestTreeFileNode($item));
+ }
+ $this->loaded = true;
+ }
+
+ function getDirItems()
+ {
+ $clean_and_sorted = array();
+ $dir_items = scandir($this->dir);
+
+ foreach($dir_items as $item)
+ {
+ if($item{0} == '.' || (!is_dir($this->dir . '/' . $item) && !$this->_isFileAllowed($item)))
+ continue;
+ $clean_and_sorted[$item] = $this->dir . '/' . $item;
+ }
+
+ uasort($clean_and_sorted, array($this, '_dirSorter'));
+ return $clean_and_sorted;
+ }
+
+ protected function _isFileAllowed($file)
+ {
+ $filter = self :: getFileFilter();
+
+ if($filter && !$filter->match($file))
+ return false;
+ return true;
+ }
+
+ protected function _dirSorter($a, $b)
+ {
+ if(is_dir($a) && !is_dir($b))
+ return -1;
+ elseif(!is_dir($a) && is_dir($b))
+ return 1;
+ return strcmp($a, $b);
+ }
+}
+
+
Modified: 3.x/trunk/limb/tests_runner/src/lmbTestTreeFileNode.class.php
===================================================================
--- 3.x/trunk/limb/tests_runner/src/lmbTestTreeFileNode.class.php 2007-08-09 08:49:12 UTC (rev 6229)
+++ 3.x/trunk/limb/tests_runner/src/lmbTestTreeFileNode.class.php 2007-08-10 06:03:04 UTC (rev 6230)
@@ -1,51 +1,53 @@
-<?php
-/*
- * Limb PHP Framework
- *
- * @link http://limb-project.com
- * @copyright Copyright © 2004-2007 BIT(http://bit-creative.com)
- * @license LGPL http://www.gnu.org/copyleft/lesser.html
- */
-require_once(dirname(__FILE__). '/lmbTestTreeTerminalNode.class.php');
-require_once(dirname(__FILE__). '/lmbTestUserException.class.php');
-
-/**
- * class lmbTestTreeFileNode.
- *
- * @package tests_runner
- * @version $Id$
- */
-class lmbTestTreeFileNode extends lmbTestTreeTerminalNode
-{
- protected $file;
-
- function __construct($file)
- {
- $this->file = $file;
- }
-
- function getFile()
- {
- return $this->file;
- }
-
- protected function _getClassesDefinedInFile()
- {
- if(!preg_match_all('~\Wclass\s+(\w+)~', file_get_contents($this->file), $matches))
- return array();
- return $matches[1];
- }
-
- protected function _doCreateTestCase()
- {
- require_once($this->file);
- $suite = new lmbTestGroup(basename($this->file));
- $candidates = $this->_getClassesDefinedInFile();
- $loader = new SimpleFileLoader();
- foreach($loader->selectRunnableTests($candidates) as $class)
- $suite->addTestCase(new $class());
-
- return $suite;
- }
-}
-
+<?php
+/*
+ * Limb PHP Framework
+ *
+ * @link http://limb-project.com
+ * @copyright Copyright © 2004-2007 BIT(http://bit-creative.com)
+ * @license LGPL http://www.gnu.org/copyleft/lesser.html
+ */
+require_once(dirname(__FILE__). '/lmbTestTreeTerminalNode.class.php');
+require_once(dirname(__FILE__). '/lmbTestUserException.class.php');
+
+/**
+ * class lmbTestTreeFileNode.
+ *
+ * @package tests_runner
+ * @version $Id$
+ */
+class lmbTestTreeFileNode extends lmbTestTreeTerminalNode
+{
+ protected $file;
+
+ function __construct($file)
+ {
+ $this->file = $file;
+ }
+
+ function getFile()
+ {
+ return $this->file;
+ }
+
+ function getTestLabel()
+ {
+ return basename($this->file);
+ }
+
+ protected function _getClassesDefinedInFile()
+ {
+ if(!preg_match_all('~\Wclass\s+(\w+)~', file_get_contents($this->file), $matches))
+ return array();
+ return $matches[1];
+ }
+
+ protected function _prepareTestCase($test)
+ {
+ require_once($this->file);
+ $candidates = $this->_getClassesDefinedInFile();
+ $loader = new SimpleFileLoader();
+ foreach($loader->selectRunnableTests($candidates) as $class)
+ $test->addTestCase(new $class());
+ }
+}
+
Modified: 3.x/trunk/limb/tests_runner/src/lmbTestTreeFilePathNode.class.php
===================================================================
--- 3.x/trunk/limb/tests_runner/src/lmbTestTreeFilePathNode.class.php 2007-08-09 08:49:12 UTC (rev 6229)
+++ 3.x/trunk/limb/tests_runner/src/lmbTestTreeFilePathNode.class.php 2007-08-10 06:03:04 UTC (rev 6230)
@@ -1,102 +1,102 @@
-<?php
-/*
- * Limb PHP Framework
- *
- * @link http://limb-project.com
- * @copyright Copyright © 2004-2007 BIT(http://bit-creative.com)
- * @license LGPL http://www.gnu.org/copyleft/lesser.html
- */
-require_once(dirname(__FILE__) . '/lmbTestTreeNode.class.php');
-require_once(dirname(__FILE__) . '/lmbTestTreeShallowDirNode.class.php');
-require_once(dirname(__FILE__) . '/lmbTestTreeDirNode.class.php');
-require_once(dirname(__FILE__) . '/lmbTestTreeFileNode.class.php');
-
-/**
- * class lmbTestTreeFilePathNode.
- *
- * @package tests_runner
- * @version $Id: lmbTestTreeFilePathNode.class.php 6020 2007-06-27 15:12:32Z pachanga $
- */
-class lmbTestTreeFilePathNode extends lmbTestTreeNode
-{
- protected $file_path;
- protected $offset;
-
- function __construct($file_path, $offset = null)
- {
- if(!is_file($file_path) && !is_dir($file_path))
- throw new Exception("'$file_path' is not a valid file path!");
-
- $this->file_path = realpath($file_path);
- $this->offset = $offset;
- }
-
- function getFilePath()
- {
- return $this->file_path;
- }
-
- protected function _loadChildren()
- {
- $path_items = $this->_getPathItems();
- $total = count($path_items);
- $current = $this;
-
- for($i=0;$i<$total;$i++)
- {
- $item = $path_items[$i];
- if(is_dir($item))
- {
- if($i+1 == $total)//is last?
- $current->addChild($new = new lmbTestTreeDirNode($item));
- else
- $current->addChild($new = new lmbTestTreeShallowDirNode($item));
- }
- else
- $current->addChild($new = new lmbTestTreeFileNode($item));
-
- $current = $new;
- }
- }
-
- protected function _getPathItems()
- {
- $items = array();
- $current = $this->file_path;
- while(($new = dirname($current)) != $current)
- {
- $items[] = $current;
- $current = $new;
- }
-
- return $this->_applyOffset(array_reverse($items));
- }
-
- protected function _applyOffset($items)
- {
- $offset = $this->offset;
- if(is_null($offset))
- $offset = $this->_determineOptimalOffset($items);
-
- return array_slice($items, $offset);
- }
-
- protected function _determineOptimalOffset($items)
- {
- $offset = 0;
- $total = count($items);
- for($i=0;$i<$total;$i++)
- {
- $item = $items[$i];
- if(is_file($item) || lmbTestTreeShallowDirNode :: hasArtifacts($item))
- break;
- elseif(is_dir($item) && $i+1 == $total)//last dir should be added anyway
- break;
-
- $offset++;
- }
- return $offset;
- }
-}
-
-
+<?php
+/*
+ * Limb PHP Framework
+ *
+ * @link http://limb-project.com
+ * @copyright Copyright © 2004-2007 BIT(http://bit-creative.com)
+ * @license LGPL http://www.gnu.org/copyleft/lesser.html
+ */
+require_once(dirname(__FILE__) . '/lmbTestTreeNode.class.php');
+require_once(dirname(__FILE__) . '/lmbTestTreeShallowDirNode.class.php');
+require_once(dirname(__FILE__) . '/lmbTestTreeDirNode.class.php');
+require_once(dirname(__FILE__) . '/lmbTestTreeFileNode.class.php');
+
+/**
+ * class lmbTestTreeFilePathNode.
+ *
+ * @package tests_runner
+ * @version $Id: lmbTestTreeFilePathNode.class.php 6020 2007-06-27 15:12:32Z pachanga $
+ */
+class lmbTestTreeFilePathNode extends lmbTestTreeNode
+{
+ protected $file_path;
+ protected $offset;
+
+ function __construct($file_path, $offset = null)
+ {
+ if(!is_file($file_path) && !is_dir($file_path))
+ throw new Exception("'$file_path' is not a valid file path!");
+
+ $this->file_path = realpath($file_path);
+ $this->offset = $offset;
+ }
+
+ function getFilePath()
+ {
+ return $this->file_path;
+ }
+
+ protected function _loadChildren()
+ {
+ $path_items = $this->_getPathItems();
+ $total = count($path_items);
+ $current = $this;
+
+ for($i=0;$i<$total;$i++)
+ {
+ $item = $path_items[$i];
+ if(is_dir($item))
+ {
+ if($i+1 == $total)//is last?
+ $current->addChild($new = new lmbTestTreeDirNode($item));
+ else
+ $current->addChild($new = new lmbTestTreeShallowDirNode($item));
+ }
+ else
+ $current->addChild($new = new lmbTestTreeFileNode($item));
+
+ $current = $new;
+ }
+ }
+
+ protected function _getPathItems()
+ {
+ $items = array();
+ $current = $this->file_path;
+ while(($new = dirname($current)) != $current)
+ {
+ $items[] = $current;
+ $current = $new;
+ }
+
+ return $this->_applyOffset(array_reverse($items));
+ }
+
+ protected function _applyOffset($items)
+ {
+ $offset = $this->offset;
+ if(is_null($offset))
+ $offset = $this->_determineOptimalOffset($items);
+
+ return array_slice($items, $offset);
+ }
+
+ protected function _determineOptimalOffset($items)
+ {
+ $offset = 0;
+ $total = count($items);
+ for($i=0;$i<$total;$i++)
+ {
+ $item = $items[$i];
+ if(is_file($item) || lmbTestTreeShallowDirNode :: hasArtifacts($item))
+ break;
+ elseif(is_dir($item) && $i+1 == $total)//last dir should be added anyway
+ break;
+
+ $offset++;
+ }
+ return $offset;
+ }
+}
+
+
Modified: 3.x/trunk/limb/tests_runner/src/lmbTestTreeGlobNode.class.php
===================================================================
--- 3.x/trunk/limb/tests_runner/src/lmbTestTreeGlobNode.class.php 2007-08-09 08:49:12 UTC (rev 6229)
+++ 3.x/trunk/limb/tests_runner/src/lmbTestTreeGlobNode.class.php 2007-08-10 06:03:04 UTC (rev 6230)
@@ -1,52 +1,52 @@
-<?php
-/*
- * Limb PHP Framework
- *
- * @link http://limb-project.com
- * @copyright Copyright © 2004-2007 BIT(http://bit-creative.com)
- * @license LGPL http://www.gnu.org/copyleft/lesser.html
- */
-require_once(dirname(__FILE__). '/lmbTestTreeNode.class.php');
-require_once(dirname(__FILE__). '/lmbTestTreeFilePathNode.class.php');
-require_once(dirname(__FILE__). '/lmbTestUserException.class.php');
-
-/**
- * class lmbTestTreeGlobNode.
- *
- * @package tests_runner
- * @version $Id$
- */
-class lmbTestTreeGlobNode extends lmbTestTreeNode
-{
- protected $paths;
-
- function __construct($paths)
- {
- if(!is_array($paths))
- $paths = array($paths);
- $this->paths = $paths;
- }
-
- protected function _loadChildren()
- {
- $found = false;
- foreach($this->paths as $path)
- {
- foreach(glob($path) as $item)
- {
- $found = true;
- $this->addChild(new lmbTestTreeFilePathNode($item));
- }
- }
-
- if(!$found)
- throw new lmbTestUserException("No test files were found for path '" . implode(';', $this->paths) . "'");
- }
-
- function getTestLabel()
- {
- return 'All ' . implode(';', $this->paths) . ' tests ';
- }
-}
-
-
+<?php
+/*
+ * Limb PHP Framework
+ *
+ * @link http://limb-project.com
+ * @copyright Copyright © 2004-2007 BIT(http://bit-creative.com)
+ * @license LGPL http://www.gnu.org/copyleft/lesser.html
+ */
+require_once(dirname(__FILE__). '/lmbTestTreeNode.class.php');
+require_once(dirname(__FILE__). '/lmbTestTreeFilePathNode.class.php');
+require_once(dirname(__FILE__). '/lmbTestUserException.class.php');
+
+/**
+ * class lmbTestTreeGlobNode.
+ *
+ * @package tests_runner
+ * @version $Id$
+ */
+class lmbTestTreeGlobNode extends lmbTestTreeNode
+{
+ protected $paths;
+
+ function __construct($paths)
+ {
+ if(!is_array($paths))
+ $paths = array($paths);
+ $this->paths = $paths;
+ }
+
+ protected function _loadChildren()
+ {
+ $found = false;
+ foreach($this->paths as $path)
+ {
+ foreach(glob($path) as $item)
+ {
+ $found = true;
+ $this->addChild(new lmbTestTreeFilePathNode($item));
+ }
+ }
+
+ if(!$found)
+ throw new lmbTestUserException("No test files were found for path '" . implode(';', $this->paths) . "'");
+ }
+
+ function getTestLabel()
+ {
+ return 'All test in "' . implode(';', $this->paths) . '"';
+ }
+}
+
+
Modified: 3.x/trunk/limb/tests_runner/src/lmbTestTreeNode.class.php
===================================================================
--- 3.x/trunk/limb/tests_runner/src/lmbTestTreeNode.class.php 2007-08-09 08:49:12 UTC (rev 6229)
+++ 3.x/trunk/limb/tests_runner/src/lmbTestTreeNode.class.php 2007-08-10 06:03:04 UTC (rev 6230)
@@ -1,165 +1,165 @@
-<?php
-/*
- * Limb PHP Framework
- *
- * @link http://limb-project.com
- * @copyright Copyright © 2004-2007 BIT(http://bit-creative.com)
- * @license LGPL http://www.gnu.org/copyleft/lesser.html
- */
-require_once(dirname(__FILE__) . '/lmbTestTreePath.class.php');
-
-/**
- * abstract class lmbTestTreeNode.
- *
- * @package tests_runner
- * @version $Id$
- */
-class lmbTestTreeNode
-{
- protected $parent;
- protected $children = array();
-
- function setParent($parent)
- {
- $this->parent = $parent;
- }
-
- function getParent()
- {
- return $this->parent;
- }
-
- function addChild($child)
- {
- $child->setParent($this);
- $this->children[] = $child;
- }
-
- function getChildren()
- {
- $this->_loadChildren();
- return $this->children;
- }
-
- function getParents()
- {
- $parents = array();
- $node = $this->parent;
- while($node)
- {
- array_unshift($parents, $node);
- $node = $node->getParent();
- }
- return $parents;
- }
-
- protected function _loadChildren(){}
-
- function findChildByPath($path)
- {
- return $this->_traverseArrayPath(lmbTestTreePath :: toArray($path));
- }
-
- protected function _traverseArrayPath($array_path, &$nodes = array())
- {
- $nodes[] = $this;
-
- // return itself in case of / path
- if(!$array_path)
- return $this;
-
- if(sizeof($array_path) == 1)
- {
- $child = $this->_getImmediateChildByIndex(array_shift($array_path));
- $nodes[] = $child;
- return $child;
- }
-
- $index = array_shift($array_path);
-
- if(!$child = $this->_getImmediateChildByIndex($index))
- return null;
-
- if($child->isTerminal())
- return null;
-
- return $child->_traverseArrayPath($array_path, $nodes);
- }
-
- protected function _getImmediateChildByIndex($index)
- {
- $children = $this->getChildren();
- if(isset($children[$index]))
- return $children[$index];
- }
-
- function isSkipped()
- {
- return false;
- }
-
- function isTerminal()
- {
- return false;
- }
-
- function init(){}
-
- function getTestLabel()
- {
- return $this->_doCreateTestCase()->getLabel();
- }
-
- function createTestCase($is_first = true)
- {
- if($is_first && $this->_hasSkippedParents())
- return null;
-
- $test = $this->_doCreateTestCase();
-
- //all parents are traversed in case some test customization is required
- if($is_first)
- {
- foreach($this->getParents() as $node)
- $node->_prepareTestCase($test);
- }
-
- $this->_prepareTestCase($test);
- //using getter instead of raw property, since child classes may need lazy loading
- $children = $this->getChildren();
- foreach($children as $child)
- {
- if($child->isSkipped())
- continue;
- $child->init();//obsolete stuff
- $test->addTestCase($child->createTestCase(false));
- }
- return $test;
- }
-
- protected function _hasSkippedParents()
- {
- if(!$this->parent)
- return false;
-
- $parent = $this->parent;
- while($parent)
- {
- if($parent->isSkipped())
- return true;
- $parent = $parent->getParent();
- }
- return false;
- }
-
- protected function _doCreateTestCase()
- {
- //we need to delay inclusion of SimpleTest as much as possible
- require_once(dirname(__FILE__) . '/lmbTestGroup.class.php');
- return new lmbTestGroup();
- }
-
- protected function _prepareTestCase($test){}
-}
-
-
+<?php
+/*
+ * Limb PHP Framework
+ *
+ * @link http://limb-project.com
+ * @copyright Copyright © 2004-2007 BIT(http://bit-creative.com)
+ * @license LGPL http://www.gnu.org/copyleft/lesser.html
+ */
+require_once(dirname(__FILE__) . '/lmbTestTreePath.class.php');
+
+/**
+ * abstract class lmbTestTreeNode.
+ *
+ * @package tests_runner
+ * @version $Id$
+ */
+class lmbTestTreeNode
+{
+ protected $parent;
+ protected $children = array();
+
+ function setParent($parent)
+ {
+ $this->parent = $parent;
+ }
+
+ function getParent()
+ {
+ return $this->parent;
+ }
+
+ function addChild($child)
+ {
+ $child->setParent($this);
+ $this->children[] = $child;
+ }
+
+ function getChildren()
+ {
+ $this->_loadChildren();
+ return $this->children;
+ }
+
+ function getParents()
+ {
+ $parents = array();
+ $node = $this->parent;
+ while($node)
+ {
+ array_unshift($parents, $node);
+ $node = $node->getParent();
+ }
+ return $parents;
+ }
+
+ protected function _loadChildren(){}
+
+ function findChildByPath($path)
+ {
+ return $this->_traverseArrayPath(lmbTestTreePath :: toArray($path));
+ }
+
+ protected function _traverseArrayPath($array_path, &$nodes = array())
+ {
+ $nodes[] = $this;
+
+ // return itself in case of / path
+ if(!$array_path)
+ return $this;
+
+ if(sizeof($array_path) == 1)
+ {
+ $child = $this->_getImmediateChildByIndex(array_shift($array_path));
+ $nodes[] = $child;
+ return $child;
+ }
+
+ $index = array_shift($array_path);
+
+ if(!$child = $this->_getImmediateChildByIndex($index))
+ return null;
+
+ if($child->isTerminal())
+ return null;
+
+ return $child->_traverseArrayPath($array_path, $nodes);
+ }
+
+ protected function _getImmediateChildByIndex($index)
+ {
+ $children = $this->getChildren();
+ if(isset($children[$index]))
+ return $children[$index];
+ }
+
+ function isSkipped()
+ {
+ return false;
+ }
+
+ function isTerminal()
+ {
+ return false;
+ }
+
+ function init(){}
+
+ function getTestLabel()
+ {
+ return 'Test Group';
+ }
+
+ function createTestCase($is_first = true)
+ {
+ if($is_first && $this->_hasSkippedParents())
+ return null;
+
+ $test = $this->_doCreateTestCase();
+
+ //all parents are traversed in case some test customization is required
+ if($is_first)
+ {
+ foreach($this->getParents() as $node)
+ $node->_prepareTestCase($test);
+ }
+
+ $this->_prepareTestCase($test);
+ //using getter instead of raw property, since child classes may need lazy loading
+ $children = $this->getChildren();
+ foreach($children as $child)
+ {
+ if($child->isSkipped())
+ continue;
+ $child->init();//obsolete stuff
+ $test->addTestCase($child->createTestCase(false));
+ }
+ return $test;
+ }
+
+ protected function _hasSkippedParents()
+ {
+ if(!$this->parent)
+ return false;
+
+ $parent = $this->parent;
+ while($parent)
+ {
+ if($parent->isSkipped())
+ return true;
+ $parent = $parent->getParent();
+ }
+ return false;
+ }
+
+ protected function _doCreateTestCase()
+ {
+ //we need to delay inclusion of SimpleTest as much as possible
+ require_once(dirname(__FILE__) . '/lmbTestGroup.class.php');
+ return new lmbTestGroup($this->getTestLabel());
+ }
+
+ protected function _prepareTestCase($test){}
+}
+
+
Modified: 3.x/trunk/limb/tests_runner/src/lmbTestTreePath.class.php
===================================================================
--- 3.x/trunk/limb/tests_runner/src/lmbTestTreePath.class.php 2007-08-09 08:49:12 UTC (rev 6229)
+++ 3.x/trunk/limb/tests_runner/src/lmbTestTreePath.class.php 2007-08-10 06:03:04 UTC (rev 6230)
@@ -1,44 +1,44 @@
-<?php
-/*
- * Limb PHP Framework
- *
- * @link http://limb-project.com
- * @copyright Copyright © 2004-2007 BIT(http://bit-creative.com)
- * @license LGPL http://www.gnu.org/copyleft/lesser.html
- */
-
-/**
- * class lmbTestTreePath.
- *
- * @package tests_runner
- * @version $Id$
- */
-class lmbTestTreePath
-{
- static function normalize($tests_path)
- {
- return '/' . implode('/', self :: toArray($tests_path));
- }
-
- static function toArray($tests_path)
- {
- $tests_path = preg_replace('~\/\/+~', '/', $tests_path);
- $tests_path = rtrim($tests_path, '/');
- $path_array = explode('/', $tests_path);
-
- if(isset($path_array[0]) && $path_array[0] == '')
- array_shift($path_array);
-
- $new_array = array();
- foreach($path_array as $item)
- {
- if($item == '..')
- array_pop($new_array);
- else
- $new_array[] = $item;
- }
- return $new_array;
- }
-}
-
-
+<?php
+/*
+ * Limb PHP Framework
+ *
+ * @link http://limb-project.com
+ * @copyright Copyright © 2004-2007 BIT(http://bit-creative.com)
+ * @license LGPL http://www.gnu.org/copyleft/lesser.html
+ */
+
+/**
+ * class lmbTestTreePath.
+ *
+ * @package tests_runner
+ * @version $Id$
+ */
+class lmbTestTreePath
+{
+ static function normalize($tests_path)
+ {
+ return '/' . implode('/', self :: toArray($tests_path));
+ }
+
+ static function toArray($tests_path)
+ {
+ $tests_path = preg_replace('~\/\/+~', '/', $tests_path);
+ $tests_path = rtrim($tests_path, '/');
+ $path_array = explode('/', $tests_path);
+
+ if(isset($path_array[0]) && $path_array[0] == '')
+ array_shift($path_array);
+
+ $new_array = array();
+ foreach($path_array as $item)
+ {
+ if($item == '..')
+ array_pop($new_array);
+ else
+ $new_array[] = $item;
+ }
+ return $new_array;
+ }
+}
+
+
Modified: 3.x/trunk/limb/tests_runner/src/lmbTestTreeShallowDirNode.class.php
===================================================================
--- 3.x/trunk/limb/tests_runner/src/lmbTestTreeShallowDirNode.class.php 2007-08-09 08:49:12 UTC (rev 6229)
+++ 3.x/trunk/limb/tests_runner/src/lmbTestTreeShallowDirNode.class.php 2007-08-10 06:03:04 UTC (rev 6230)
@@ -1,99 +1,91 @@
-<?php
-/*
- * Limb PHP Framework
- *
- * @link http://limb-project.com
- * @copyright Copyright © 2004-2007 BIT(http://bit-creative.com)
- * @license LGPL http://www.gnu.org/copyleft/lesser.html
- */
-require_once(dirname(__FILE__) . '/lmbTestTreeNode.class.php');
-require_once(dirname(__FILE__) . '/lmbDetachedFixture.class.php');
-
-/**
- * class lmbTestTreeShallowDirNode.
- *
- * @package tests_runner
- * @version $Id: lmbTestTreeShallowDirNode.class.php 6020 2007-06-27 15:12:32Z pachanga $
- */
-class lmbTestTreeShallowDirNode extends lmbTestTreeNode
-{
- protected $dir;
- protected $skipped;
-
- function __construct($dir)
- {
- if(!is_dir($dir))
- throw new Exception("'$dir' is not a directory!");
-
- $this->dir = $dir;
- }
-
- static function hasArtifacts($dir)
- {
- $artifacts = array('.init.php',
- '.setup.php',
- '.teardown.php',
- '.ignore.php',
- '.skipif.php');
- foreach($artifacts as $artifact)
- {
- if(file_exists($dir . '/' . $artifact))
- return true;
- }
- return false;
- }
-
- function getDir()
- {
- return $this->dir;
- }
-
- function init()
- {
- //deprecated
- if(file_exists($this->dir . '/.init.php'))
- include_once($this->dir . '/.init.php');
- }
-
- protected function _doCreateTestCase()
- {
- require_once(dirname(__FILE__) . '/lmbTestGroup.class.php');
-
- $label = $this->_getDirectoryLabel();
- $test = new lmbTestGroup($label);
- return $test;
- }
-
- protected function _prepareTestCase($test)
- {
- $fixture = new lmbDetachedFixture($this->dir . '/.setup.php',
- $this->dir . '/.teardown.php');
- //set this fixture to be the first one
- $test->addFixture($fixture);
- }
-
- protected function _getDirectoryLabel()
- {
- if(file_exists($this->dir . '/.description'))
- return file_get_contents($this->dir . '/.description');
- else
- return 'Group test in "' . $this->dir . '"';
- }
-
- function isSkipped()
- {
- if(!is_null($this->skipped))
- return $this->skipped;
-
- if(file_exists($this->dir . '/.skipif.php'))
- $this->skipped = (bool)include($this->dir . '/.skipif.php');
- elseif(file_exists($this->dir . '/.ignore.php'))//deprecated
- $this->skipped = (bool)include($this->dir . '/.ignore.php');
- else
- $this->skipped = false;
-
- return $this->skipped;
- }
-}
-
-
+<?php
+/*
+ * Limb PHP Framework
+ *
+ * @link http://limb-project.com
+ * @copyright Copyright © 2004-2007 BIT(http://bit-creative.com)
+ * @license LGPL http://www.gnu.org/copyleft/lesser.html
+ */
+require_once(dirname(__FILE__) . '/lmbTestTreeNode.class.php');
+require_once(dirname(__FILE__) . '/lmbDetachedFixture.class.php');
+
+/**
+ * class lmbTestTreeShallowDirNode.
+ *
+ * @package tests_runner
+ * @version $Id: lmbTestTreeShallowDirNode.class.php 6020 2007-06-27 15:12:32Z pachanga $
+ */
+class lmbTestTreeShallowDirNode extends lmbTestTreeNode
+{
+ protected $dir;
+ protected $skipped;
+
+ function __construct($dir)
+ {
+ if(!is_dir($dir))
+ throw new Exception("'$dir' is not a directory!");
+
+ $this->dir = $dir;
+ }
+
+ //move this one to a better place, lmbTestDirArtifacts?
+ static function hasArtifacts($dir)
+ {
+ $artifacts = array('.init.php',
+ '.setup.php',
+ '.teardown.php',
+ '.ignore.php',
+ '.skipif.php');
+ foreach($artifacts as $artifact)
+ {
+ if(file_exists($dir . '/' . $artifact))
+ return true;
+ }
+ return false;
+ }
+
+ function getDir()
+ {
+ return $this->dir;
+ }
+
+ function init()
+ {
+ //deprecated
+ if(file_exists($this->dir . '/.init.php'))
+ include_once($this->dir . '/.init.php');
+ }
+
+ function getTestLabel()
+ {
+ if(file_exists($this->dir . '/.description'))
+ return file_get_contents($this->dir . '/.description');
+ else
+ return 'Group test in "' . $this->dir . '"';
+ }
+
+ protected function _prepareTestCase($test)
+ {
+ $fixture = new lmbDetachedFixture($this->dir . '/.setup.php',
+ $this->dir . '/.teardown.php');
+ //set this fixture to be the first one
+ $test->addFixture($fixture);
+ }
+
+ function isSkipped()
+ {
+ if(!is_null($this->skipped))
+ return $this->skipped;
+
+ if(file_exists($this->dir . '/.skipif.php'))
+ $this->skipped = (bool)include($this->dir . '/.skipif.php');
+ elseif(file_exists($this->dir . '/.ignore.php'))//deprecated
+ $this->skipped = (bool)include($this->dir . '/.ignore.php');
+ else
+ $this->skipped = false;
+
+ return $this->skipped;
+ }
+}
+
+
Modified: 3.x/trunk/limb/tests_runner/src/lmbTestTreeTerminalNode.class.php
===================================================================
--- 3.x/trunk/limb/tests_runner/src/lmbTestTreeTerminalNode.class.php 2007-08-09 08:49:12 UTC (rev 6229)
+++ 3.x/trunk/limb/tests_runner/src/lmbTestTreeTerminalNode.class.php 2007-08-10 06:03:04 UTC (rev 6230)
@@ -1,28 +1,28 @@
-<?php
-/*
- * Limb PHP Framework
- *
- * @link http://limb-project.com
- * @copyright Copyright © 2004-2007 BIT(http://bit-creative.com)
- * @license LGPL http://www.gnu.org/copyleft/lesser.html
- */
-
-/**
- * abstract class lmbTestTreeTerminalNode.
- *
- * @package tests_runner
- * @version $Id$
- */
-class lmbTestTreeTerminalNode extends lmbTestTreeNode
-{
- function addChild($node){}
-
- function findChildByPath($path){}
-
- function isTerminal()
- {
- return true;
- }
-}
-
-
+<?php
+/*
+ * Limb PHP Framework
+ *
+ * @link http://limb-project.com
+ * @copyright Copyright © 2004-2007 BIT(http://bit-creative.com)
+ * @license LGPL http://www.gnu.org/copyleft/lesser.html
+ */
+
+/**
+ * abstract class lmbTestTreeTerminalNode.
+ *
+ * @package tests_runner
+ * @version $Id$
+ */
+class lmbTestTreeTerminalNode extends lmbTestTreeNode
+{
+ function addChild($node){}
+
+ function findChildByPath($path){}
+
+ function isTerminal()
+ {
+ return true;
+ }
+}
+
+
Modified: 3.x/trunk/limb/tests_runner/src/lmbTestUserException.class.php
===================================================================
--- 3.x/trunk/limb/tests_runner/src/lmbTestUserException.class.php 2007-08-09 08:49:12 UTC (rev 6229)
+++ 3.x/trunk/limb/tests_runner/src/lmbTestUserException.class.php 2007-08-10 06:03:04 UTC (rev 6230)
@@ -1,18 +1,18 @@
-<?php
-/*
- * Limb PHP Framework
- *
- * @link http://limb-project.com
- * @copyright Copyright © 2004-2007 BIT(http://bit-creative.com)
- * @license LGPL http://www.gnu.org/copyleft/lesser.html
- */
-
-/**
- * class lmbTestUserException.
- *
- * @package tests_runner
- * @version $Id$
- */
-class lmbTestUserException extends Exception{}
-
-
+<?php
+/*
+ * Limb PHP Framework
+ *
+ * @link http://limb-project.com
+ * @copyright Copyright © 2004-2007 BIT(http://bit-creative.com)
+ * @license LGPL http://www.gnu.org/copyleft/lesser.html
+ */
+
+/**
+ * class lmbTestUserException.
+ *
+ * @package tests_runner
+ * @version $Id$
+ */
+class lmbTestUserException extends Exception{}
+
+
Modified: 3.x/trunk/limb/tests_runner/src/lmbTestWebUI.class.php
===================================================================
--- 3.x/trunk/limb/tests_runner/src/lmbTestWebUI.class.php 2007-08-09 08:49:12 UTC (rev 6229)
+++ 3.x/trunk/limb/tests_runner/src/lmbTestWebUI.class.php 2007-08-10 06:03:04 UTC (rev 6230)
@@ -1,192 +1,192 @@
-<?php
-/*
- * Limb PHP Framework
- *
- * @link http://limb-project.com
- * @copyright Copyright © 2004-2007 BIT(http://bit-creative.com)
- * @license LGPL http://www.gnu.org/copyleft/lesser.html
- */
-require_once(dirname(__FILE__) . '/lmbTestTreePath.class.php');
-require_once(dirname(__FILE__) . '/lmbTestRunner.class.php');
-require_once(dirname(__FILE__) . '/lmbTestHTMLReporter.class.php');
-
-/**
- * class lmbTestWebUI.
- *
- * @package tests_runner
- * @version $Id$
- */
-class lmbTestWebUI
-{
- protected $tree;
- protected $encoding = 'UTF-8';
-
- function __construct($root_node)
- {
- $this->root_node = $root_node;
- }
-
- function setEncoding($encoding)
- {
- $this->encoding = $encoding;
- }
-
- protected function _getReporter()
- {
- return new lmbTestHTMLReporter($this->encoding);
- }
-
- protected function _getBaseUrl()
- {
- return $_SERVER['PHP_SELF'];
- }
-
- function run()
- {
- if(isset($_GET['perform']))
- {
- if(is_array($_GET['perform']))
- {
- foreach(array_keys($_GET['perform']) as $path)
- $this->perform(lmbTestTreePath :: normalize($path));
- }
- else
- $this->perform(lmbTestTreePath :: normalize($_GET['perform']));
- }
- elseif(isset($_GET['browse']))
- $this->browse(lmbTestTreePath :: normalize($_GET['browse']));
- else
- $this->browse();
- }
-
- function perform($path)
- {
- $runner = new lmbTestRunner();
- $runner->setReporter($this->_getReporter());
- $runner->run($this->root_node, $path);
-
- if(isset($_GET['back']))
- $postfix = '';
- else
- $postfix = '/..';
-
- echo '<small>' . $runner->getRunTime() . '</small>';
- echo '<p>' . $this->_createBrowseLink($path . $postfix, 'Back') . '</p>';
- }
-
- function browse($path='/')
- {
- $node = $this->root_node->findChildByPath($path);
-
- echo '<html><body><style>@import url("style.css");</style>';
-
- if($this->root_node !== $node)
- echo '<p>' . $this->_createBrowseLink($path . '/..', 'Back');
-
- $sub_nodes = $node->getChildren();
-
- $buffer = '';
-
- $buffer .= "<p>Available test groups in '" . $node->getTestLabel() . "':\n";
- $buffer .= '<p>' . $this->_createPerformLink($path, 'Run all tests from this group', true);
-
- if(sizeof($sub_nodes))
- {
- $buffer .= "<p><form action='" . $this->_getBaseURL(). "' name='tests' method='GET'>\n";
- $buffer .= $this->_createAntiEmptySelectionHiddenInput();
- $buffer .= $this->_getToggleJS();
- $buffer .= $this->_createRunSelectedButton();
- $buffer .= "<p><a href='#' onclick='toggle_checkbox()'>toggle all</a></p>";
- $buffer .= "<table>";
-
- foreach($sub_nodes as $index => $sub_node)
- {
- if($index % 2)
- $class_name = 'odd';
- else
- $class_name = 'even';
- $buffer .= "<tr class='{$class_name}'>";
- $buffer .= "<td>" . $this->_createPerformCheckBox("{$path}/{$index}") . "</td>";
-
- if($sub_node->isTerminal())
- {
- $buffer .= "<td>" . $this->_createPerformLink("{$path}/{$index}", 'P') . "</td>";
- }
- else
- {
- $buffer .= "<td>" . $this->_createPerformLink("{$path}/{$index}", 'P') .
- $this->_createBrowseLink("{$path}/{$index}", 'B') ."</td>";
- }
-
- $buffer .= "<td>" . $sub_node->getTestLabel() . "</td></tr>\n";
- }
- $buffer .= "</table>\n";
- $buffer .= $this->_createRunSelectedButton();
- $buffer .= "</form>\n";
- }
- else
- $buffer .= "<p>No groups available.</p> \n";
-
- echo $buffer;
-
- echo '</body></html>';
- }
-
- protected function _createPerformHref($path)
- {
- return $this->_getBaseURL() . "?perform=$path";
- }
-
- protected function _createPerformLink($path, $title, $need_back = false)
- {
- $back = $need_back ? '&back=1' : '';
- return "<a href='" . $this->_createPerformHref($path) . "$back'>$title</a> ";
- }
-
- protected function _createBrowseHref($path)
- {
- return $this->_getBaseURL() . "?browse=$path";
- }
-
- protected function _createBrowseLink($path, $title)
- {
- return "<a href='" . $this->_createBrowseHref($path) . "'>$title</a> ";
- }
-
- protected function _createPerformCheckBox($path)
- {
- return "<input type='checkbox' name='perform[$path]'>";
- }
-
- protected function _createRunSelectedButton()
- {
- return "<input type='submit' value='Run selected tests'>\n";
- }
-
- protected function _createAntiEmptySelectionHiddenInput()
- {
- if(isset($_GET['perform']))
- return '';
- return "<input type='hidden' name='browse' value='" .
- (isset($_GET['browse']) ? $_GET['browse'] : '/') . "'>";
- }
-
- protected function _getToggleJS()
- {
- return <<<EOD
-<script>
- var toggle_mark = 0;
- function toggle_checkbox() {
- toggle_mark = toggle_mark ? 0 : 1;
- inputs = document.getElementsByTagName('input');
- for(i=0;i<inputs.length;i++) {
- var item = inputs[i];
- item.checked = toggle_mark;
- }
- }
-</script>
-EOD;
- }
-}
-
-
+<?php
+/*
+ * Limb PHP Framework
+ *
+ * @link http://limb-project.com
+ * @copyright Copyright © 2004-2007 BIT(http://bit-creative.com)
+ * @license LGPL http://www.gnu.org/copyleft/lesser.html
+ */
+require_once(dirname(__FILE__) . '/lmbTestTreePath.class.php');
+require_once(dirname(__FILE__) . '/lmbTestRunner.class.php');
+require_once(dirname(__FILE__) . '/lmbTestHTMLReporter.class.php');
+
+/**
+ * class lmbTestWebUI.
+ *
+ * @package tests_runner
+ * @version $Id$
+ */
+class lmbTestWebUI
+{
+ protected $tree;
+ protected $encoding = 'UTF-8';
+
+ function __construct($root_node)
+ {
+ $this->root_node = $root_node;
+ }
+
+ function setEncoding($encoding)
+ {
+ $this->encoding = $encoding;
+ }
+
+ protected function _getReporter()
+ {
+ return new lmbTestHTMLReporter($this->encoding);
+ }
+
+ protected function _getBaseUrl()
+ {
+ return $_SERVER['PHP_SELF'];
+ }
+
+ function run()
+ {
+ if(isset($_GET['perform']))
+ {
+ if(is_array($_GET['perform']))
+ {
+ foreach(array_keys($_GET['perform']) as $path)
+ $this->perform(lmbTestTreePath :: normalize($path));
+ }
+ else
+ $this->perform(lmbTestTreePath :: normalize($_GET['perform']));
+ }
+ elseif(isset($_GET['browse']))
+ $this->browse(lmbTestTreePath :: normalize($_GET['browse']));
+ else
+ $this->browse();
+ }
+
+ function perform($path)
+ {
+ $runner = new lmbTestRunner();
+ $runner->setReporter($this->_getReporter());
+ $runner->run($this->root_node, $path);
+
+ if(isset($_GET['back']))
+ $postfix = '';
+ else
+ $postfix = '/..';
+
+ echo '<small>' . $runner->getRunTime() . '</small>';
+ echo '<p>' . $this->_createBrowseLink($path . $postfix, 'Back') . '</p>';
+ }
+
+ function browse($path='/')
+ {
+ $node = $this->root_node->findChildByPath($path);
+
+ echo '<html><body><style>@import url("style.css");</style>';
+
+ if($this->root_node !== $node)
+ echo '<p>' . $this->_createBrowseLink($path . '/..', 'Back');
+
+ $sub_nodes = $node->getChildren();
+
+ $buffer = '';
+
+ $buffer .= "<p>Available test groups in '" . $node->getTestLabel() . "':\n";
+ $buffer .= '<p>' . $this->_createPerformLink($path, 'Run all tests from this group', true);
+
+ if(sizeof($sub_nodes))
+ {
+ $buffer .= "<p><form action='" . $this->_getBaseURL(). "' name='tests' method='GET'>\n";
+ $buffer .= $this->_createAntiEmptySelectionHiddenInput();
+ $buffer .= $this->_getToggleJS();
+ $buffer .= $this->_createRunSelectedButton();
+ $buffer .= "<p><a href='#' onclick='toggle_checkbox()'>toggle all</a></p>";
+ $buffer .= "<table>";
+
+ foreach($sub_nodes as $index => $sub_node)
+ {
+ if($index % 2)
+ $class_name = 'odd';
+ else
+ $class_name = 'even';
+ $buffer .= "<tr class='{$class_name}'>";
+ $buffer .= "<td>" . $this->_createPerformCheckBox("{$path}/{$index}") . "</td>";
+
+ if($sub_node->isTerminal())
+ {
+ $buffer .= "<td>" . $this->_createPerformLink("{$path}/{$index}", 'P') . "</td>";
+ }
+ else
+ {
+ $buffer .= "<td>" . $this->_createPerformLink("{$path}/{$index}", 'P') .
+ $this->_createBrowseLink("{$path}/{$index}", 'B') ."</td>";
+ }
+
+ $buffer .= "<td>" . $sub_node->getTestLabel() . "</td></tr>\n";
+ }
+ $buffer .= "</table>\n";
+ $buffer .= $this->_createRunSelectedButton();
+ $buffer .= "</form>\n";
+ }
+ else
+ $buffer .= "<p>No groups available.</p> \n";
+
+ echo $buffer;
+
+ echo '</body></html>';
+ }
+
+ protected function _createPerformHref($path)
+ {
+ return $this->_getBaseURL() . "?perform=$path";
+ }
+
+ protected function _createPerformLink($path, $title, $need_back = false)
+ {
+ $back = $need_back ? '&back=1' : '';
+ return "<a href='" . $this->_createPerformHref($path) . "$back'>$title</a> ";
+ }
+
+ protected function _createBrowseHref($path)
+ {
+ return $this->_getBaseURL() . "?browse=$path";
+ }
+
+ protected function _createBrowseLink($path, $title)
+ {
+ return "<a href='" . $this->_createBrowseHref($path) . "'>$title</a> ";
+ }
+
+ protected function _createPerformCheckBox($path)
+ {
+ return "<input type='checkbox' name='perform[$path]'>";
+ }
+
+ protected function _createRunSelectedButton()
+ {
+ return "<input type='submit' value='Run selected tests'>\n";
+ }
+
+ protected function _createAntiEmptySelectionHiddenInput()
+ {
+ if(isset($_GET['perform']))
+ return '';
+ return "<input type='hidden' name='browse' value='" .
+ (isset($_GET['browse']) ? $_GET['browse'] : '/') . "'>";
+ }
+
+ protected function _getToggleJS()
+ {
+ return <<<EOD
+<script>
+ var toggle_mark = 0;
+ function toggle_checkbox() {
+ toggle_mark = toggle_mark ? 0 : 1;
+ inputs = document.getElementsByTagName('input');
+ for(i=0;i<inputs.length;i++) {
+ var item = inputs[i];
+ item.checked = toggle_mark;
+ }
+ }
+</script>
+EOD;
+ }
+}
+
+
Modified: 3.x/trunk/limb/tests_runner/tests/common.inc.php
===================================================================
--- 3.x/trunk/limb/tests_runner/tests/common.inc.php 2007-08-09 08:49:12 UTC (rev 6229)
+++ 3.x/trunk/limb/tests_runner/tests/common.inc.php 2007-08-10 06:03:04 UTC (rev 6230)
@@ -1,122 +1,122 @@
-<?php
-/*
- * Limb PHP Framework
- *
- * @link http://limb-project.com
- * @copyright Copyright © 2004-2007 BIT(http://bit-creative.com)
- * @license LGPL http://www.gnu.org/copyleft/lesser.html
- */
-
-class GeneratedTestClass
-{
- protected $class_name;
-
- function __construct()
- {
- $this->class_name = 'GenClass_' . mt_rand(1, 10000);
- }
-
- function getClass()
- {
- return $this->class_name;
- }
-
- function getFileName()
- {
- return $this->class_name . ".class.php";
- }
-
- function getOutput()
- {
- return $this->class_name . "\n";
- }
-
- function generate()
- {
- $code = '';
- $code .= "<?php\n";
- $code .= $this->generateClass();
- $code .= "\n?>";
- return $code;
- }
-
- function generateFailing()
- {
- $code = '';
- $code .= "<?php\n";
- $code .= $this->generateClassFailing();
- $code .= "\n?>";
- return $code;
- }
-
- function generateClass()
- {
- $code = "class {$this->class_name} extends UnitTestCase {
- function testSay() {echo \"" . $this->getOutput() . "\";}
- }";
- return $code;
- }
-
- function generateClassFailing()
- {
- $code = "class {$this->class_name} extends UnitTestCase {
- function testSay() {\$this->assertTrue(false);echo \"" . $this->getOutput() . "\";}
- }";
- return $code;
- }
-}
-
-abstract class lmbTestRunnerBase extends UnitTestCase
-{
- function _rmdir($path)
- {
- if(!is_dir($path))
- return;
-
- $dir = opendir($path);
- while($entry = readdir($dir))
- {
- if(is_file("$path/$entry"))
- unlink("$path/$entry");
- elseif(is_dir("$path/$entry") && $entry != '.' && $entry != '..')
- $this->_rmdir("$path/$entry");
- }
- closedir($dir);
- $res = rmdir($path);
- clearstatcache();
- return $res;
- }
-
- function _createTestCase($file, $extra = '')
- {
- $dir = dirname($file);
- if(!is_dir($dir))
- mkdir($dir, 0777, true);
-
- $generated = new GeneratedTestClass();
- file_put_contents($file, "<?php\n" . $generated->generateClass() . $extra . "\n?>");
- return $generated;
- }
-
- function _createTestCaseFailing($file, $extra = '')
- {
- $dir = dirname($file);
- if(!is_dir($dir))
- mkdir($dir, 0777, true);
-
- $generated = new GeneratedTestClass();
- file_put_contents($file, "<?php\n" . $generated->generateClassFailing() . $extra . "\n?>");
- return $generated;
- }
-
- function _runNodeAndAssertOutput($node, $expected)
- {
- ob_start();
- $group = $node->createTestCase();
- $group->run(new SimpleReporter());
- $str = ob_get_contents();
- ob_end_clean();
- $this->assertEqual($str, $expected);
- }
-}
-
+<?php
+/*
+ * Limb PHP Framework
+ *
+ * @link http://limb-project.com
+ * @copyright Copyright © 2004-2007 BIT(http://bit-creative.com)
+ * @license LGPL http://www.gnu.org/copyleft/lesser.html
+ */
+
+class GeneratedTestClass
+{
+ protected $class_name;
+
+ function __construct()
+ {
+ $this->class_name = 'GenClass_' . mt_rand(1, 10000);
+ }
+
+ function getClass()
+ {
+ return $this->class_name;
+ }
+
+ function getFileName()
+ {
+ return $this->class_name . ".class.php";
+ }
+
+ function getOutput()
+ {
+ return $this->class_name . "\n";
+ }
+
+ function generate()
+ {
+ $code = '';
+ $code .= "<?php\n";
+ $code .= $this->generateClass();
+ $code .= "\n?>";
+ return $code;
+ }
+
+ function generateFailing()
+ {
+ $code = '';
+ $code .= "<?php\n";
+ $code .= $this->generateClassFailing();
+ $code .= "\n?>";
+ return $code;
+ }
+
+ function generateClass()
+ {
+ $code = "class {$this->class_name} extends UnitTestCase {
+ function testSay() {echo \"" . $this->getOutput() . "\";}
+ }";
+ return $code;
+ }
+
+ function generateClassFailing()
+ {
+ $code = "class {$this->class_name} extends UnitTestCase {
+ function testSay() {\$this->assertTrue(false);echo \"" . $this->getOutput() . "\";}
+ }";
+ return $code;
+ }
+}
+
+abstract class lmbTestRunnerBase extends UnitTestCase
+{
+ function _rmdir($path)
+ {
+ if(!is_dir($path))
+ return;
+
+ $dir = opendir($path);
+ while($entry = readdir($dir))
+ {
+ if(is_file("$path/$entry"))
+ unlink("$path/$entry");
+ elseif(is_dir("$path/$entry") && $entry != '.' && $entry != '..')
+ $this->_rmdir("$path/$entry");
+ }
+ closedir($dir);
+ $res = rmdir($path);
+ clearstatcache();
+ return $res;
+ }
+
+ function _createTestCase($file, $extra = '')
+ {
+ $dir = dirname($file);
+ if(!is_dir($dir))
+ mkdir($dir, 0777, true);
+
+ $generated = new GeneratedTestClass();
+ file_put_contents($file, "<?php\n" . $generated->generateClass() . $extra . "\n?>");
+ return $generated;
+ }
+
+ function _createTestCaseFailing($file, $extra = '')
+ {
+ $dir = dirname($file);
+ if(!is_dir($dir))
+ mkdir($dir, 0777, true);
+
+ $generated = new GeneratedTestClass();
+ file_put_contents($file, "<?php\n" . $generated->generateClassFailing() . $extra . "\n?>");
+ return $generated;
+ }
+
+ function _runNodeAndAssertOutput($node, $expected)
+ {
+ ob_start();
+ $group = $node->createTestCase();
+ $group->run(new SimpleReporter());
+ $str = ob_get_contents();
+ ob_end_clean();
+ $this->assertEqual($str, $expected);
+ }
+}
+
Modified: 3.x/trunk/limb/tests_runner/tests/test_self.php
===================================================================
--- 3.x/trunk/limb/tests_runner/tests/test_self.php 2007-08-09 08:49:12 UTC (rev 6229)
+++ 3.x/trunk/limb/tests_runner/tests/test_self.php 2007-08-10 06:03:04 UTC (rev 6230)
@@ -1,21 +1,21 @@
-<?php
-/*
- * Limb PHP Framework
- *
- * @link http://limb-project.com
- * @copyright Copyright © 2004-2007 BIT(http://bit-creative.com)
- * @license LGPL http://www.gnu.org/copyleft/lesser.html
- */
-
-if(isset($argv[1]))
- define('SIMPLE_TEST', $argv[1]);
-require_once(dirname(__FILE__) . '/cases/.setup.php');
-
-$group = new TestSuite();
-foreach(glob(dirname(__FILE__) . '/cases/*Test.class.php') as $file)
- $group->addTestFile($file);
-
-if(!$res = $group->run(new TextReporter()))
- exit(1);
-
-
+<?php
+/*
+ * Limb PHP Framework
+ *
+ * @link http://limb-project.com
+ * @copyright Copyright © 2004-2007 BIT(http://bit-creative.com)
+ * @license LGPL http://www.gnu.org/copyleft/lesser.html
+ */
+
+if(isset($argv[1]))
+ define('SIMPLE_TEST', $argv[1]);
+require_once(dirname(__FILE__) . '/cases/.setup.php');
+
+$group = new TestSuite();
+foreach(glob(dirname(__FILE__) . '/cases/*Test.class.php') as $file)
+ $group->addTestFile($file);
+
+if(!$res = $group->run(new TextReporter()))
+ exit(1);
+
+
More information about the limb-svn
mailing list