summaryrefslogtreecommitdiff
path: root/modules
diff options
context:
space:
mode:
authorBharat Mediratta <bharat@menalto.com>2008-12-12 05:02:44 +0000
committerBharat Mediratta <bharat@menalto.com>2008-12-12 05:02:44 +0000
commit697c2503ae4582fefa572c6f72dfba0e4adae717 (patch)
treea6b184468de8cf91c843c5f30fef09f3781940e3 /modules
parentb202816324c3a6bf515a8d938c33e882106f26da (diff)
Add support for filtering tests down to the Class::method level.
Diffstat (limited to 'modules')
-rw-r--r--modules/unit_test/libraries/Unit_Test.php20
1 files changed, 13 insertions, 7 deletions
diff --git a/modules/unit_test/libraries/Unit_Test.php b/modules/unit_test/libraries/Unit_Test.php
index a03d725f..018ce8e1 100644
--- a/modules/unit_test/libraries/Unit_Test.php
+++ b/modules/unit_test/libraries/Unit_Test.php
@@ -23,13 +23,14 @@ class Unit_Test_Core {
/**
* Sets the test path(s), runs the tests inside and stores the results.
*
- * @param string(s) test path(s)
+ * @param array test path(s)
+ * @param string filter (regular expression)
* @return void
*/
- public function __construct()
+ public function __construct($extra_paths=array(), $filter=null)
{
// Merge possible default test path(s) from config with the rest
- $paths = array_merge(func_get_args(), Kohana::config('unit_test.paths', FALSE, FALSE));
+ $paths = array_merge($extra_paths, Kohana::config('unit_test.paths', FALSE, FALSE));
// Normalize all test paths
foreach ($paths as $path)
@@ -64,10 +65,6 @@ class Unit_Test_Core {
// The class name should be the same as the file name
$class = substr($path, strrpos($path, '/') + 1, -(strlen(EXT)));
- if (count($_SERVER['argv']) > 2 && !in_array($class, $_SERVER['argv'])) {
- continue;
- }
-
// Skip hidden files
if (substr($class, 0, 1) === '.')
continue;
@@ -125,6 +122,10 @@ class Unit_Test_Core {
if ( ! $method->isPublic() OR $method->isStatic() OR $method->getNumberOfRequiredParameters() !== 0)
continue;
+ if ($filter && !preg_match("/$filter/i", "$class::{$method->getName()}")) {
+ continue;
+ }
+
// Test methods should be suffixed with "_test"
if (substr($method_name = $method->getName(), -5) !== '_test')
continue;
@@ -187,6 +188,11 @@ class Unit_Test_Core {
// Cleanup
unset($object);
}
+
+ if ($filter && $this->stats[$class]['total'] == 0) {
+ unset($this->results[$class]);
+ unset($this->stats[$class]);
+ }
}
}
}