2011-03-11 02:45:49 +01:00
|
|
|
<?php
|
|
|
|
/**
|
2012-04-12 08:02:46 +02:00
|
|
|
* @package framework
|
2011-03-11 02:45:49 +01:00
|
|
|
* @subpackage dev
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* PHPUnit Wrapper class. Implements the correct behaviour for PHPUnit V3.4.
|
|
|
|
*/
|
|
|
|
class PhpUnitWrapper_3_4 extends PhpUnitWrapper {
|
|
|
|
|
2014-04-17 15:14:51 +02:00
|
|
|
public function getVersion() {
|
|
|
|
return 'PhpUnit V3.4';
|
|
|
|
}
|
2011-03-11 02:45:49 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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
|
2012-03-24 04:38:57 +01:00
|
|
|
$modules = $this->moduleDirectories();
|
|
|
|
|
2013-03-21 19:48:54 +01:00
|
|
|
foreach(TestRunner::config()->coverage_filter_dirs as $dir) {
|
2012-03-24 04:38:57 +01:00
|
|
|
if($dir[0] == '*') {
|
|
|
|
$dir = substr($dir, 1);
|
|
|
|
foreach ($modules as $module) {
|
|
|
|
PHPUnit_Util_Filter::addDirectoryToFilter(BASE_PATH . '/' . $dir);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
PHPUnit_Util_Filter::addDirectoryToFilter(BASE_PATH . '/' . $dir);
|
|
|
|
}
|
|
|
|
}
|
2011-03-11 02:45:49 +01:00
|
|
|
$this->getFrameworkTestResults()->collectCodeCoverageInformation(true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2014-04-17 15:14:51 +02:00
|
|
|
* Overwrites afterRunTests. Creates coverage report and clover report
|
2011-03-11 02:45:49 +01:00
|
|
|
* if required.
|
|
|
|
*/
|
2014-04-17 15:14:51 +02:00
|
|
|
protected function afterRunTests() {
|
2011-03-11 02:45:49 +01:00
|
|
|
|
|
|
|
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/');
|
|
|
|
|
2012-09-26 23:34:00 +02:00
|
|
|
$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';
|
2011-03-11 02:45:49 +01:00
|
|
|
|
|
|
|
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>";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-03-24 04:38:57 +01:00
|
|
|
}
|