Revision
9
Author
emsmith
Date
2006-08-15 10:10:11 -0700 (Tue, 15 Aug 2006)

Log Message

Actually, I'm messing with some properties and websvn at the moment - so ignore this

Modified Paths

Property Changed

Diff

Modified: library/trunk/lib/test/runner.class.php (8 => 9)


--- library/trunk/lib/test/runner.class.php	2006-08-11 18:26:34 UTC (rev 8)
+++ library/trunk/lib/test/runner.class.php	2006-08-15 17:10:11 UTC (rev 9)
@@ -26,7 +26,7 @@
 class CCL_TestRunner
 {
 	/**
-	 * list of testcases to run
+	 * list of testunit classes to run
 	 * @var $queue array
 	 */
 	private $queue = array();
@@ -34,42 +34,55 @@
 	/**
 	 * public function __construct
 	 *
-	 * discovers if this is being called via the command
+	 * discovers if this is being called via cli or through a web sapi, you
+	 * can override auto configuration by sending config information
 	 *
 	 * @param type $name about
 	 * @return type about
 	 */
-	public function __construct()
+	public function __construct(array $config = NULL)
 	{
-		// configuration - webpage or cli?
-		// cli will look for ini file or command line args
-		// web will look for get/post and/or show form
+		$this->cli = PHP_SAPI === 'cli' ? TRUE : FALSE;
+		// cli interface shortcut
+		// webpage form shortcut
+		if (!is_null($config))
+		{
+			//$this->setConfig($config);
+		}
+		elseif ($this->cli)
+		{
+			// command line args or display cli entry interface
+		}
+		else
+		{
+			// get/post or display webpage form
+		}
 		return;
 	}
 
 	/**
 	 * public function addTest
 	 *
-	 * add a testcase or testsuite subclass to the queue
+	 * add a testunit class to the queue
 	 *
-	 * @param string|object $class name of class or class object
+	 * @param string $class name of class
+	 * @param string $method name of method
 	 * @return void
 	 */
-	public function addTest($class)
+	public function addTest($class, $method = NULL)
 	{
-		if (get_parent_class($class) != 'CCL_TestUnit' &&
-				get_parent_class($class) != 'CCL_TestSuite')
+		if (get_parent_class($class) != 'CCL_TestUnit')
 		{
-			throw new Exception(get_class($class) . ' must be a subclass of CCL_TestCase or CCL_TestSuite');
+			throw new Exception(get_class($class) . ' must be a subclass of CCL_TestUnit');
 			return;
 		}
-		if (is_object($class))
+		if (is_null($class))
 		{
 			$this->queue[] = $class;
 		}
 		else
 		{
-			$this->queue[] = new $class();
+			$this->queue[] = array($class, $method);
 		}
 		return;
 	}
@@ -78,7 +91,7 @@
 	 * public function addFile
 	 *
 	 * add a single file or directory of files - the files are included and
-	 * any testsuite or testcase classes are added to the queue
+	 * testunit classes are added to the queue
 	 *
 	 * @param string $filename directory or file to add
 	 * @return void
@@ -87,7 +100,7 @@
 	{
 		if (!file_exists($filename))
 		{
-			throw new Exception($filename . ' does not exist and could not be added to the test suite');
+			throw new Exception($filename . ' does not exist and could not be added');
 			return;
 		}
 		if (is_file($filename))
@@ -100,7 +113,7 @@
 			foreach ($list as $name)
 			{
 				if (is_file($filename . DIRECTORY_SEPARATOR . $name) &&
-					pathinfo($name, PATHINFO_EXTENSION) == 'php' &&
+					pathinfo($name, PATHINFO_EXTENSION) == 'test.php' &&
 					!in_array($name{0}, array('.', '~')))
 				{
 					$this->includeFile($filename . DIRECTORY_SEPARATOR . $name);
@@ -118,29 +131,62 @@
 	/**
 	 * public function run
 	 *
-	 * runs the tests - this will recurse down like crazy without work :)
+	 * runs all tests in queue
 	 *
 	 * @return void
 	 */
 	public function run()
 	{
-		$this->reporter->testSuiteStart($this->name);
 		if (empty($this->queue))
 		{
 			throw new Exception('There are no TestUnits to run');
 		}
-		foreach ($this->queue as $object)
+		$result = new CCL_TestResult();
+		foreach ($this->reports as $class => $config)
 		{
-			$object->run();
+			$report = new $class($config);
+			$result->attach($report);
 		}
-		$this->reporter->testSuiteEnd();
+		foreach ($this->queue as $item)
+		{
+			if (is_array($item))
+			{
+				$class = new $item[0]($result);
+				$class->run($item[1]);
+			}
+			else
+			{
+				$class = new $item($result);
+				$class->run();
+			}
+		}
 		return;
 	}
 
+	//----------------------------------------------------------------
+	//             Internal Junk
+	//----------------------------------------------------------------
+
 	/**
+	 * private function includeLib
+	 *
+	 * includes the required files for getting testing to work
+	 *
+	 * @return void
+	 */
+	private function includeLib()
+	{
+		$dir = dirname(__FILE__) . DIRECTORY_SEPARATOR;
+		include($dir . 'error.class.php');
+		include($dir . 'result.class.php');
+		include($dir . 'unit.abstract.php');
+		// include report specific classes here
+	}
+
+	/**
 	 * private function includeFile
 	 *
-	 * includes the file and adds any suite/test children to the queue
+	 * includes the file and adds any testunit class names to the queue
 	 *
 	 * @param string $filename
 	 * @return void
@@ -153,10 +199,9 @@
 		$checklist = array_diff($postlist, $prelist);
 		foreach ($checklist as $class)
 		{
-			if (get_parent_class($class) == 'CCL_TestUnit' ||
-				get_parent_class($class) == 'CCL_TestSuite')
+			if (get_parent_class($class) == 'CCL_TestUnit')
 			{
-				$this->queue[] = new $class();
+				$this->queue[] = $class;
 			}
 		}
 		unset ($prelist, $postlist, $checklist);
Property changes on: library/trunk/lib/test/runner.class.php
___________________________________________________________________
Name: svn:mime-type
   - text/x-php
   + text/html