[limb-svn] r6021 - in 3.x/trunk/limb/tests_runner: src tests/cases
svn at limb-project.com
svn at limb-project.com
Thu Jun 28 17:18:44 MSD 2007
Author: pachanga
Date: 2007-06-28 17:18:44 +0400 (Thu, 28 Jun 2007)
New Revision: 6021
URL: http://fisheye.limb-project.com/changelog/limb/?cs=6021
Added:
3.x/trunk/limb/tests_runner/src/lmbTestTreeFilePathNode.class.php
3.x/trunk/limb/tests_runner/src/lmbTestTreeShallowDirNode.class.php
3.x/trunk/limb/tests_runner/tests/cases/lmbTestTreeFilePathNodeTest.class.php
Removed:
3.x/trunk/limb/tests_runner/src/lmbFile2TestNodeMapper.class.php
3.x/trunk/limb/tests_runner/src/lmbTestFileRunner.class.php
3.x/trunk/limb/tests_runner/tests/cases/lmbFile2TestNodeMapperTest.class.php
3.x/trunk/limb/tests_runner/tests/cases/lmbTestFileRunnerTest.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/lmbTestTreeDirNode.class.php
3.x/trunk/limb/tests_runner/src/lmbTestTreeFileNode.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/tests/cases/lmbTestShellUITest.class.php
3.x/trunk/limb/tests_runner/tests/cases/lmbTestTreeDirNodeTest.class.php
3.x/trunk/limb/tests_runner/tests/cases/lmbTestTreeFileNodeTest.class.php
3.x/trunk/limb/tests_runner/tests/cases/lmbTestTreeGlobNodeTest.class.php
3.x/trunk/limb/tests_runner/tests/cases/lmbTestTreeNodeTest.class.php
Log:
-- continuing major cleanup and refactoring:
* lmbFile2TestNodeMapper removed as not necessary anymore
* lmbTestFileRunner removed as well
* lmbTestTreeFilePathNode added, it encapsulates all functionality related to proper filling of test nodes. It builds tree nodes using its file path.
* lmbTestTreeNode is more generic now
* lmbTestTreeNode :: createTestGroup() => createTestCase()
* lmbTestTreeNode :: objectifyPath() removed as no longer needed
* lmbTestTreeGlobNode can accept multiple paths as an array
* lmbTestShellUI uses lmbTestTreeGlobNode and lmbTestRunner
* lmbTestTreeShallowDirNode added, it doesn't load file items recursively
* lmbTestTreeDirNode extends lmbTestTreeShallowDirNode
* lmbTestTreeDirNode's $file_filter and $class_format are now static properties which can be set/get
Deleted: 3.x/trunk/limb/tests_runner/src/lmbFile2TestNodeMapper.class.php
===================================================================
--- 3.x/trunk/limb/tests_runner/src/lmbFile2TestNodeMapper.class.php 2007-06-27 15:12:32 UTC (rev 6020)
+++ 3.x/trunk/limb/tests_runner/src/lmbFile2TestNodeMapper.class.php 2007-06-28 13:18:44 UTC (rev 6021)
@@ -1,64 +0,0 @@
-<?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__) . '/lmbTestTreeDirNode.class.php');
-
-/**
- * class lmbFile2TestNodeMapper.
- *
- * @package tests_runner
- * @version $Id$
- */
-class lmbFile2TestNodeMapper
-{
- function map($start_dir, $file)
- {
- $start_dir = realpath($start_dir);
- $file = realpath($file);
- $file = preg_replace('~^' . preg_quote($start_dir) . '~', '', $file);
-
- $path_items = explode(DIRECTORY_SEPARATOR, $file);
-
- if(empty($path_items[0]))
- array_shift($path_items);
-
- $path = '/' . $this->_doMap($start_dir, $path_items, $found);
- if(!$found)
- return false;
-
- return $path;
- }
-
- function _doMap($dir, $path_items, &$mapped = false)
- {
- $counter = 0;
- $current_item = reset($path_items);
-
- $node = new lmbTestTreeDirNode($dir);
-
- foreach($node->getDirItems() as $item => $full_path)
- {
- if($item == $current_item)
- {
- if(sizeof($path_items) > 1 && is_dir($full_path))
- {
- array_shift($path_items);
- return $counter . '/' . $this->_doMap($full_path, $path_items, $mapped);
- }
- elseif(sizeof($path_items) == 1)
- {
- $mapped = true;
- return $counter;
- }
- }
- $counter++;
- }
- }
-}
-
-?>
Deleted: 3.x/trunk/limb/tests_runner/src/lmbTestFileRunner.class.php
===================================================================
--- 3.x/trunk/limb/tests_runner/src/lmbTestFileRunner.class.php 2007-06-27 15:12:32 UTC (rev 6020)
+++ 3.x/trunk/limb/tests_runner/src/lmbTestFileRunner.class.php 2007-06-28 13:18:44 UTC (rev 6021)
@@ -1,119 +0,0 @@
-<?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__) . '/lmbTestRunner.class.php');
-
-/**
- * class lmbTestFileRunner.
- *
- * @package tests_runner
- * @version $Id$
- */
-class lmbTestFileRunner extends lmbTestRunner
-{
- protected $tests_found = false;
-
- function runForFiles($file_path)
- {
- if(!is_array($file_path))
- $test_paths[] = $file_path;
- else
- $test_paths = $file_path;
-
- require_once(dirname(__FILE__) . '/../simpletest.inc.php');
-
- $this->_startTimer();
- $this->_startCoverage();
-
- try
- {
- $res = $this->_doRunForFiles($test_paths);
- }
- catch(Exception $e)
- {
- $this->_showException($e);
- return false;
- }
-
- $this->_endCoverage();
- $this->_stopTimer();
- return $res;
- }
-
- protected function _doRunForFiles($test_paths)
- {
- $this->tests_found = false;
- $res = true;
- foreach($test_paths as $test_path)
- {
- foreach(glob($this->_normalizePath($test_path)) as $file)
- {
- $this->tests_found = true;
- $root_dir = $this->_getRootDir($file);
- $path = $this->_mapFileToNode($root_dir, $file);
- $node = $this->_initDirNode($root_dir);
- $res = $res & $this->_doRun($node, $path);
- }
- }
- return $res;
- }
-
- function testsFound()
- {
- return $this->tests_found;
- }
-
- protected function _normalizePath($path)
- {
- if($this->_isAbsolutePath($path))
- return rtrim($path, '\\/');
- else
- return rtrim($this->_getcwd() . DIRECTORY_SEPARATOR . $path, '\\/');
- }
-
- /**
- * Due to require_once error in PHP before 5.2 version this method 'strtolowers' paths under windows
- */
- protected function _getcwd()
- {
- $wd = getcwd();
- //win32 check
- if(DIRECTORY_SEPARATOR == '\\')
- $wd = strtolower($wd);
- return $wd;
- }
-
- protected function _isAbsolutePath($path)
- {
- return $path{0} == '/' || preg_match('~^[a-z]:~i', $path);
- }
-
- protected function _initDirNode($dir)
- {
- require_once(dirname(__FILE__) . '/lmbTestTreeDirNode.class.php');
- return new lmbTestTreeDirNode($dir);
- }
-
- protected function _mapFileToNode($root_dir, $file)
- {
- require_once(dirname(__FILE__) . '/lmbFile2TestNodeMapper.class.php');
- $mapper = new lmbFile2TestNodeMapper();
- return $mapper->map($root_dir, $file);
- }
-
- protected function _getRootDir($file)
- {
- $path_items = explode(DIRECTORY_SEPARATOR, $file);
- //windows/linux filesystem paths style check
- return empty($path_items[0]) ?
- DIRECTORY_SEPARATOR . $path_items[1] : //unix
- $path_items[0] . DIRECTORY_SEPARATOR; //windows
- }
-}
-
-?>
\ 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-27 15:12:32 UTC (rev 6020)
+++ 3.x/trunk/limb/tests_runner/src/lmbTestRunner.class.php 2007-06-28 13:18:44 UTC (rev 6021)
@@ -36,7 +36,7 @@
$this->coverage_report_dir = $coverage_report_dir;
}
- function run($root_node, $path)
+ function run($root_node, $path='/')
{
require_once(dirname(__FILE__) . '/../simpletest.inc.php');
@@ -60,18 +60,10 @@
protected function _doRun($node, $path)
{
- if(!$tree_path = $node->objectifyPath($path))
+ if(!$sub_node = $node->findChildByPath($path))
throw new Exception("Test node '$path' not found!");
- if($node = $tree_path->getSkippedNode())
- {
- echo "(There's a skipped test node in a path, skipping execution)\n";
- return true;
- }
-
- $tree_path->init();
-
- $test = $tree_path->createTestGroup();
+ $test = $sub_node->createTestCase();
return $test->run($this->_getReporter());
}
Modified: 3.x/trunk/limb/tests_runner/src/lmbTestShellUI.class.php
===================================================================
--- 3.x/trunk/limb/tests_runner/src/lmbTestShellUI.class.php 2007-06-27 15:12:32 UTC (rev 6020)
+++ 3.x/trunk/limb/tests_runner/src/lmbTestShellUI.class.php 2007-06-28 13:18:44 UTC (rev 6021)
@@ -7,7 +7,8 @@
* @license LGPL http://www.gnu.org/copyleft/lesser.html
*/
require_once(dirname(__FILE__) . '/lmbTestGetopt.class.php');
-require_once(dirname(__FILE__) . '/lmbTestFileRunner.class.php');
+require_once(dirname(__FILE__) . '/lmbTestRunner.class.php');
+require_once(dirname(__FILE__) . '/lmbTestTreeGlobNode.class.php');
/**
* class lmbTestShellUI.
@@ -185,7 +186,7 @@
if(!$cover_report_dir && defined('LIMB_TESTS_RUNNER_COVERAGE_REPORT_DIR'))
$cover_report_dir = LIMB_TESTS_RUNNER_COVERAGE_REPORT_DIR;
- $runner = new lmbTestFileRunner();
+ $runner = new lmbTestRunner();
if($this->reporter)
$runner->setReporter($this->reporter);
@@ -193,12 +194,16 @@
if($cover_include)
$runner->useCoverage($cover_include, $cover_exclude, $cover_report_dir);
- $found = false;
- $res = $runner->runForFiles($options[1]);
+ try
+ {
+ $node = new lmbTestTreeGlobNode($options[1]);
+ $res = $runner->run($node);
+ }
+ catch(Exception $e)
+ {
+ $this->_error($e->getMessage());
+ }
- if(!$runner->testsFound())
- $this->_error("No tests were found\n");
-
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-06-27 15:12:32 UTC (rev 6020)
+++ 3.x/trunk/limb/tests_runner/src/lmbTestTreeDirNode.class.php 2007-06-28 13:18:44 UTC (rev 6021)
@@ -6,118 +6,60 @@
* @copyright Copyright © 2004-2007 BIT(http://bit-creative.com)
* @license LGPL http://www.gnu.org/copyleft/lesser.html
*/
-require_once(dirname(__FILE__) . '/lmbTestGroup.class.php');
-require_once(dirname(__FILE__) . '/lmbTestTreeNode.class.php');
+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');
-require_once(dirname(__FILE__) . '/lmbTestTreePath.class.php');
- at define('LIMB_TESTS_RUNNER_FILE_FILTER', '*Test.class.php;*.test.php;*_test.php');
- at define('LIMB_TESTS_RUNNER_CLASS_FORMAT', '%s.class.php');
-
/**
* class lmbTestTreeDirNode.
*
* @package tests_runner
* @version $Id$
*/
-class lmbTestTreeDirNode extends lmbTestTreeNode
+class lmbTestTreeDirNode extends lmbTestTreeShallowDirNode
{
- protected $dir;
- protected $file_filter;
- protected $class_format;
- protected $test_group;
+ protected static $file_filter = '*Test.class.php;*.test.php;*_test.php';
+ protected static $class_format = '%s.class.php';
protected $loaded;
- protected $skipped;
- function __construct($dir, $file_filter = LIMB_TESTS_RUNNER_FILE_FILTER, $class_format = LIMB_TESTS_RUNNER_CLASS_FORMAT)
+ function createTestCase()
{
- if(!is_dir($dir))
- throw new Exception("'$dir' is not a directory!");
-
- $this->dir = $dir;
- $this->file_filter = $this->_createFileFilter($file_filter);
- $this->class_format = $class_format;
+ $this->_loadChildren();
+ return parent :: createTestCase();
}
- function getDir()
+ static function getFileFilter()
{
- return $this->dir;
+ if(is_object(self :: $file_filter))
+ return self :: $file_filter;
+ elseif(is_array(self :: $file_filter))
+ return new lmbTestFileFilter(self :: $file_filter);
+ else
+ return new lmbTestFileFilter(explode(';', self :: $file_filter));
}
- function getChildren()
+ static function setFileFilter($filter)
{
- $this->_loadLazyChildren();
- return $this->children;
+ $prev = self :: getFileFilter();
+ self :: $file_filter = $filter;
+ return $prev;
}
- function getTestLabel()
+ static function getClassFormat()
{
- $group = $this->_createTestGroupWithoutChildren();
- return $group->getLabel();
+ return self :: $class_format;
}
- function init()
+ static function setClassFormat($format)
{
- if(file_exists($this->dir . '/.init.php'))
- include_once($this->dir . '/.init.php');
+ $prev = self :: $class_format;
+ self :: $class_format = $format;
+ return $prev;
}
- //TODO: why having $test_group as a property?
- function createTestGroup()
+ function _loadChildren()
{
- if(is_object($this->test_group))
- return $this->test_group;
-
- $this->test_group = $this->_createTestGroupWithoutChildren();
- $this->_addChildrenTestCases($this->test_group);
-
- return $this->test_group;
- }
-
- protected function _createTestGroupWithoutChildren()
- {
- $label = $this->_getDirectoryLabel();
- $group = new lmbTestGroup($label);
- $fixture = new lmbDetachedFixture($this->dir . '/.setup.php',
- $this->dir . '/.teardown.php');
- $group->useFixture($fixture);
- return $group;
- }
-
- protected function _addChildrenTestCases($group)
- {
- foreach($this->getChildren() as $child)
- {
- if(!$child->isSkipped())
- {
- $child->init();
- $group->addTestCase($child->createTestGroup());
- }
- }
- }
-
- protected function _getDirectoryLabel()
- {
- if(file_exists($this->dir . '/.description'))
- return file_get_contents($this->dir . '/.description');
- else
- return 'Group test in "' . $this->dir . '"';
- }
-
- protected function _createFileFilter($file_filter)
- {
- if(is_object($file_filter))
- return $file_filter;
- elseif(is_array($file_filter))
- return new lmbTestFileFilter($file_filter);
- else
- return new lmbTestFileFilter(explode(';', $file_filter));
- }
-
- function _loadLazyChildren()
- {
if(!is_null($this->loaded) && $this->loaded)
return;
@@ -126,7 +68,7 @@
foreach($dir_items as $item)
{
if(is_dir($item))
- $this->addChild(new lmbTestTreeDirNode($item, $this->file_filter, $this->class_format));
+ $this->addChild(new lmbTestTreeDirNode($item));
else
$this->addChild(new lmbTestTreeFileNode($item, $this->_extractClassName($item)));
}
@@ -149,31 +91,18 @@
return $clean_and_sorted;
}
- 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'))
- $this->skipped = (bool)include($this->dir . '/.ignore.php');
- else
- $this->skipped = false;
-
- return $this->skipped;
- }
-
protected function _isFileAllowed($file)
{
- if($this->file_filter && !$this->file_filter->match($file))
+ $filter = self :: getFileFilter();
+
+ if($filter && !$filter->match($file))
return false;
return true;
}
protected function _extractClassName($file)
{
- $regex = preg_quote($this->class_format);
+ $regex = preg_quote(self :: $class_format);
$regex = '~^' . str_replace('%s', '(.*)', $regex) . '$~';
if(preg_match($regex, basename($file), $m))
Modified: 3.x/trunk/limb/tests_runner/src/lmbTestTreeFileNode.class.php
===================================================================
--- 3.x/trunk/limb/tests_runner/src/lmbTestTreeFileNode.class.php 2007-06-27 15:12:32 UTC (rev 6020)
+++ 3.x/trunk/limb/tests_runner/src/lmbTestTreeFileNode.class.php 2007-06-28 13:18:44 UTC (rev 6021)
@@ -16,7 +16,6 @@
*/
class lmbTestTreeFileNode extends lmbTestTreeTerminalNode
{
- protected $test_group;
protected $file;
protected $class;
@@ -36,13 +35,10 @@
return $this->class;
}
- function createTestGroup()
+ protected function _doCreateTestCase()
{
- if($this->test_group)
- return $this->test_group;
+ $suite = new TestSuite(basename($this->file));
- $this->test_group = new TestSuite(basename($this->file));
-
if(!is_null($this->class))
{
require_once($this->file);
@@ -50,12 +46,12 @@
throw new Exception("Class '{$this->class}' not found in '{$this->file}' file!");
$test = new $this->class();
- $this->test_group->addTestCase($test);
+ $suite->addTestCase($test);
}
else
- $this->test_group->addFile($this->file);
+ $suite->addFile($this->file);
- return $this->test_group;
+ return $suite;
}
}
?>
Added: 3.x/trunk/limb/tests_runner/src/lmbTestTreeFilePathNode.class.php
===================================================================
--- 3.x/trunk/limb/tests_runner/src/lmbTestTreeFilePathNode.class.php (rev 0)
+++ 3.x/trunk/limb/tests_runner/src/lmbTestTreeFilePathNode.class.php 2007-06-28 13:18:44 UTC (rev 6021)
@@ -0,0 +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;
+ }
+}
+
+?>
Modified: 3.x/trunk/limb/tests_runner/src/lmbTestTreeGlobNode.class.php
===================================================================
--- 3.x/trunk/limb/tests_runner/src/lmbTestTreeGlobNode.class.php 2007-06-27 15:12:32 UTC (rev 6020)
+++ 3.x/trunk/limb/tests_runner/src/lmbTestTreeGlobNode.class.php 2007-06-28 13:18:44 UTC (rev 6021)
@@ -7,7 +7,7 @@
* @license LGPL http://www.gnu.org/copyleft/lesser.html
*/
require_once(dirname(__FILE__). '/lmbTestTreeNode.class.php');
-require_once(dirname(__FILE__). '/lmbTestTreeDirNode.class.php');
+require_once(dirname(__FILE__). '/lmbTestTreeFilePathNode.class.php');
/**
* class lmbTestTreeGlobNode.
@@ -17,19 +17,27 @@
*/
class lmbTestTreeGlobNode extends lmbTestTreeNode
{
- protected $glob;
+ protected $paths;
- function __construct($glob)
+ function __construct($paths)
{
- $this->glob = $glob;
+ if(!is_array($paths))
+ $paths = array($paths);
+ $this->paths = $paths;
+ }
- foreach(glob($glob) as $item)
- $this->addChild(new lmbTestTreeDirNode($item));
+ protected function _loadChildren()
+ {
+ foreach($this->paths as $path)
+ {
+ foreach(glob($path) as $item)
+ $this->addChild(new lmbTestTreeFilePathNode($item));
+ }
}
function getTestLabel()
{
- return 'All ' . $this->glob . ' tests ';
+ return 'All ' . implode(';', $this->paths) . ' tests ';
}
}
Modified: 3.x/trunk/limb/tests_runner/src/lmbTestTreeNode.class.php
===================================================================
--- 3.x/trunk/limb/tests_runner/src/lmbTestTreeNode.class.php 2007-06-27 15:12:32 UTC (rev 6020)
+++ 3.x/trunk/limb/tests_runner/src/lmbTestTreeNode.class.php 2007-06-28 13:18:44 UTC (rev 6021)
@@ -6,6 +6,7 @@
* @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.
@@ -36,19 +37,11 @@
function getChildren()
{
+ $this->_loadChildren();
return $this->children;
}
- function objectifyPath($path)
- {
- if($this->_traverseArrayPath(lmbTestTreePath :: toArray($path), $nodes))
- {
- $tree_path = new lmbTestTreePath();
- foreach($nodes as $node)
- $tree_path->addNode($node);
- return $tree_path;
- }
- }
+ protected function _loadChildren(){}
function findChildByPath($path)
{
@@ -98,22 +91,30 @@
return false;
}
- function createTestGroup()
+ function init(){}
+
+ function getTestLabel()
{
- $group = new TestSuite();
- foreach($this->children as $child)
- $group->addTestCase($child->createTestGroup());
- return $group;
+ return $this->_doCreateTestCase()->getLabel();
}
- function init()
+ function createTestCase()
{
- return true;
+ $test = $this->_doCreateTestCase();
+ $children = $this->getChildren();//getter instead of raw property, since child classes may need customization
+ foreach($children as $child)
+ {
+ if($child->isSkipped())
+ continue;
+ $child->init();
+ $test->addTestCase($child->createTestCase());
+ }
+ return $test;
}
- function getTestLabel()
+ protected function _doCreateTestCase()
{
- return $this->createTestGroup()->getLabel();
+ return new TestSuite();
}
}
Modified: 3.x/trunk/limb/tests_runner/src/lmbTestTreePath.class.php
===================================================================
--- 3.x/trunk/limb/tests_runner/src/lmbTestTreePath.class.php 2007-06-27 15:12:32 UTC (rev 6020)
+++ 3.x/trunk/limb/tests_runner/src/lmbTestTreePath.class.php 2007-06-28 13:18:44 UTC (rev 6021)
@@ -15,50 +15,6 @@
*/
class lmbTestTreePath
{
- protected $nodes = array();
-
- function addNode($node)
- {
- $this->nodes[] = $node;
- }
-
- function createTestGroup()
- {
- if($node = end($this->nodes))
- return $node->createTestGroup();
- }
-
- function init()
- {
- foreach($this->nodes as $node)
- $node->init();
- }
-
- function hasSkippedNodes()
- {
- return $this->getSkippedNode() !== null;
- }
-
- function getSkippedNode()
- {
- foreach($this->nodes as $node)
- {
- if($node->isSkipped())
- return $node;
- }
- }
-
- function size()
- {
- return count($this->nodes);
- }
-
- function at($index)
- {
- if(isset($this->nodes[$index]))
- return $this->nodes[$index];
- }
-
static function normalize($tests_path)
{
return '/' . implode('/', self :: toArray($tests_path));
Added: 3.x/trunk/limb/tests_runner/src/lmbTestTreeShallowDirNode.class.php
===================================================================
--- 3.x/trunk/limb/tests_runner/src/lmbTestTreeShallowDirNode.class.php (rev 0)
+++ 3.x/trunk/limb/tests_runner/src/lmbTestTreeShallowDirNode.class.php 2007-06-28 13:18:44 UTC (rev 6021)
@@ -0,0 +1,95 @@
+<?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()
+ {
+ 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);
+ $fixture = new lmbDetachedFixture($this->dir . '/.setup.php',
+ $this->dir . '/.teardown.php');
+ $test->useFixture($fixture);
+ return $test;
+ }
+
+ 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'))
+ $this->skipped = (bool)include($this->dir . '/.ignore.php');
+ else
+ $this->skipped = false;
+
+ return $this->skipped;
+ }
+}
+
+?>
Deleted: 3.x/trunk/limb/tests_runner/tests/cases/lmbFile2TestNodeMapperTest.class.php
===================================================================
--- 3.x/trunk/limb/tests_runner/tests/cases/lmbFile2TestNodeMapperTest.class.php 2007-06-27 15:12:32 UTC (rev 6020)
+++ 3.x/trunk/limb/tests_runner/tests/cases/lmbFile2TestNodeMapperTest.class.php 2007-06-28 13:18:44 UTC (rev 6021)
@@ -1,67 +0,0 @@
-<?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__) . '/../common.inc.php');
-require_once(dirname(__FILE__) . '/../../src/lmbFile2TestNodeMapper.class.php');
-
-class lmbFile2TestNodeMapperTest extends lmbTestRunnerBase
-{
- function setUp()
- {
- $this->_rmdir(LIMB_VAR_DIR);
- mkdir(LIMB_VAR_DIR);
- }
-
- function tearDown()
- {
- $this->_rmdir(LIMB_VAR_DIR);
- }
-
- function testSimpleMap()
- {
- mkdir(LIMB_VAR_DIR . '/a');
- touch(LIMB_VAR_DIR . '/a/foo_test.php');
-
- $mapper = new lmbFile2TestNodeMapper();
- $path = $mapper->map(LIMB_VAR_DIR, LIMB_VAR_DIR . '/a/foo_test.php');
-
- $this->assertEqual($path, '/0/0');
- }
-
- function testMoreComplexMap()
- {
- mkdir(LIMB_VAR_DIR . '/a');
- mkdir(LIMB_VAR_DIR . '/a/b');
-
- touch(LIMB_VAR_DIR . '/a/b/bar_test.php');
- touch(LIMB_VAR_DIR . '/a/b/foo_test.php');
-
- $mapper = new lmbFile2TestNodeMapper();
- $path = $mapper->map(LIMB_VAR_DIR, LIMB_VAR_DIR . '/a/b/foo_test.php');
-
- $this->assertEqual($path, '/0/0/1');
- }
-
- function testMapWithJunkFiles()
- {
- mkdir(LIMB_VAR_DIR . '/a');
- mkdir(LIMB_VAR_DIR . '/a/b');
-
- touch(LIMB_VAR_DIR . '/a/b/bar_test.php');
- touch(LIMB_VAR_DIR . '/a/b/foo_test.php');
- touch(LIMB_VAR_DIR . '/a/b/a.junk');
- touch(LIMB_VAR_DIR . '/a/b/b.junk');
-
- $mapper = new lmbFile2TestNodeMapper();
- $path = $mapper->map(LIMB_VAR_DIR, LIMB_VAR_DIR . '/a/b/foo_test.php');
-
- $this->assertEqual($path, '/0/0/1');
- }
-}
-
-?>
Deleted: 3.x/trunk/limb/tests_runner/tests/cases/lmbTestFileRunnerTest.class.php
===================================================================
--- 3.x/trunk/limb/tests_runner/tests/cases/lmbTestFileRunnerTest.class.php 2007-06-27 15:12:32 UTC (rev 6020)
+++ 3.x/trunk/limb/tests_runner/tests/cases/lmbTestFileRunnerTest.class.php 2007-06-28 13:18:44 UTC (rev 6021)
@@ -1,106 +0,0 @@
-<?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__) . '/../common.inc.php');
-require_once(dirname(__FILE__) . '/../../src/lmbTestFileRunner.class.php');
-
-class lmbTestFileRunnerTest extends lmbTestRunnerBase
-{
- protected $cases;
-
- function setUp()
- {
- $this->_rmdir(LIMB_VAR_DIR);
- mkdir(LIMB_VAR_DIR);
- //we need unique temporary dir since test modules are included once
- mkdir($this->cases = LIMB_VAR_DIR . '/' . mt_rand());
- }
-
- function tearDown()
- {
- $this->_rmdir(LIMB_VAR_DIR);
- }
-
- function testRunOkForFile()
- {
- $foo = $this->_createTestCase($this->cases . '/foo_test.php');
- $bar = $this->_createTestCase($this->cases . '/a/bar_test.php');
- $zoo = $this->_createTestCase($this->cases . '/a/z/zoo_test.php');
-
- $runner = new lmbTestFileRunner();
- ob_start();
- $this->assertTrue($runner->runForFiles($this->cases . '/a/z/zoo_test.php'));
- ob_end_clean();
- $this->assertTrue($runner->testsFound());
- }
-
- function testRunOkForDir()
- {
- $foo = $this->_createTestCase($this->cases . '/foo_test.php');
- $bar = $this->_createTestCase($this->cases . '/a/bar_test.php');
- $zoo = $this->_createTestCase($this->cases . '/a/z/zoo_test.php');
-
- $runner = new lmbTestFileRunner();
- ob_start();
- $this->assertTrue($runner->runForFiles($this->cases . '/a'));
- ob_end_clean();
- $this->assertTrue($runner->testsFound());
- }
-
- function testNoRunnableFilesFound()
- {
- $runner = new lmbTestFileRunner();
- $this->assertTrue($runner->runForFiles($this->cases . mt_rand()));
- $this->assertFalse($runner->testsFound());
- }
-
- function testRunFailedForFile()
- {
- $foo = $this->_createTestCase($this->cases . '/foo_test.php');
- $bar = $this->_createTestCase($this->cases . '/a/bar_test.php');
- $zoo = $this->_createTestCaseFailing($this->cases . '/a/z/zoo_test.php');
-
- $runner = new lmbTestFileRunner();
- ob_start();
- $this->assertFalse($runner->runForFiles($this->cases . '/a/z/zoo_test.php'));
- ob_end_clean();
- $this->assertTrue($runner->testsFound());
- }
-
- function testRunFailedForDir()
- {
- $foo = $this->_createTestCase($this->cases . '/foo_test.php');
- $bar = $this->_createTestCase($this->cases . '/a/bar_test.php');
- $zoo = $this->_createTestCaseFailing($this->cases . '/a/z/zoo_test.php');
-
- $runner = new lmbTestFileRunner();
- ob_start();
- $this->assertFalse($runner->runForFiles($this->cases . '/a'));
- ob_end_clean();
- $this->assertTrue($runner->testsFound());
- }
-
- function testTestsInSkippedDirAreNotExecuted()
- {
- $foo = $this->_createTestCase($this->cases . '/foo_test.php');
- $bar = $this->_createTestCase($this->cases . '/a/bar_test.php');
- $zoo = $this->_createTestCase($this->cases . '/a/z/zoo_test.php');
-
- file_put_contents($this->cases . '/a/.skipif.php', '<?php return true; ?>');
-
- $runner = new lmbTestFileRunner();
- ob_start();
- $this->assertTrue($runner->runForFiles($this->cases . '/a/z/zoo_test.php'));
- $str = ob_get_contents();
- ob_end_clean();
- $this->assertTrue($runner->testsFound());
- $this->assertNoPattern('~' . preg_quote($zoo->getOutput()) . '~', $str);
- }
-}
-
-?>
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-27 15:12:32 UTC (rev 6020)
+++ 3.x/trunk/limb/tests_runner/tests/cases/lmbTestShellUITest.class.php 2007-06-28 13:18:44 UTC (rev 6021)
@@ -82,18 +82,18 @@
function testPerformMultipleArgs()
{
- $foo = $this->_createTestCase($f1 = LIMB_VAR_DIR . '/cases/foo_test.php');
- $bar = $this->_createTestCase($f2 = LIMB_VAR_DIR . '/cases/a/bar_test.php');
- $zoo = $this->_createTestCase($f3 = LIMB_VAR_DIR . '/cases/a/z/zoo_test.php');
+ $foo = $this->_createTestCase($foo_file = LIMB_VAR_DIR . '/cases/foo_test.php');
+ $bar = $this->_createTestCase($bar_file = LIMB_VAR_DIR . '/cases/a/bar_test.php');
+ $zoo = $this->_createTestCase($zoo_file = LIMB_VAR_DIR . '/cases/a/z/zoo_test.php');
- $ret = $this->_execScript("$f2 $f1 $f3", $screen);
+ $ret = $this->_execScript("$bar_file $foo_file $zoo_file", $screen);
if(!$this->assertEqual($ret, 0))
echo $screen;
- $this->assertPattern('~1\s+of\s+1\s+done\(' . $foo->getClass() . '\)~', $screen);
- $this->assertPattern('~1\s+of\s+1\s+done\(' . $bar->getClass() . '\)~', $screen);
- $this->assertPattern('~1\s+of\s+1\s+done\(' . $zoo->getClass() . '\)~', $screen);
- $this->assertPattern('~(Test cases run:\s*1\/1.*){3}~si', $screen);
+ $this->assertPattern('~1\s+of\s+3\s+done\(' . $bar->getClass() . '\)~', $screen);
+ $this->assertPattern('~2\s+of\s+3\s+done\(' . $foo->getClass() . '\)~', $screen);
+ $this->assertPattern('~3\s+of\s+3\s+done\(' . $zoo->getClass() . '\)~', $screen);
+ $this->assertPattern('~Test cases run:\s*3\/3.*~si', $screen);
$this->assertNoPattern('~Error~i', $screen);
}
Modified: 3.x/trunk/limb/tests_runner/tests/cases/lmbTestTreeDirNodeTest.class.php
===================================================================
--- 3.x/trunk/limb/tests_runner/tests/cases/lmbTestTreeDirNodeTest.class.php 2007-06-27 15:12:32 UTC (rev 6020)
+++ 3.x/trunk/limb/tests_runner/tests/cases/lmbTestTreeDirNodeTest.class.php 2007-06-28 13:18:44 UTC (rev 6021)
@@ -32,7 +32,6 @@
{
mkdir($this->var_dir . '/a');
mkdir($this->var_dir . '/a/b');
-
touch($this->var_dir . '/a/b/bar_test.php');
touch($this->var_dir . '/a/b/foo_test.php');
@@ -62,11 +61,15 @@
touch($this->var_dir . '/junk.php');
touch($this->var_dir . '/FooYo.class.php');
- $node = new lmbTestTreeDirNode($this->var_dir, array('*test.php', '*Yo.class.php'));
+ $prev_filter = lmbTestTreeDirNode :: setFileFilter(array('*test.php', '*Yo.class.php'));
+
+ $node = new lmbTestTreeDirNode($this->var_dir);
$nodes = $node->getChildren();
$this->assertEqual(sizeof($nodes), 2);
$this->assertEqual($nodes[0]->getFile(), $this->var_dir . '/FooYo.class.php');
$this->assertEqual($nodes[1]->getFile(), $this->var_dir . '/bar_test.php');
+
+ lmbTestTreeDirNode :: setFileFilter($prev_filter);
}
function testUseFileFilterAndClassFormat()
@@ -75,63 +78,19 @@
touch($this->var_dir . '/junk.php');
touch($this->var_dir . '/' . $foo->getFileName());
+ $prev_filter = lmbTestTreeDirNode :: setFileFilter('*.class.php');
+ $prev_format = lmbTestTreeDirNode :: setClassFormat('%s.class.php');
+
$node = new lmbTestTreeDirNode($this->var_dir, array('*.class.php'), '%s.class.php');
$nodes = $node->getChildren();
$this->assertEqual(sizeof($nodes), 1);
$this->assertEqual($nodes[0]->getFile(), $this->var_dir . '/' . $foo->getFileName());
$this->assertEqual($nodes[0]->getClass(), $foo->getClass());
- }
- function testFileFilterIsInherited()
- {
- mkdir($this->var_dir . '/a');
- touch($this->var_dir . '/a/BarTest.class.php');
- touch($this->var_dir . '/a/garbage.php');
- touch($this->var_dir . '/bar_test.php');
- touch($this->var_dir . '/bah.php');
- touch($this->var_dir . '/junk.php');
- touch($this->var_dir . '/FooTest.class.php');
-
- $node = new lmbTestTreeDirNode($this->var_dir, array('*test.php', '*Test.class.php'));
- $nodes = $node->getChildren();
- $this->assertEqual(sizeof($nodes), 3);
-
- $this->assertEqual($nodes[0]->getDir(), $this->var_dir . '/a');
-
- $a_nodes = $nodes[0]->getChildren();
- $this->assertEqual(sizeof($a_nodes), 1);
- $this->assertEqual($a_nodes[0]->getFile(), $this->var_dir . '/a/BarTest.class.php');
-
- $this->assertEqual($nodes[1]->getFile(), $this->var_dir . '/FooTest.class.php');
- $this->assertEqual($nodes[2]->getFile(), $this->var_dir . '/bar_test.php');
+ lmbTestTreeDirNode :: setFileFilter($prev_filter);
+ lmbTestTreeDirNode :: setClassFormat($prev_format);
}
- function testFileFilterAndClassFormatAreInherited()
- {
- mkdir($this->var_dir . '/a');
- touch($this->var_dir . '/a/BarTest.klass.php');
- touch($this->var_dir . '/a/garbage.php');
- touch($this->var_dir . '/bar_test.php');
- touch($this->var_dir . '/bah.php');
- touch($this->var_dir . '/junk.php');
- touch($this->var_dir . '/FooTest.klass.php');
-
- $node = new lmbTestTreeDirNode($this->var_dir, array('*test.php', '*Test.klass.php'), '%s.klass.php');
- $nodes = $node->getChildren();
- $this->assertEqual(sizeof($nodes), 3);
-
- $this->assertEqual($nodes[0]->getDir(), $this->var_dir . '/a');
-
- $a_nodes = $nodes[0]->getChildren();
- $this->assertEqual(sizeof($a_nodes), 1);
- $this->assertEqual($a_nodes[0]->getFile(), $this->var_dir . '/a/BarTest.klass.php');
- $this->assertEqual($a_nodes[0]->getClass(), 'BarTest');
-
- $this->assertEqual($nodes[1]->getFile(), $this->var_dir . '/FooTest.klass.php');
- $this->assertEqual($nodes[1]->getClass(), 'FooTest');
- $this->assertEqual($nodes[2]->getFile(), $this->var_dir . '/bar_test.php');
- }
-
function testFindChildByPath()
{
mkdir($this->var_dir . '/a');
@@ -149,7 +108,6 @@
{
mkdir($this->var_dir . '/a');
mkdir($this->var_dir . '/a/b');
-
touch($this->var_dir . '/a/b/bar_test.php');
touch($this->var_dir . '/a/b/foo_test.php');
@@ -183,7 +141,7 @@
//we check for any possible garbage during php includes
ob_start();
- $group = $node->createTestGroup();
+ $group = $node->createTestCase();
$group->run(new SimpleReporter());
$str = ob_get_contents();
@@ -197,7 +155,7 @@
$node = new lmbTestTreeDirNode($this->var_dir);
$this->assertEqual($node->getTestLabel(), 'Foo');
- $group = $node->createTestGroup();
+ $group = $node->createTestCase();
$this->assertEqual($group->getLabel(), 'Foo');
}
@@ -205,7 +163,7 @@
{
$node = new lmbTestTreeDirNode($this->var_dir);
$this->assertEqual($node->getTestLabel(), 'Group test in "' . $this->var_dir . '"');
- $group = $node->createTestGroup();
+ $group = $node->createTestCase();
$this->assertEqual($group->getLabel(), 'Group test in "' . $this->var_dir . '"');
}
@@ -235,7 +193,7 @@
file_put_contents($this->var_dir . '/a/b/.skipif.php', '<?php return true; ?>');
$root_node = new lmbTestTreeDirNode($this->var_dir);
- $group = $root_node->createTestGroup();
+ $group = $root_node->createTestCase();
ob_start();
$group->run(new SimpleReporter());
@@ -258,7 +216,7 @@
file_put_contents($this->var_dir . '/a/b/.skipif.php', '<?php return false; ?>');
$root_node = new lmbTestTreeDirNode($this->var_dir);
- $group = $root_node->createTestGroup();
+ $group = $root_node->createTestCase();
ob_start();
$group->run(new SimpleReporter());
@@ -282,7 +240,7 @@
file_put_contents($this->var_dir . '/a/b/.skipif.php', '<?php return true; ?>');
$root_node = new lmbTestTreeDirNode($this->var_dir);
- $group = $root_node->createTestGroup();
+ $group = $root_node->createTestCase();
ob_start();
$group->run(new SimpleReporter());
@@ -302,7 +260,7 @@
file_put_contents($this->var_dir . '/a/.skipif.php', '<?php return true; ?>');
$root_node = new lmbTestTreeDirNode($this->var_dir);
- $group = $root_node->createTestGroup();
+ $group = $root_node->createTestCase();
ob_start();
$group->run(new SimpleReporter());
Modified: 3.x/trunk/limb/tests_runner/tests/cases/lmbTestTreeFileNodeTest.class.php
===================================================================
--- 3.x/trunk/limb/tests_runner/tests/cases/lmbTestTreeFileNodeTest.class.php 2007-06-27 15:12:32 UTC (rev 6020)
+++ 3.x/trunk/limb/tests_runner/tests/cases/lmbTestTreeFileNodeTest.class.php 2007-06-28 13:18:44 UTC (rev 6021)
@@ -32,7 +32,7 @@
$node = new lmbTestTreeFileNode(LIMB_VAR_DIR . '/module.php');
ob_start();
- $group = $node->createTestGroup();
+ $group = $node->createTestCase();
$group->run(new SimpleReporter());
$str = ob_get_contents();
@@ -51,7 +51,7 @@
$node = new lmbTestTreeFileNode(LIMB_VAR_DIR . '/unique_module_name.php', $foo->getClass());
ob_start();
- $group = $node->createTestGroup();
+ $group = $node->createTestCase();
$group->run(new SimpleReporter());
$str = ob_get_contents();
@@ -66,7 +66,7 @@
$node = new lmbTestTreeFileNode(LIMB_VAR_DIR . '/foo.php');
$this->assertEqual($node->getTestLabel(), 'foo.php');
- $group = $node->createTestGroup();
+ $group = $node->createTestCase();
$this->assertEqual($group->getLabel(), 'foo.php');
}
}
Added: 3.x/trunk/limb/tests_runner/tests/cases/lmbTestTreeFilePathNodeTest.class.php
===================================================================
--- 3.x/trunk/limb/tests_runner/tests/cases/lmbTestTreeFilePathNodeTest.class.php (rev 0)
+++ 3.x/trunk/limb/tests_runner/tests/cases/lmbTestTreeFilePathNodeTest.class.php 2007-06-28 13:18:44 UTC (rev 6021)
@@ -0,0 +1,147 @@
+<?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__) . '/../common.inc.php');
+require_once(dirname(__FILE__) . '/../../src/lmbTestTreeFilePathNode.class.php');
+
+class lmbTestTreeFilePathNodeTest extends lmbTestRunnerBase
+{
+ protected $var_dir;
+
+ function setUp()
+ {
+ $this->_rmdir(LIMB_VAR_DIR);
+ //we need unique temporary dir since test modules are included once
+ $this->var_dir = LIMB_VAR_DIR . '/' . mt_rand();
+ mkdir(LIMB_VAR_DIR);
+ mkdir($this->var_dir);
+ }
+
+ function tearDown()
+ {
+ $this->_rmdir(LIMB_VAR_DIR);
+ }
+
+ function testLoadChildrenForFilePathEndingWithFile()
+ {
+ mkdir($this->var_dir . '/a');
+ mkdir($this->var_dir . '/a/b');
+ touch($this->var_dir . '/a/b/bar_test.php');
+ touch($this->var_dir . '/a/b/foo_test.php');
+
+ $node = new lmbTestTreeFilePathNode($this->var_dir . '/a/b/foo_test.php', -3);
+ $kids = $node->getChildren();
+ $this->assertEqual(sizeof($kids), 1);
+ $this->assertIsA($kids[0], 'lmbTestTreeShallowDirNode');
+ $this->assertEqual($kids[0]->getDir(), realpath($this->var_dir . '/a'));
+
+ $kids = $kids[0]->getChildren();
+ $this->assertEqual(sizeof($kids), 1);
+ $this->assertIsA($kids[0], 'lmbTestTreeShallowDirNode');
+ $this->assertEqual($kids[0]->getDir(), realpath($this->var_dir . '/a/b'));
+
+ $kids = $kids[0]->getChildren();
+ $this->assertEqual(sizeof($kids), 1);
+ $this->assertIsA($kids[0], 'lmbTestTreeFileNode');
+ $this->assertEqual($kids[0]->getFile(), realpath($this->var_dir . '/a/b/foo_test.php'));
+ }
+
+ function testLoadChildrenForFilePathEndingWithDir()
+ {
+ mkdir($this->var_dir . '/a');
+ mkdir($this->var_dir . '/a/b');
+ touch($this->var_dir . '/a/b/bar_test.php');
+ touch($this->var_dir . '/a/b/foo_test.php');
+
+ $node = new lmbTestTreeFilePathNode($this->var_dir . '/a/b', -2);
+ $kids = $node->getChildren();
+ $this->assertEqual(sizeof($kids), 1);
+ $this->assertIsA($kids[0], 'lmbTestTreeShallowDirNode');
+ $this->assertEqual($kids[0]->getDir(), realpath($this->var_dir . '/a'));
+
+ $kids = $kids[0]->getChildren();
+ $this->assertEqual(sizeof($kids), 1);
+ $this->assertIsA($kids[0], 'lmbTestTreeDirNode');
+ $this->assertEqual($kids[0]->getDir(), realpath($this->var_dir . '/a/b'));
+ }
+
+ function testLoadChildrenUseAutoOffsetForFile()
+ {
+ mkdir($this->var_dir . '/a');
+ mkdir($this->var_dir . '/a/b');
+ touch($this->var_dir . '/a/b/bar_test.php');
+ touch($this->var_dir . '/a/b/foo_test.php');
+
+ $node = new lmbTestTreeFilePathNode($this->var_dir . '/a/b/bar_test.php');
+ $kids = $node->getChildren();
+ $this->assertEqual(sizeof($kids), 1);
+ $this->assertIsA($kids[0], 'lmbTestTreeFileNode');
+ $this->assertEqual($kids[0]->getFile(), realpath($this->var_dir . '/a/b/bar_test.php'));
+ }
+
+ function testLoadChildrenUseAutoOffsetForFileWithArtifacts()
+ {
+ mkdir($this->var_dir . '/a');
+ mkdir($this->var_dir . '/a/b');
+ file_put_contents($this->var_dir . '/a/.skipif.php', '<?php return false; ?>');
+ touch($this->var_dir . '/a/b/bar_test.php');
+ touch($this->var_dir . '/a/b/foo_test.php');
+
+ $node = new lmbTestTreeFilePathNode($this->var_dir . '/a/b/bar_test.php');
+ $kids = $node->getChildren();
+ $this->assertEqual(sizeof($kids), 1);
+ $this->assertIsA($kids[0], 'lmbTestTreeShallowDirNode');
+ $this->assertEqual($kids[0]->getDir(), realpath($this->var_dir . '/a'));
+
+ $kids = $kids[0]->getChildren();
+ $this->assertEqual(sizeof($kids), 1);
+ $this->assertIsA($kids[0], 'lmbTestTreeShallowDirNode');
+ $this->assertEqual($kids[0]->getDir(), realpath($this->var_dir . '/a/b'));
+
+ $kids = $kids[0]->getChildren();
+ $this->assertEqual(sizeof($kids), 1);
+ $this->assertIsA($kids[0], 'lmbTestTreeFileNode');
+ $this->assertEqual($kids[0]->getFile(), realpath($this->var_dir . '/a/b/bar_test.php'));
+ }
+
+ function testLoadChildrenUseAutoOffsetForDir()
+ {
+ mkdir($this->var_dir . '/a');
+ mkdir($this->var_dir . '/a/b');
+ touch($this->var_dir . '/a/b/bar_test.php');
+ touch($this->var_dir . '/a/b/foo_test.php');
+
+ $node = new lmbTestTreeFilePathNode($this->var_dir . '/a/b/');
+ $kids = $node->getChildren();
+ $this->assertEqual(sizeof($kids), 1);
+ $this->assertIsA($kids[0], 'lmbTestTreeDirNode');
+ $this->assertEqual($kids[0]->getDir(), realpath($this->var_dir . '/a/b'));
+ }
+
+ function testLoadChildrenUseAutoOffsetForDirWithArtifacts()
+ {
+ mkdir($this->var_dir . '/a');
+ mkdir($this->var_dir . '/a/b');
+ file_put_contents($this->var_dir . '/a/.skipif.php', '<?php return false; ?>');
+ touch($this->var_dir . '/a/b/bar_test.php');
+ touch($this->var_dir . '/a/b/foo_test.php');
+
+ $node = new lmbTestTreeFilePathNode($this->var_dir . '/a/b');
+ $kids = $node->getChildren();
+ $this->assertEqual(sizeof($kids), 1);
+ $this->assertIsA($kids[0], 'lmbTestTreeShallowDirNode');
+ $this->assertEqual($kids[0]->getDir(), realpath($this->var_dir . '/a'));
+
+ $kids = $kids[0]->getChildren();
+ $this->assertEqual(sizeof($kids), 1);
+ $this->assertIsA($kids[0], 'lmbTestTreeDirNode');
+ $this->assertEqual($kids[0]->getDir(), realpath($this->var_dir . '/a/b'));
+ }
+}
+
+?>
Modified: 3.x/trunk/limb/tests_runner/tests/cases/lmbTestTreeGlobNodeTest.class.php
===================================================================
--- 3.x/trunk/limb/tests_runner/tests/cases/lmbTestTreeGlobNodeTest.class.php 2007-06-27 15:12:32 UTC (rev 6020)
+++ 3.x/trunk/limb/tests_runner/tests/cases/lmbTestTreeGlobNodeTest.class.php 2007-06-28 13:18:44 UTC (rev 6021)
@@ -38,9 +38,8 @@
file_put_contents(LIMB_VAR_DIR . '/b/junk_test.php', $junk->generate()); //should be ignored
$root_node = new lmbTestTreeGlobNode(LIMB_VAR_DIR . '/*/tests');
+ $group = $root_node->createTestCase();
- $group = $root_node->createTestGroup();
-
ob_start();
$group->run(new SimpleReporter());
$str = ob_get_contents();
@@ -60,7 +59,7 @@
$root_node = new lmbTestTreeGlobNode(LIMB_VAR_DIR . '/a');
- $group = $root_node->createTestGroup();
+ $group = $root_node->createTestCase();
ob_start();
$group->run(new SimpleReporter());
Modified: 3.x/trunk/limb/tests_runner/tests/cases/lmbTestTreeNodeTest.class.php
===================================================================
--- 3.x/trunk/limb/tests_runner/tests/cases/lmbTestTreeNodeTest.class.php 2007-06-27 15:12:32 UTC (rev 6020)
+++ 3.x/trunk/limb/tests_runner/tests/cases/lmbTestTreeNodeTest.class.php 2007-06-28 13:18:44 UTC (rev 6021)
@@ -45,33 +45,6 @@
$this->assertTrue($a->findChildByPath('/0') === $a_b);
$this->assertNull($a->findChildByPath('/100'));
}
-
- function testObjectifyPath()
- {
- $a = new lmbTestTreeNode();
- $a_b = new lmbTestTreeNode();
- $c = new lmbTestTreeNode();
-
- $root = new lmbTestTreeNode();
- $root->addChild($a);
- $a->addChild($a_b);
- $root->addChild($c);
-
- $path = $root->objectifyPath('/0/0');
- $this->assertEqual($path->size(), 3);
- $this->assertTrue($path->at(0) === $root);
- $this->assertTrue($path->at(1) === $a);
- $this->assertTrue($path->at(2) === $a_b);
- $this->assertNull($path->at(3));
-
- $path = $root->objectifyPath('/1');
- $this->assertEqual($path->size(), 2);
- $this->assertTrue($path->at(0) === $root);
- $this->assertTrue($path->at(1) === $c);
- $this->assertNull($path->at(2));
-
- $this->assertNull($root->objectifyPath('/100'));
- }
}
?>
More information about the limb-svn
mailing list