mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
BUG Allow PHPUnit installation with composer / Fix travis
This commit is contained in:
parent
be59fd9237
commit
ca62f73330
@ -13,7 +13,7 @@ before_script:
|
||||
- cd ~/builds/ss
|
||||
|
||||
script:
|
||||
- phpunit sapphire/tests
|
||||
- vendor/bin/phpunit sapphire/tests
|
||||
|
||||
branches:
|
||||
except:
|
||||
|
@ -18,5 +18,8 @@
|
||||
"require": {
|
||||
"php": ">=5.2.4",
|
||||
"composer/installers": "*"
|
||||
},
|
||||
"require-dev": {
|
||||
"phpunit/PHPUnit": "~3.7"
|
||||
}
|
||||
}
|
||||
|
@ -135,17 +135,25 @@ class PhpUnitWrapper implements IPhpUnitWrapper {
|
||||
*
|
||||
* @return PhpUnitWrapper Instance of the php-wrapper class
|
||||
*/
|
||||
static function inst() {
|
||||
public static function inst() {
|
||||
|
||||
if (self::$phpunit_wrapper == null) {
|
||||
if (fileExistsInIncludePath("/PHPUnit/Autoload.php")) {
|
||||
self::$phpunit_wrapper = new PhpUnitWrapper_3_5();
|
||||
} else
|
||||
if (fileExistsInIncludePath("/PHPUnit/Framework.php")) {
|
||||
self::$phpunit_wrapper = new PhpUnitWrapper_3_4();
|
||||
} else {
|
||||
self::$phpunit_wrapper = new PhpUnitWrapper();
|
||||
}
|
||||
// Loaded via autoloader, composer or other generic
|
||||
if (class_exists('PHPUnit_Runner_Version')) {
|
||||
self::$phpunit_wrapper = new PhpUnitWrapper_Generic();
|
||||
}
|
||||
// 3.5 detection
|
||||
else if (fileExistsInIncludePath("/PHPUnit/Autoload.php")) {
|
||||
self::$phpunit_wrapper = new PhpUnitWrapper_3_5();
|
||||
}
|
||||
// 3.4 detection
|
||||
else if (fileExistsInIncludePath("/PHPUnit/Framework.php")) {
|
||||
self::$phpunit_wrapper = new PhpUnitWrapper_3_4();
|
||||
}
|
||||
// No version found - will lead to an error
|
||||
else {
|
||||
self::$phpunit_wrapper = new PhpUnitWrapper();
|
||||
}
|
||||
self::$phpunit_wrapper->init();
|
||||
|
||||
}
|
||||
@ -209,7 +217,7 @@ class PhpUnitWrapper implements IPhpUnitWrapper {
|
||||
|
||||
$this->beforeRunTests();
|
||||
$this->getSuite()->run($this->getFrameworkTestResults());
|
||||
$this->aferRunTests();
|
||||
$this->afterRunTests();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -9,7 +9,9 @@
|
||||
*/
|
||||
class PhpUnitWrapper_3_4 extends PhpUnitWrapper {
|
||||
|
||||
protected $version = 'PhpUnit V3.4';
|
||||
public function getVersion() {
|
||||
return 'PhpUnit V3.4';
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialise the wrapper class.
|
||||
@ -37,10 +39,10 @@ class PhpUnitWrapper_3_4 extends PhpUnitWrapper {
|
||||
}
|
||||
|
||||
/**
|
||||
* Overwrites aferRunTests. Creates coverage report and clover report
|
||||
* Overwrites afterRunTests. Creates coverage report and clover report
|
||||
* if required.
|
||||
*/
|
||||
protected function aferRunTests() {
|
||||
protected function afterRunTests() {
|
||||
|
||||
if($this->getCoverageStatus()) {
|
||||
|
||||
|
@ -4,64 +4,21 @@
|
||||
* @subpackage dev
|
||||
*/
|
||||
|
||||
class PhpUnitWrapper_3_5 extends PhpUnitWrapper {
|
||||
class PhpUnitWrapper_3_5 extends PhpUnitWrapper_Generic {
|
||||
|
||||
protected $version = 'PhpUnit V3.5';
|
||||
|
||||
protected $coverage = null;
|
||||
|
||||
protected static $test_name = 'SapphireTest';
|
||||
|
||||
static function get_test_name() {
|
||||
return self::$test_name;
|
||||
public function getVersion() {
|
||||
return 'PhpUnit V3.5';
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialise the wrapper class.
|
||||
*/
|
||||
public function init() {
|
||||
require_once 'PHP/CodeCoverage.php';
|
||||
require_once 'PHP/CodeCoverage/Report/HTML.php';
|
||||
|
||||
require_once 'PHPUnit/Autoload.php';
|
||||
|
||||
require_once 'PHP/CodeCoverage/Filter.php';
|
||||
}
|
||||
|
||||
/**
|
||||
* Overwrites beforeRunTests. Initiates coverage-report generation if
|
||||
* $coverage has been set to true (@see setCoverageStatus).
|
||||
*/
|
||||
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);
|
||||
}
|
||||
|
||||
$filter->addFileToBlacklist(__FILE__, 'PHPUNIT');
|
||||
|
||||
$coverage->start(self::get_test_name());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Overwrites aferRunTests. Creates coverage report and clover report
|
||||
* if required.
|
||||
*/
|
||||
protected function aferRunTests() {
|
||||
|
||||
if($this->getCoverageStatus()) {
|
||||
$coverage = $this->coverage;
|
||||
$coverage->stop();
|
||||
|
||||
$writer = new PHP_CodeCoverage_Report_HTML();
|
||||
$writer->process($coverage, ASSETS_PATH.'/code-coverage-report');
|
||||
if(!class_exists('PHPUnit_Framework_TestCase')) {
|
||||
require_once 'PHP/CodeCoverage.php';
|
||||
require_once 'PHP/CodeCoverage/Report/HTML.php';
|
||||
require_once 'PHPUnit/Autoload.php';
|
||||
require_once 'PHP/CodeCoverage/Filter.php';
|
||||
}
|
||||
}
|
||||
|
||||
|
63
dev/phpunit/PhpUnitWrapper_Generic.php
Normal file
63
dev/phpunit/PhpUnitWrapper_Generic.php
Normal file
@ -0,0 +1,63 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Generic PhpUnitWrapper.
|
||||
* Originally intended for use with Composer based installations, but will work
|
||||
* with any fully functional autoloader.
|
||||
*/
|
||||
class PhpUnitWrapper_Generic extends PhpUnitWrapper {
|
||||
|
||||
/**
|
||||
* Returns a version string, like 3.7.34 or 4.2-dev.
|
||||
* @return string
|
||||
*/
|
||||
public function getVersion() {
|
||||
return PHPUnit_Runner_Version::id();
|
||||
}
|
||||
|
||||
protected $coverage = null;
|
||||
|
||||
protected static $test_name = 'SapphireTest';
|
||||
|
||||
public static function get_test_name() {
|
||||
return static::$test_name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Overwrites beforeRunTests. Initiates coverage-report generation if
|
||||
* $coverage has been set to true (@see setCoverageStatus).
|
||||
*/
|
||||
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);
|
||||
}
|
||||
|
||||
$filter->addFileToBlacklist(__FILE__, 'PHPUNIT');
|
||||
|
||||
$coverage->start(self::get_test_name());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Overwrites afterRunTests. Creates coverage report and clover report
|
||||
* if required.
|
||||
*/
|
||||
protected function afterRunTests() {
|
||||
|
||||
if($this->getCoverageStatus()) {
|
||||
$coverage = $this->coverage;
|
||||
$coverage->stop();
|
||||
|
||||
$writer = new PHP_CodeCoverage_Report_HTML();
|
||||
$writer->process($coverage, ASSETS_PATH.'/code-coverage-report');
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user