2010-01-06 01:29:08 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* CakeBaseReporter contains common functionality to all cake test suite reporters.
|
|
|
|
*
|
|
|
|
* PHP versions 4 and 5
|
|
|
|
*
|
|
|
|
* CakePHP(tm) Tests <https://trac.cakephp.org/wiki/Developement/TestSuite>
|
|
|
|
* Copyright 2005-2009, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
|
|
|
*
|
|
|
|
* Licensed under The Open Group Test Suite License
|
|
|
|
* Redistributions of files must retain the above copyright notice.
|
|
|
|
*
|
|
|
|
* @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
|
|
|
|
* @license http://www.opensource.org/licenses/opengroup.php The Open Group Test Suite License
|
|
|
|
*/
|
|
|
|
|
2010-05-08 20:18:45 +00:00
|
|
|
PHPUnit_Util_Filter::addFileToFilter(__FILE__, 'DEFAULT');
|
|
|
|
|
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 01:29:08 +00:00
|
|
|
/**
|
|
|
|
* Signals / Paints the beginning of a TestSuite executing.
|
|
|
|
* Starts the timer for the TestSuite execution time.
|
|
|
|
*
|
|
|
|
* @param string $test_name Name of the test that is being run.
|
|
|
|
* @param integer $size
|
|
|
|
* @return void
|
|
|
|
*/
|
2010-04-15 02:56:51 +00:00
|
|
|
public function paintGroupStart($test_name, $size) {
|
2010-01-06 01:29:08 +00:00
|
|
|
if (empty($this->_timeStart)) {
|
2010-04-15 16:58:28 +00:00
|
|
|
$this->_timeStart = microtime(true);
|
2010-01-06 01:29:08 +00:00
|
|
|
}
|
|
|
|
parent::paintGroupStart($test_name, $size);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Signals/Paints the end of a TestSuite. All test cases have run
|
|
|
|
* and timers are stopped.
|
|
|
|
*
|
|
|
|
* @param string $test_name Name of the test that is being run.
|
|
|
|
* @return void
|
|
|
|
*/
|
2010-04-15 02:56:51 +00:00
|
|
|
public function paintGroupEnd($test_name) {
|
2010-04-15 16:58:28 +00:00
|
|
|
$this->_timeEnd = microtime(true);
|
2010-01-06 01:29:08 +00:00
|
|
|
$this->_timeDuration = $this->_timeEnd - $this->_timeStart;
|
|
|
|
parent::paintGroupEnd($test_name);
|
|
|
|
}
|
|
|
|
|
2010-01-10 18:24:41 +00:00
|
|
|
/**
|
|
|
|
* Paints the beginning of a test method being run. This is used
|
|
|
|
* to start/resume the code coverage tool.
|
|
|
|
*
|
|
|
|
* @param string $method The method name being run.
|
|
|
|
* @return void
|
|
|
|
*/
|
2010-04-15 02:56:51 +00:00
|
|
|
public function paintMethodStart($method) {
|
2010-01-10 18:24:41 +00:00
|
|
|
parent::paintMethodStart($method);
|
|
|
|
if (!empty($this->params['codeCoverage'])) {
|
|
|
|
CodeCoverageManager::start();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Paints the end of a test method being run. This is used
|
|
|
|
* to pause the collection of code coverage if its being used.
|
|
|
|
*
|
|
|
|
* @param string $method The name of the method being run.
|
|
|
|
* @return void
|
|
|
|
*/
|
2010-04-15 02:56:51 +00:00
|
|
|
public function paintMethodEnd($method) {
|
2010-01-10 18:24:41 +00:00
|
|
|
parent::paintMethodEnd($method);
|
|
|
|
if (!empty($this->params['codeCoverage'])) {
|
|
|
|
CodeCoverageManager::stop();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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-01-09 15:55:58 +00:00
|
|
|
$testList = TestManager::getTestCaseList();
|
|
|
|
return $testList;
|
2010-01-06 03:52:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Retrieves a list of group test cases from the active Manager class
|
|
|
|
* displaying it in the correct format for the reporter subclass.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2010-04-15 02:56:51 +00:00
|
|
|
public function groupTestList() {
|
2010-01-09 15:55:58 +00:00
|
|
|
$testList = TestManager::getGroupTestList();
|
|
|
|
return $testList;
|
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) {
|
|
|
|
$this->paintException($e);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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) {
|
|
|
|
$this->paintFail($e);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Incomplete test.
|
|
|
|
*
|
|
|
|
* @param PHPUnit_Framework_Test $test
|
|
|
|
* @param Exception $e
|
|
|
|
* @param float $time
|
|
|
|
*/
|
|
|
|
public function addIncompleteTest(PHPUnit_Framework_Test $test, Exception $e, $time) {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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
|
|
|
}
|