mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 12:05:37 +00:00
API CHANGE Removing support for PHPUnit 3.4 (3.5.0 has been released in Sept 2010). Removing PhpUnitWrapper_3_4, and adding better version detection.
This commit is contained in:
parent
65f6104cd6
commit
23e342ce03
@ -89,7 +89,7 @@ class TestRunner extends Controller {
|
|||||||
if (!self::$default_reporter) self::set_reporter(Director::is_cli() ? 'CliDebugView' : 'DebugView');
|
if (!self::$default_reporter) self::set_reporter(Director::is_cli() ? 'CliDebugView' : 'DebugView');
|
||||||
|
|
||||||
if(!PhpUnitWrapper::has_php_unit()) {
|
if(!PhpUnitWrapper::has_php_unit()) {
|
||||||
die("Please install PHPUnit using pear");
|
die("Please install PHPUnit 3.5.0 or newer using pear\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -22,7 +22,7 @@ function fileExistsInIncludePath($filename) {
|
|||||||
/**
|
/**
|
||||||
* PHPUnit Wrapper class.
|
* PHPUnit Wrapper class.
|
||||||
* Base class for PHPUnit wrapper classes to support different PHPUnit versions.
|
* Base class for PHPUnit wrapper classes to support different PHPUnit versions.
|
||||||
* The current implementation supports PHPUnit 3.4 and PHPUnit 3.5.
|
* The current implementation supports PHPUnit 3.5.
|
||||||
*/
|
*/
|
||||||
class PhpUnitWrapper implements IPhpUnitWrapper {
|
class PhpUnitWrapper implements IPhpUnitWrapper {
|
||||||
|
|
||||||
@ -49,13 +49,6 @@ class PhpUnitWrapper implements IPhpUnitWrapper {
|
|||||||
*/
|
*/
|
||||||
private $reporter = null;
|
private $reporter = null;
|
||||||
|
|
||||||
/**
|
|
||||||
* Shows the version, implemented by the phpunit-wrapper class instance.
|
|
||||||
* This instance implements no phpunit, the version is null.
|
|
||||||
* @var String
|
|
||||||
*/
|
|
||||||
protected $version = null;
|
|
||||||
|
|
||||||
private static $phpunit_wrapper = null;
|
private static $phpunit_wrapper = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -123,11 +116,10 @@ class PhpUnitWrapper implements IPhpUnitWrapper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Getter for $version (@see $version).
|
|
||||||
* @return String
|
* @return String
|
||||||
*/
|
*/
|
||||||
public function getVersion() {
|
public function getVersion() {
|
||||||
return $this->version;
|
return (method_exists('PHPUnit_Runner_Version', 'id')) ? PHPUnit_Runner_Version::id() : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -140,25 +132,21 @@ class PhpUnitWrapper implements IPhpUnitWrapper {
|
|||||||
if (self::$phpunit_wrapper == null) {
|
if (self::$phpunit_wrapper == null) {
|
||||||
if (fileExistsInIncludePath("/PHPUnit/Autoload.php")) {
|
if (fileExistsInIncludePath("/PHPUnit/Autoload.php")) {
|
||||||
self::$phpunit_wrapper = new PhpUnitWrapper_3_5();
|
self::$phpunit_wrapper = new PhpUnitWrapper_3_5();
|
||||||
} else
|
|
||||||
if (fileExistsInIncludePath("/PHPUnit/Framework.php")) {
|
|
||||||
self::$phpunit_wrapper = new PhpUnitWrapper_3_4();
|
|
||||||
} else {
|
} else {
|
||||||
self::$phpunit_wrapper = new PhpUnitWrapper();
|
self::$phpunit_wrapper = new PhpUnitWrapper();
|
||||||
}
|
}
|
||||||
self::$phpunit_wrapper->init();
|
self::$phpunit_wrapper->init();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return self::$phpunit_wrapper;
|
return self::$phpunit_wrapper;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns true if one of the two supported PHPUNIT versions is installed.
|
|
||||||
*
|
|
||||||
* @return boolean true if PHPUnit has been installed on the environment.
|
* @return boolean true if PHPUnit has been installed on the environment.
|
||||||
*/
|
*/
|
||||||
static function has_php_unit() {
|
static function has_php_unit() {
|
||||||
return (Bool) self::inst()->getVersion();
|
$version = self::inst()->getVersion();
|
||||||
|
return ($version && version_compare($version, '3.5.0', '>='));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1,63 +0,0 @@
|
|||||||
<?php
|
|
||||||
/**
|
|
||||||
* @package sapphire
|
|
||||||
* @subpackage dev
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* PHPUnit Wrapper class. Implements the correct behaviour for PHPUnit V3.4.
|
|
||||||
*/
|
|
||||||
class PhpUnitWrapper_3_4 extends PhpUnitWrapper {
|
|
||||||
|
|
||||||
protected $version = 'PhpUnit V3.4';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Initialise the wrapper class.
|
|
||||||
*/
|
|
||||||
public function init() {
|
|
||||||
parent::init();
|
|
||||||
require_once 'PHPUnit/Framework.php';
|
|
||||||
require_once 'PHPUnit/Util/Report.php';
|
|
||||||
require_once 'PHPUnit/TextUI/TestRunner.php';
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Overwrites beforeRunTests. Initiates coverage-report generation if
|
|
||||||
* $coverage has been set to true (@see setCoverageStatus).
|
|
||||||
*/
|
|
||||||
protected function beforeRunTests() {
|
|
||||||
|
|
||||||
if($this->getCoverageStatus()) {
|
|
||||||
// blacklist selected folders from coverage report
|
|
||||||
foreach(TestRunner::$coverage_filter_dirs as $dir) {
|
|
||||||
PHPUnit_Util_Filter::addDirectoryToFilter(BASE_PATH . '/' . $dir);
|
|
||||||
}
|
|
||||||
$this->getFrameworkTestResults()->collectCodeCoverageInformation(true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Overwrites aferRunTests. Creates coverage report and clover report
|
|
||||||
* if required.
|
|
||||||
*/
|
|
||||||
protected function aferRunTests() {
|
|
||||||
|
|
||||||
if($this->getCoverageStatus()) {
|
|
||||||
|
|
||||||
if(!file_exists(ASSETS_PATH . '/coverage-report')) {
|
|
||||||
mkdir(ASSETS_PATH . '/coverage-report');
|
|
||||||
}
|
|
||||||
|
|
||||||
$ret = PHPUnit_Util_Report::render($this->getFrameworkTestResults(), ASSETS_PATH . '/coverage-report/');
|
|
||||||
|
|
||||||
$coverageApp = ASSETS_PATH . '/coverage-report/' . preg_replace('/[^A-Za-z0-9]/','_',preg_replace('/(\/$)|(^\/)/','',Director::baseFolder())) . '.html';
|
|
||||||
$coverageTemplates = ASSETS_PATH . '/coverage-report/' . preg_replace('/[^A-Za-z0-9]/','_',preg_replace('/(\/$)|(^\/)/','',realpath(TEMP_FOLDER))) . '.html';
|
|
||||||
|
|
||||||
echo "<p>Coverage reports available here:<ul>
|
|
||||||
<li><a href=\"$coverageApp\">Coverage report of the application</a></li>
|
|
||||||
<li><a href=\"$coverageTemplates\">Coverage report of the templates</a></li>
|
|
||||||
</ul>";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -6,8 +6,6 @@
|
|||||||
|
|
||||||
class PhpUnitWrapper_3_5 extends PhpUnitWrapper {
|
class PhpUnitWrapper_3_5 extends PhpUnitWrapper {
|
||||||
|
|
||||||
protected $version = 'PhpUnit V3.5';
|
|
||||||
|
|
||||||
protected $coverage = null;
|
protected $coverage = null;
|
||||||
|
|
||||||
protected static $test_name = 'SapphireTest';
|
protected static $test_name = 'SapphireTest';
|
||||||
|
Loading…
x
Reference in New Issue
Block a user