runTests($tests); } else { echo "Please install PHPUnit using pear"; } } /** * Run only a single test class */ function only() { $className = $this->urlParams['ID']; if(class_exists($className)) { $this->runTests(array($className)); } else { echo "Class '$className' not found"; } } function runTests($classList) { if(!Director::is_cli()) { self::$default_reporter->writeHeader(); echo '
'; echo "

Sapphire PHPUnit Test Runner

"; echo "

Using the following subclasses of SapphireTest for testing: " . implode(", ", $classList) . "

"; echo "
"; echo '
'; echo "
";
		} else {
			echo "Sapphire PHPUnit Test Runner\n";
			echo "Using the following subclasses of SapphireTest for testing: " . implode(", ", $classList) . "\n\n";
		}
		
		// Remove our error handler so that PHP can use its own
		//restore_error_handler();	
		
		$suite = new PHPUnit_Framework_TestSuite();
		foreach($classList as $className) {
			// Ensure that the autoloader pulls in the test class, as PHPUnit won't know how to do this.
			class_exists($className);
			$suite->addTest(new PHPUnit_Framework_TestSuite($className));
		}

		/*, array("reportDirectory" => "/Users/sminnee/phpunit-report")*/
		$testResult = PHPUnit_TextUI_TestRunner::run($suite);
		
		if(!Director::is_cli()) echo '
'; // Put the error handlers back Debug::loadErrorHandlers(); if(!Director::is_cli()) self::$default_reporter->writeFooter(); // Todo: we should figure out how to pass this data back through Director more cleanly if(Director::is_cli() && $testResult->errorCount() > 0) exit(2); } } // This class is here to help with documentation. if(!hasPhpUnit()) { /** * PHPUnit is a testing framework that can be installed using PEAR. * It's not bundled with Sapphire, you will need to install it yourself. * * @package sapphire * @subpackage testing */ class PHPUnit_Framework_TestCase { } }