Parallel Unit Testing Structure - commentary request

At some point around day 3 of fighting getting PECL under windows I got PHPUnit to install. I played around with it some, but was somewhat unhappy with the results. I felt like, well, I was learning a sub language for testing. So while I will probably return to PHPUnit at a later point I tried out the following testing pattern and have had good results so far. The root is this object.


<?php
namespace GazelleTest;
/**
 * Root Unit Test class. Gazelle uses a system independent from
 * dependencies other than PHP itself, and this class it at the
 * heart of it.  Each Gazelle Unit Test is to have the same name
 * as the class that it tests, though each class exists in
 * separate namespaces.
 * 
 * @author Michael
 * @package Gazelle Testing
 */
abstract class UnitTest {
	/**
	 * Test Status codes. These form a bitfield, so the next
	 * one should be 4...
	 */
	const PASSED = 0;
	const FAIL = 1;
	const WRONG_EXCEPTION = 2;
	
	/**
	 * Tests to run.
	 * @var array
	 */
	protected $tests = array();
	
	/**
	 * Error record.
	 */
	public $errors = array();
	
	/**
	 * Setup Procedures
	 */
	protected abstract function setUp();
	
	/**
	 * Setup a test batch.  Each test should have the object that
	 * is being tested and parameters to test it against. Each
	 * Unit test needs at least one test batch.  The returned
	 * batch needs to be an array with three elements -
	 * 		obj => object being tested.
	 * 		params => parameters under testing.
	 * 		tests => Tests to be performed.
	 * 
	 * @param Name of the group
	 * @param Object under test
	 * @param Array of parameters to use for testing.
	 */
	protected abstract function setUpTests( $name, $obj, $params );
	
	public function __construct() {
		$this->setUp();
	}
	/**
	 * Set up and run the tests. Final because I do NOT want this methodology
	 * swapped on the child tests at all.
	 */
	public final function run() {		
		/* Iterate over the tests - each test should be a closure that
		 * takes the class to test as the sole argument. Return errors
		 * encountered in the test as a bitfield, or 0 for no errors.
		 */
		foreach ($this->tests as $group => $batch ) {
			foreach ($batch['tests'] as $name => $test ) {
				$error = $test();
				
				if ($error) {
					$msg = $name;
					
					if ( $error & self::PASSED ) {
						$msg .= ' PASSED';
					}
					
					if ( $error & self::FAIL ) {
						$msg .= ' FAIL';
					}
					
					if ($error & self::WRONG_EXCEPTION) {
						$msg .= ' WRONG_EXCEPTION';
					}
					
					$this->errors[$group][] = array (
						'message' => $msg,
						'object' => $batch['object'],
						'params' => $batch['params']
					);
				}
			}
		}
		
		return count($this->errors) == 0;
	}
	
	/**
	 * Return the fully qualified class name of our counterpart
	 * in the framework.
	 */	
	protected function getClassName() {
		return '\\\\Gazelle\\\\'.substr( get_class($this), strlen(__NAMESPACE__)+1 );
	}
}

The problem I am seeking to address is tracking inheritance dependency as painlessly as possible. To do this, I have the testing classes share names with what they test but lie in their own namespace. The tests themselves are closure arrays.

The tests extend from one another in the same way that the classes in the framework extend from each other. The only difference is at the top the tests extend from Unit test. I take advantage of namespacing to keep the objects under test ignorant of test constants and functions. My framework does not use global variables at all so var pollution isn’t a concern.

I think this pattern will work to a point - its fine for testing public exposures of the class. Internal states aren’t as easily testable - but I intend to bring in PHPUnit to handle that problem once I have a better handle on how it works.