'browse', '$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'); } public function Link() { return Controller::join_links(Director::absoluteBaseURL(), 'dev/tests/'); } /** * Run all test classes */ function all() { die("here"); if(hasPhpUnit()) { $tests = ClassInfo::subclassesFor('SapphireTest'); array_shift($tests); unset($tests['FunctionalTest']); $this->runTests($tests); } else { echo "Please install PHPUnit using pear"; } } /** * Browse all enabled test cases in the environment */ function browse() { self::$default_reporter->writeHeader(); echo '
'; echo '

Available Tests

'; echo '
'; echo '
'; $tests = ClassInfo::subclassesFor('SapphireTest'); echo "

Link() . "all\">Run all " . count($tests) . " tests

"; echo "
"; foreach ($tests as $test) { echo "

Link() . "$test\">Run $test

"; } echo '
'; self::$default_reporter->writeFooter(); } 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 { if ($className == 'all') $this->all(); } } function runTests($classList, $coverage = false) { // run tests before outputting anything to the client $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")*/ $reporter = new SapphireTestReporter(); $results = new PHPUnit_Framework_TestResult(); $results->addListener($reporter); /*, array("reportDirectory" => "/Users/sminnee/phpunit-report")*/ if($coverage) { $suite->run($results); //$testResult = PHPUnit_TextUI_TestRunner::run($suite, array("reportDirectory" => "../assets/coverage-report")); $coverageURL = Director::absoluteURL('assets/coverage-report'); echo "

Coverage report available here

"; } else { $suite->run($results); //$testResult = PHPUnit_TextUI_TestRunner::run($suite); } self::$default_reporter->writeHeader(); if (count($classList) > 1) { self::$default_reporter->writeInfo("All Tests", "Running test cases: " . implode(", ", $classList) .")"); } else { self::$default_reporter->writeInfo($classList[0], ""); } echo '
'; $reporter->writeResults(); 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->failureCount() + $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 { } }