silverstripe-framework/dev/phpunit/PhpUnitWrapper_3_5.php
Ingo Schommer 73824f3a24 ENHANCEMENT: Created a phpunit wrapper class to ensure that Sapphire's test framework is capable of running unit tests, coverage report and retrieve clover-statistics for PHPUnit 3.4 and PHPUnit 3.5
git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/branches/2.4@111039 467b73ca-7a2a-4603-9d3b-597d59a354a9
2011-02-02 14:19:50 +13:00

84 lines
1.9 KiB
PHP

<?php
class PhpUnitWrapper_3_5 extends PhpUnitWrapper {
protected $version = 'PhpUnit V3.5';
protected $coverage = null;
protected static $test_name = 'SapphireTest';
protected static $generate_clover = false;
protected static $clover_filename = 'clover.xml';
static function get_test_name() {
return self::$test_name;
}
static function get_generate_clover() {
return self::$generate_clover;
}
static function set_generate_clover($value) {
self::$generate_clover = $value;
}
static function get_clover_filename() {
return self::$clover_filename;
}
static function set_clover_filename($value) {
self::$clover_filename = $value;
}
public function init() {
require_once 'PHP/CodeCoverage.php';
require_once 'PHP/CodeCoverage/Report/Clover.php';
require_once 'PHP/CodeCoverage/Report/HTML.php';
require_once 'PHPUnit/Autoload.php';
require_once 'PHP/CodeCoverage/Filter.php';
PHP_CodeCoverage_Filter::getInstance()->addFileToBlacklist(__FILE__, 'PHPUNIT');
}
protected function beforeRunTests() {
if($this->getCoverageStatus()) {
$this->coverage = new PHP_CodeCoverage;
$coverage = $this->coverage;
$filter = $coverage->filter();
foreach(TestRunner::$coverage_filter_dirs as $dir) {
$filter->addDirectoryToBlacklist(BASE_PATH . '/' . $dir);
}
$coverage->start(self::get_test_name());
}
}
protected function aferRunTests() {
if($this->getCoverageStatus()) {
$coverage = $this->coverage;
$coverage->stop();
if (self::get_generate_clover() == true) {
$filename = self::get_clover_filename();
$writer = new PHP_CodeCoverage_Report_Clover;
$writer->process($coverage, ASSETS_PATH."/".$filename);
}
$writer = new PHP_CodeCoverage_Report_HTML;
$writer->process($coverage, ASSETS_PATH.'/code-coverage-report');
}
}
public function runTests() {
return parent::runTests();
}
}