2010-01-06 01:29:08 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* CakeBaseReporter contains common functionality to all cake test suite reporters.
|
|
|
|
*
|
2010-10-03 16:31:21 +00:00
|
|
|
* PHP 5
|
2010-01-06 01:29:08 +00:00
|
|
|
*
|
2010-05-19 01:15:13 +00:00
|
|
|
* CakePHP(tm) Tests <http://book.cakephp.org/view/1196/Testing>
|
2010-01-06 01:29:08 +00:00
|
|
|
* Copyright 2005-2009, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
|
|
|
*
|
2010-10-03 16:31:21 +00:00
|
|
|
* Licensed under The MIT License
|
|
|
|
* Redistributions of files must retain the above copyright notice
|
2010-01-06 01:29:08 +00:00
|
|
|
*
|
|
|
|
* @copyright Copyright 2005-2009, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
2010-01-26 22:03:03 +00:00
|
|
|
* @link http://cakephp.org CakePHP(tm) Project
|
2010-01-06 01:29:08 +00:00
|
|
|
* @package cake
|
2010-01-10 01:20:13 +00:00
|
|
|
* @subpackage cake.tests.libs.reporter
|
2010-01-06 01:29:08 +00:00
|
|
|
* @since CakePHP(tm) v 1.3
|
2010-10-03 16:27:27 +00:00
|
|
|
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
2010-01-06 01:29:08 +00:00
|
|
|
*/
|
|
|
|
|
2010-09-28 03:07:23 +00:00
|
|
|
PHP_CodeCoverage_Filter::getInstance()->addFileToBlacklist(__FILE__, 'DEFAULT');
|
2010-05-08 20:18:45 +00:00
|
|
|
|
2010-01-06 01:29:08 +00:00
|
|
|
/**
|
|
|
|
* CakeBaseReporter contains common reporting features used in the CakePHP Test suite
|
|
|
|
*
|
|
|
|
* @package cake
|
|
|
|
* @subpackage cake.tests.lib
|
|
|
|
*/
|
2010-05-13 04:18:22 +00:00
|
|
|
class CakeBaseReporter implements PHPUnit_Framework_TestListener {
|
2010-01-06 01:29:08 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Time the test runs started.
|
|
|
|
*
|
|
|
|
* @var integer
|
|
|
|
* @access protected
|
|
|
|
*/
|
2010-04-04 06:36:12 +00:00
|
|
|
protected $_timeStart = 0;
|
2010-01-06 01:29:08 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Time the test runs ended
|
|
|
|
*
|
|
|
|
* @var integer
|
|
|
|
* @access protected
|
|
|
|
*/
|
2010-04-04 06:36:12 +00:00
|
|
|
protected $_timeEnd = 0;
|
2010-01-06 01:29:08 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Duration of all test methods.
|
|
|
|
*
|
|
|
|
* @var integer
|
|
|
|
* @access protected
|
|
|
|
*/
|
2010-04-04 06:36:12 +00:00
|
|
|
protected $_timeDuration = 0;
|
2010-01-06 01:29:08 +00:00
|
|
|
|
2010-01-09 16:20:47 +00:00
|
|
|
/**
|
|
|
|
* Array of request parameters. Usually parsed GET params.
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
*/
|
2010-04-04 07:14:00 +00:00
|
|
|
public $params = array();
|
2010-01-09 16:20:47 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Character set for the output of test reporting.
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
* @access protected
|
|
|
|
*/
|
2010-04-04 06:36:12 +00:00
|
|
|
protected $_characterSet;
|
2010-01-09 16:20:47 +00:00
|
|
|
|
2010-05-04 21:01:03 +00:00
|
|
|
/**
|
|
|
|
* The number of assertions done for a test suite
|
|
|
|
*/
|
|
|
|
protected $numAssertions = 0;
|
2010-01-09 16:20:47 +00:00
|
|
|
/**
|
|
|
|
* Does nothing yet. The first output will
|
|
|
|
* be sent on the first test start.
|
|
|
|
*
|
|
|
|
* ### Params
|
|
|
|
*
|
|
|
|
* - show_passes - Should passes be shown
|
|
|
|
* - plugin - Plugin test being run?
|
|
|
|
* - app - App test being run.
|
|
|
|
* - case - The case being run
|
2010-01-10 18:24:41 +00:00
|
|
|
* - codeCoverage - Whether the case/group being run is being code covered.
|
2010-01-09 16:20:47 +00:00
|
|
|
*
|
|
|
|
* @param string $charset The character set to output with. Defaults to UTF-8
|
|
|
|
* @param array $params Array of request parameters the reporter should use. See above.
|
|
|
|
*/
|
2010-04-15 02:56:51 +00:00
|
|
|
function __construct($charset = 'utf-8', $params = array()) {
|
2010-01-10 17:48:11 +00:00
|
|
|
if (!$charset) {
|
|
|
|
$charset = 'utf-8';
|
|
|
|
}
|
2010-01-09 16:20:47 +00:00
|
|
|
$this->_characterSet = $charset;
|
|
|
|
$this->params = $params;
|
|
|
|
}
|
|
|
|
|
2010-01-06 03:52:25 +00:00
|
|
|
/**
|
|
|
|
* Retrieves a list of test cases from the active Manager class,
|
|
|
|
* displaying it in the correct format for the reporter subclass
|
|
|
|
*
|
|
|
|
* @return mixed
|
|
|
|
*/
|
2010-04-15 02:56:51 +00:00
|
|
|
public function testCaseList() {
|
2010-06-09 22:37:24 +00:00
|
|
|
$testList = TestManager::getTestCaseList($this->params);
|
2010-01-09 15:55:58 +00:00
|
|
|
return $testList;
|
2010-01-06 03:52:25 +00:00
|
|
|
}
|
|
|
|
|
2010-01-07 03:52:04 +00:00
|
|
|
/**
|
2010-01-09 16:20:47 +00:00
|
|
|
* Paints the start of the response from the test suite.
|
2010-01-07 03:52:04 +00:00
|
|
|
* Used to paint things like head elements in an html page.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2010-04-15 02:56:51 +00:00
|
|
|
public function paintDocumentStart() {
|
2010-01-07 03:52:04 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2010-01-09 16:20:47 +00:00
|
|
|
* Paints the end of the response from the test suite.
|
2010-01-07 03:52:04 +00:00
|
|
|
* Used to paint things like </body> in an html page.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2010-04-15 02:56:51 +00:00
|
|
|
public function paintDocumentEnd() {
|
2010-01-09 16:20:47 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Paint a list of test sets, core, app, and plugin test sets
|
|
|
|
* available.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2010-04-15 02:56:51 +00:00
|
|
|
public function paintTestMenu() {
|
2010-01-06 03:52:25 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2010-01-09 16:20:47 +00:00
|
|
|
/**
|
|
|
|
* Get the baseUrl if one is available.
|
|
|
|
*
|
|
|
|
* @return string The base url for the request.
|
|
|
|
*/
|
2010-04-15 02:56:51 +00:00
|
|
|
public function baseUrl() {
|
2010-01-09 16:20:47 +00:00
|
|
|
if (!empty($_SERVER['PHP_SELF'])) {
|
|
|
|
return $_SERVER['PHP_SELF'];
|
|
|
|
}
|
|
|
|
return '';
|
|
|
|
}
|
|
|
|
|
2010-05-13 04:18:22 +00:00
|
|
|
public function paintResult(PHPUnit_Framework_TestResult $result) {
|
|
|
|
$this->paintFooter($result);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* An error occurred.
|
|
|
|
*
|
|
|
|
* @param PHPUnit_Framework_Test $test
|
|
|
|
* @param Exception $e
|
|
|
|
* @param float $time
|
|
|
|
*/
|
|
|
|
public function addError(PHPUnit_Framework_Test $test, Exception $e, $time) {
|
2010-07-15 02:58:42 +00:00
|
|
|
$this->paintException($e, $test);
|
2010-05-13 04:18:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A failure occurred.
|
|
|
|
*
|
|
|
|
* @param PHPUnit_Framework_Test $test
|
|
|
|
* @param PHPUnit_Framework_AssertionFailedError $e
|
|
|
|
* @param float $time
|
|
|
|
*/
|
|
|
|
public function addFailure(PHPUnit_Framework_Test $test, PHPUnit_Framework_AssertionFailedError $e, $time) {
|
2010-07-15 02:58:42 +00:00
|
|
|
$this->paintFail($e, $test);
|
2010-05-13 04:18:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Incomplete test.
|
|
|
|
*
|
|
|
|
* @param PHPUnit_Framework_Test $test
|
|
|
|
* @param Exception $e
|
|
|
|
* @param float $time
|
|
|
|
*/
|
|
|
|
public function addIncompleteTest(PHPUnit_Framework_Test $test, Exception $e, $time) {
|
2010-06-12 22:55:27 +00:00
|
|
|
$this->paintSkip($e, $test);
|
2010-05-13 04:18:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Skipped test.
|
|
|
|
*
|
|
|
|
* @param PHPUnit_Framework_Test $test
|
|
|
|
* @param Exception $e
|
|
|
|
* @param float $time
|
|
|
|
*/
|
|
|
|
public function addSkippedTest(PHPUnit_Framework_Test $test, Exception $e, $time) {
|
2010-05-18 03:01:22 +00:00
|
|
|
$this->paintSkip($e, $test);
|
2010-05-13 04:18:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A test suite started.
|
|
|
|
*
|
|
|
|
* @param PHPUnit_Framework_TestSuite $suite
|
|
|
|
*/
|
|
|
|
public function startTestSuite(PHPUnit_Framework_TestSuite $suite) {
|
|
|
|
echo sprintf(__('Running %s'), $suite->getName()) . "\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A test suite ended.
|
|
|
|
*
|
|
|
|
* @param PHPUnit_Framework_TestSuite $suite
|
|
|
|
*/
|
|
|
|
public function endTestSuite(PHPUnit_Framework_TestSuite $suite) {
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A test started.
|
|
|
|
*
|
|
|
|
* @param PHPUnit_Framework_Test $test
|
|
|
|
*/
|
|
|
|
public function startTest(PHPUnit_Framework_Test $test) {
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A test ended.
|
|
|
|
*
|
|
|
|
* @param PHPUnit_Framework_Test $test
|
|
|
|
* @param float $time
|
|
|
|
*/
|
|
|
|
public function endTest(PHPUnit_Framework_Test $test, $time) {
|
|
|
|
$this->numAssertions += $test->getNumAssertions();
|
|
|
|
$this->paintPass($test, $time);
|
|
|
|
}
|
|
|
|
|
2010-01-06 01:29:08 +00:00
|
|
|
}
|