'index', '$TestCase' => 'only' ); /** * Override the default reporter with a custom configured subclass. * * @param string $reporter */ static function set_reporter($reporter) { if (is_string($reporter)) $reporter = new $reporter; self::$default_reporter = $reporter; } function init() { parent::init(); if (!self::$default_reporter) self::set_reporter('DebugView'); } /** * Run all test classes */ function index() { if(hasPhpUnit()) { $tests = ClassInfo::subclassesFor('SapphireTest'); array_shift($tests); unset($tests['FunctionalTest']); $this->runTests($tests); } else { echo "Please install PHPUnit using pear"; } } function coverage() { if(hasPhpUnit()) { ManifestBuilder::includeEverything(); $tests = ClassInfo::subclassesFor('SapphireTest'); array_shift($tests); unset($tests['FunctionalTest']); $this->runTests($tests, true); } else { echo "Please install PHPUnit using pear"; } } /** * Run only a single test class */ function only($request) { $className = $request->param('TestCase'); if(class_exists($className)) { $this->runTests(array($className)); } else { echo "Class '$className' not found"; } } function runTests($classList, $coverage = false) { if(!Director::is_cli()) { self::$default_reporter->writeHeader(); echo '
Using the following subclasses of SapphireTest for testing: " . implode(", ", $classList) . "
"; 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")*/ if($coverage) { $testResult = PHPUnit_TextUI_TestRunner::run($suite, array("reportDirectory" => "../assets/coverage-report")); } else { $testResult = PHPUnit_TextUI_TestRunner::run($suite); } if($coverage) { $coverageURL = Director::absoluteURL('assets/coverage-report'); echo ""; } if(!Director::is_cli()) echo '