From 63224005f5f5ccf278cba4c39d852be66fba24b7 Mon Sep 17 00:00:00 2001 From: Sam Minnee Date: Mon, 25 Aug 2008 01:41:58 +0000 Subject: [PATCH] Fixed coverage reporting on test runner git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@61461 467b73ca-7a2a-4603-9d3b-597d59a354a9 --- dev/TestRunner.php | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/dev/TestRunner.php b/dev/TestRunner.php index e7a6fe104..8aa319272 100644 --- a/dev/TestRunner.php +++ b/dev/TestRunner.php @@ -17,6 +17,7 @@ function hasPhpUnit() { */ if(hasPhpUnit()) { require_once 'PHPUnit/Framework.php'; +require_once 'PHPUnit/Util/Report.php'; require_once 'PHPUnit/TextUI/TestRunner.php'; } @@ -32,6 +33,7 @@ class TestRunner extends Controller { static $url_handlers = array( '' => 'browse', + 'coverage' => 'coverage', '$TestCase' => 'only', ); @@ -80,7 +82,8 @@ class TestRunner extends Controller { echo '
'; $tests = ClassInfo::subclassesFor('SapphireTest'); echo "

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

"; - echo "
"; + echo "

Link() . "coverage\">Runs all tests and make test coverage report

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

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

"; } @@ -142,12 +145,19 @@ class TestRunner extends Controller { $results->addListener($reporter); if($coverage) { + $results->collectCodeCoverageInformation(true); $suite->run($results); - $coverageURL = Director::absoluteURL('assets/coverage-report'); - echo "

Coverage report available here

"; + + if(!file_exists('../assets/coverage-report')) mkdir('../assets/coverage-report'); + PHPUnit_Util_Report::render($results, '../assets/coverage-report/'); + $coverageApp = Director::baseURL() . 'assets/coverage-report/' . preg_replace('/[^A-Za-z0-9]/','_',preg_replace('/(\/$)|(^\/)/','',Director::baseFolder())) . '.html'; + $coverageTemplates = Director::baseURL() . 'assets/coverage-report/' . preg_replace('/[^A-Za-z0-9]/','_',preg_replace('/(\/$)|(^\/)/','',realpath(TEMP_FOLDER))) . '.html'; + echo "

Coverage reports available here:

"; } else { $suite->run($results); - //$testResult = PHPUnit_TextUI_TestRunner::run($suite); } echo '
';