2010-01-05 20:29:08 -05:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* CakeBaseReporter contains common functionality to all cake test suite reporters.
|
|
|
|
*
|
2017-06-11 00:15:34 +02:00
|
|
|
* CakePHP(tm) Tests <https://book.cakephp.org/2.0/en/development/testing.html>
|
2017-06-11 00:10:52 +02:00
|
|
|
* Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
|
2010-01-05 20:29:08 -05:00
|
|
|
*
|
2010-10-03 12:31:21 -04:00
|
|
|
* Licensed under The MIT License
|
2013-02-08 21:22:51 +09:00
|
|
|
* For full copyright and license information, please see the LICENSE.txt
|
2010-10-03 12:31:21 -04:00
|
|
|
* Redistributions of files must retain the above copyright notice
|
2010-01-05 20:29:08 -05:00
|
|
|
*
|
2017-06-11 00:10:52 +02:00
|
|
|
* @copyright Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
|
2017-06-10 23:33:55 +02:00
|
|
|
* @link https://cakephp.org CakePHP(tm) Project
|
2010-01-05 20:29:08 -05:00
|
|
|
* @since CakePHP(tm) v 1.3
|
2017-06-11 00:23:14 +02:00
|
|
|
* @license https://opensource.org/licenses/mit-license.php MIT License
|
2010-01-05 20:29:08 -05:00
|
|
|
*/
|
2013-05-31 00:11:14 +02:00
|
|
|
|
2014-11-24 16:36:43 -05:00
|
|
|
if (!defined('__PHPUNIT_PHAR__')) {
|
2014-11-24 14:51:36 -05:00
|
|
|
require_once 'PHPUnit/TextUI/ResultPrinter.php';
|
|
|
|
}
|
2010-01-05 20:29:08 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
* CakeBaseReporter contains common reporting features used in the CakePHP Test suite
|
|
|
|
*
|
2011-07-26 01:46:14 -04:30
|
|
|
* @package Cake.TestSuite.Reporter
|
2010-01-05 20:29:08 -05:00
|
|
|
*/
|
2011-02-12 18:39:25 -05:00
|
|
|
class CakeBaseReporter extends PHPUnit_TextUI_ResultPrinter {
|
2010-01-05 20:29:08 -05:00
|
|
|
|
2012-11-29 04:00:47 +05:30
|
|
|
/**
|
|
|
|
* Headers sent
|
|
|
|
*
|
2014-07-03 15:36:42 +02:00
|
|
|
* @var bool
|
2012-11-29 04:00:47 +05:30
|
|
|
*/
|
2011-02-12 23:07:39 -05:00
|
|
|
protected $_headerSent = false;
|
2010-01-05 20:29:08 -05:00
|
|
|
|
2010-01-09 11:20:47 -05:00
|
|
|
/**
|
2012-12-22 23:48:15 +01:00
|
|
|
* Array of request parameters. Usually parsed GET params.
|
2010-01-09 11:20:47 -05:00
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
*/
|
2010-04-04 17:14:00 +10:00
|
|
|
public $params = array();
|
2010-01-09 11:20:47 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Character set for the output of test reporting.
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
2010-04-04 16:36:12 +10:00
|
|
|
protected $_characterSet;
|
2010-01-09 11:20:47 -05: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?
|
2011-12-19 23:13:46 -05:00
|
|
|
* - core - Core test being run.
|
2010-01-09 11:20:47 -05:00
|
|
|
* - case - The case being run
|
2010-01-10 13:24:41 -05:00
|
|
|
* - codeCoverage - Whether the case/group being run is being code covered.
|
2011-02-22 01:21:26 +05:30
|
|
|
*
|
2010-01-09 11:20:47 -05: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.
|
|
|
|
*/
|
2012-02-16 23:13:12 -08:00
|
|
|
public function __construct($charset = 'utf-8', $params = array()) {
|
2010-01-10 12:48:11 -05:00
|
|
|
if (!$charset) {
|
|
|
|
$charset = 'utf-8';
|
|
|
|
}
|
2010-01-09 11:20:47 -05:00
|
|
|
$this->_characterSet = $charset;
|
|
|
|
$this->params = $params;
|
|
|
|
}
|
|
|
|
|
2010-01-05 22:52:25 -05: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-14 22:56:51 -04:00
|
|
|
public function testCaseList() {
|
2011-02-12 22:49:15 -05:00
|
|
|
$testList = CakeTestLoader::generateTestList($this->params);
|
2010-01-09 10:55:58 -05:00
|
|
|
return $testList;
|
2010-01-05 22:52:25 -05:00
|
|
|
}
|
|
|
|
|
2010-01-06 22:52:04 -05:00
|
|
|
/**
|
2010-01-09 11:20:47 -05:00
|
|
|
* Paints the start of the response from the test suite.
|
2010-01-06 22:52:04 -05:00
|
|
|
* Used to paint things like head elements in an html page.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2010-04-14 22:56:51 -04:00
|
|
|
public function paintDocumentStart() {
|
2010-01-06 22:52:04 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2010-01-09 11:20:47 -05:00
|
|
|
* Paints the end of the response from the test suite.
|
2010-01-06 22:52:04 -05:00
|
|
|
* Used to paint things like </body> in an html page.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2010-04-14 22:56:51 -04:00
|
|
|
public function paintDocumentEnd() {
|
2010-01-09 11:20:47 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Paint a list of test sets, core, app, and plugin test sets
|
|
|
|
* available.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2010-04-14 22:56:51 -04:00
|
|
|
public function paintTestMenu() {
|
2010-01-05 22:52:25 -05:00
|
|
|
}
|
|
|
|
|
2010-01-09 11:20:47 -05:00
|
|
|
/**
|
|
|
|
* Get the baseUrl if one is available.
|
|
|
|
*
|
2013-10-07 23:17:58 -04:00
|
|
|
* @return string The base URL for the request.
|
2010-01-09 11:20:47 -05:00
|
|
|
*/
|
2010-04-14 22:56:51 -04:00
|
|
|
public function baseUrl() {
|
2010-01-09 11:20:47 -05:00
|
|
|
if (!empty($_SERVER['PHP_SELF'])) {
|
|
|
|
return $_SERVER['PHP_SELF'];
|
|
|
|
}
|
|
|
|
return '';
|
|
|
|
}
|
|
|
|
|
2012-11-29 04:00:47 +05:30
|
|
|
/**
|
|
|
|
* Print result
|
|
|
|
*
|
2014-06-06 13:57:48 -04:00
|
|
|
* @param PHPUnit_Framework_TestResult $result The result object
|
2014-04-02 03:09:42 +02:00
|
|
|
* @return void
|
2012-11-29 04:00:47 +05:30
|
|
|
*/
|
2011-02-12 18:39:25 -05:00
|
|
|
public function printResult(PHPUnit_Framework_TestResult $result) {
|
|
|
|
$this->paintFooter($result);
|
|
|
|
}
|
|
|
|
|
2012-11-29 04:00:47 +05:30
|
|
|
/**
|
|
|
|
* Paint result
|
|
|
|
*
|
2014-06-06 13:57:48 -04:00
|
|
|
* @param PHPUnit_Framework_TestResult $result The result object
|
2014-04-02 03:09:42 +02:00
|
|
|
* @return void
|
2012-11-29 04:00:47 +05:30
|
|
|
*/
|
2010-05-13 00:18:22 -04:00
|
|
|
public function paintResult(PHPUnit_Framework_TestResult $result) {
|
|
|
|
$this->paintFooter($result);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2012-03-04 21:51:44 -05:00
|
|
|
* An error occurred.
|
|
|
|
*
|
2014-06-27 22:58:34 -04:00
|
|
|
* @param PHPUnit_Framework_Test $test The test to add an error for.
|
|
|
|
* @param Exception $e The exception object to add.
|
|
|
|
* @param float $time The current time.
|
2014-04-02 03:09:42 +02:00
|
|
|
* @return void
|
2012-03-04 21:51:44 -05:00
|
|
|
*/
|
2010-05-13 00:18:22 -04:00
|
|
|
public function addError(PHPUnit_Framework_Test $test, Exception $e, $time) {
|
2010-07-14 22:58:42 -04:00
|
|
|
$this->paintException($e, $test);
|
2010-05-13 00:18:22 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2012-03-04 21:51:44 -05:00
|
|
|
* A failure occurred.
|
|
|
|
*
|
2014-06-27 22:58:34 -04:00
|
|
|
* @param PHPUnit_Framework_Test $test The test that failed
|
|
|
|
* @param PHPUnit_Framework_AssertionFailedError $e The assertion that failed.
|
|
|
|
* @param float $time The current time.
|
2014-04-02 03:09:42 +02:00
|
|
|
* @return void
|
2012-03-04 21:51:44 -05:00
|
|
|
*/
|
2010-05-13 00:18:22 -04:00
|
|
|
public function addFailure(PHPUnit_Framework_Test $test, PHPUnit_Framework_AssertionFailedError $e, $time) {
|
2010-07-14 22:58:42 -04:00
|
|
|
$this->paintFail($e, $test);
|
2010-05-13 00:18:22 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2012-03-04 21:51:44 -05:00
|
|
|
* Incomplete test.
|
|
|
|
*
|
2014-06-27 22:58:34 -04:00
|
|
|
* @param PHPUnit_Framework_Test $test The test that was incomplete.
|
|
|
|
* @param Exception $e The incomplete exception
|
|
|
|
* @param float $time The current time.
|
2014-04-02 03:09:42 +02:00
|
|
|
* @return void
|
2012-03-04 21:51:44 -05:00
|
|
|
*/
|
2010-05-13 00:18:22 -04:00
|
|
|
public function addIncompleteTest(PHPUnit_Framework_Test $test, Exception $e, $time) {
|
2010-06-12 18:55:27 -04:00
|
|
|
$this->paintSkip($e, $test);
|
2010-05-13 00:18:22 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2012-03-04 21:51:44 -05:00
|
|
|
* Skipped test.
|
|
|
|
*
|
2014-06-27 22:58:34 -04:00
|
|
|
* @param PHPUnit_Framework_Test $test The test that failed.
|
|
|
|
* @param Exception $e The skip object.
|
|
|
|
* @param float $time The current time.
|
2014-04-02 03:09:42 +02:00
|
|
|
* @return void
|
2012-03-04 21:51:44 -05:00
|
|
|
*/
|
2010-05-13 00:18:22 -04:00
|
|
|
public function addSkippedTest(PHPUnit_Framework_Test $test, Exception $e, $time) {
|
2010-05-17 22:31:22 -04:30
|
|
|
$this->paintSkip($e, $test);
|
2010-05-13 00:18:22 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A test suite started.
|
|
|
|
*
|
2014-06-27 22:58:34 -04:00
|
|
|
* @param PHPUnit_Framework_TestSuite $suite The suite to start
|
2014-04-02 03:09:42 +02:00
|
|
|
* @return void
|
2010-05-13 00:18:22 -04:00
|
|
|
*/
|
|
|
|
public function startTestSuite(PHPUnit_Framework_TestSuite $suite) {
|
2011-02-12 23:07:39 -05:00
|
|
|
if (!$this->_headerSent) {
|
|
|
|
echo $this->paintHeader();
|
|
|
|
}
|
2011-03-20 16:35:43 +01:00
|
|
|
echo __d('cake_dev', 'Running %s', $suite->getName()) . "\n";
|
2010-05-13 00:18:22 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A test suite ended.
|
|
|
|
*
|
2014-06-27 22:58:34 -04:00
|
|
|
* @param PHPUnit_Framework_TestSuite $suite The suite that ended.
|
2014-04-02 03:09:42 +02:00
|
|
|
* @return void
|
2010-05-13 00:18:22 -04:00
|
|
|
*/
|
|
|
|
public function endTestSuite(PHPUnit_Framework_TestSuite $suite) {
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A test started.
|
|
|
|
*
|
2014-06-27 22:58:34 -04:00
|
|
|
* @param PHPUnit_Framework_Test $test The test that started.
|
2014-04-02 03:09:42 +02:00
|
|
|
* @return void
|
2010-05-13 00:18:22 -04:00
|
|
|
*/
|
|
|
|
public function startTest(PHPUnit_Framework_Test $test) {
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A test ended.
|
|
|
|
*
|
2014-06-27 22:58:34 -04:00
|
|
|
* @param PHPUnit_Framework_Test $test The test that ended
|
|
|
|
* @param float $time The current time.
|
2014-04-02 03:09:42 +02:00
|
|
|
* @return void
|
2010-05-13 00:18:22 -04:00
|
|
|
*/
|
|
|
|
public function endTest(PHPUnit_Framework_Test $test, $time) {
|
|
|
|
$this->numAssertions += $test->getNumAssertions();
|
2012-07-13 22:58:07 -04:00
|
|
|
if ($test->hasFailed()) {
|
|
|
|
return;
|
|
|
|
}
|
2010-05-13 00:18:22 -04:00
|
|
|
$this->paintPass($test, $time);
|
|
|
|
}
|
|
|
|
|
2011-11-02 23:25:09 -04:00
|
|
|
}
|