2010-10-19 05:06:55 +02:00
|
|
|
<?php
|
2010-10-19 05:35:14 +02:00
|
|
|
/**
|
|
|
|
* @package sapphire
|
|
|
|
* @subpackage dev
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* PHPUnit Wrapper class. Implements the correct behaviour for PHPUnit V3.4.
|
|
|
|
*/
|
2010-10-19 05:06:55 +02:00
|
|
|
class PhpUnitWrapper_3_4 extends PhpUnitWrapper {
|
|
|
|
|
|
|
|
protected $version = 'PhpUnit V3.4';
|
|
|
|
|
2010-10-19 05:35:14 +02:00
|
|
|
/**
|
|
|
|
* Initialise the wrapper class.
|
|
|
|
*/
|
2010-10-19 05:06:55 +02:00
|
|
|
public function init() {
|
2010-10-19 05:35:14 +02:00
|
|
|
parent::init();
|
2010-10-19 05:06:55 +02:00
|
|
|
require_once 'PHPUnit/Framework.php';
|
|
|
|
require_once 'PHPUnit/Util/Report.php';
|
|
|
|
require_once 'PHPUnit/TextUI/TestRunner.php';
|
|
|
|
}
|
|
|
|
|
2010-10-19 05:35:14 +02:00
|
|
|
/**
|
|
|
|
* Overwrites beforeRunTests. Initiates coverage-report generation if
|
|
|
|
* $coverage has been set to true (@see setCoverageStatus).
|
|
|
|
*/
|
2010-10-19 05:06:55 +02:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-10-19 05:35:14 +02:00
|
|
|
/**
|
|
|
|
* Overwrites aferRunTests. Creates coverage report and clover report
|
|
|
|
* if required.
|
|
|
|
*/
|
2010-10-19 05:06:55 +02:00
|
|
|
protected function aferRunTests() {
|
|
|
|
|
|
|
|
if($this->getCoverageStatus()) {
|
|
|
|
|
|
|
|
if(!file_exists(ASSETS_PATH . '/coverage-report')) {
|
|
|
|
mkdir(ASSETS_PATH . '/coverage-report');
|
|
|
|
}
|
|
|
|
|
2010-10-19 05:35:14 +02:00
|
|
|
$ret = PHPUnit_Util_Report::render($this->getFrameworkTestResults(), ASSETS_PATH . '/coverage-report/');
|
2010-10-19 05:06:55 +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';
|
|
|
|
|
|
|
|
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>";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|