2010-01-06 01:29:08 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* CakeBaseReporter contains common functionality to all cake test suite reporters.
|
|
|
|
*
|
2017-06-10 22:15:34 +00:00
|
|
|
* CakePHP(tm) Tests <https://book.cakephp.org/2.0/en/development/testing.html>
|
2017-06-10 22:10:52 +00:00
|
|
|
* Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
|
2010-01-06 01:29:08 +00:00
|
|
|
*
|
2010-10-03 16:31:21 +00:00
|
|
|
* Licensed under The MIT License
|
2013-02-08 12:22:51 +00:00
|
|
|
* For full copyright and license information, please see the LICENSE.txt
|
2010-10-03 16:31:21 +00:00
|
|
|
* Redistributions of files must retain the above copyright notice
|
2010-01-06 01:29:08 +00:00
|
|
|
*
|
2017-06-10 22:10:52 +00:00
|
|
|
* @copyright Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
|
2017-06-10 21:33:55 +00:00
|
|
|
* @link https://cakephp.org CakePHP(tm) Project
|
2010-01-06 01:29:08 +00:00
|
|
|
* @since CakePHP(tm) v 1.3
|
2017-06-10 22:23:14 +00:00
|
|
|
* @license https://opensource.org/licenses/mit-license.php MIT License
|
2010-01-06 01:29:08 +00:00
|
|
|
*/
|
2013-05-30 22:11:14 +00:00
|
|
|
|
2017-03-10 22:24:41 +00:00
|
|
|
if (!class_exists('PHPUnit_TextUI_ResultPrinter')) {
|
2014-11-24 19:51:36 +00:00
|
|
|
require_once 'PHPUnit/TextUI/ResultPrinter.php';
|
|
|
|
}
|
2010-01-06 01:29:08 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* CakeBaseReporter contains common reporting features used in the CakePHP Test suite
|
|
|
|
*
|
2011-07-26 06:16:14 +00:00
|
|
|
* @package Cake.TestSuite.Reporter
|
2010-01-06 01:29:08 +00:00
|
|
|
*/
|
2011-02-12 23:39:25 +00:00
|
|
|
class CakeBaseReporter extends PHPUnit_TextUI_ResultPrinter {
|
2010-01-06 01:29:08 +00:00
|
|
|
|
2012-11-28 22:30:47 +00:00
|
|
|
/**
|
|
|
|
* Headers sent
|
|
|
|
*
|
2014-07-03 13:36:42 +00:00
|
|
|
* @var bool
|
2012-11-28 22:30:47 +00:00
|
|
|
*/
|
2011-02-13 04:07:39 +00:00
|
|
|
protected $_headerSent = false;
|
2010-01-06 01:29:08 +00:00
|
|
|
|
2010-01-09 16:20:47 +00:00
|
|
|
/**
|
2012-12-22 22:48:15 +00:00
|
|
|
* Array of request parameters. Usually parsed GET params.
|
2010-01-09 16:20:47 +00:00
|
|
|
*
|
|
|
|
* @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
|
|
|
|
*/
|
2010-04-04 06:36:12 +00:00
|
|
|
protected $_characterSet;
|
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?
|
2011-12-20 04:13:46 +00:00
|
|
|
* - core - Core test being run.
|
2010-01-09 16:20:47 +00:00
|
|
|
* - case - The case being run
|
2010-01-10 18:24:41 +00:00
|
|
|
* - codeCoverage - Whether the case/group being run is being code covered.
|
2011-02-21 19:51:26 +00:00
|
|
|
*
|
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.
|
|
|
|
*/
|
2012-02-17 07:13:12 +00:00
|
|
|
public 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() {
|
2011-02-13 03:49:15 +00:00
|
|
|
$testList = CakeTestLoader::generateTestList($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.
|
|
|
|
*
|
2013-10-08 03:17:58 +00:00
|
|
|
* @return string The base URL for the request.
|
2010-01-09 16:20:47 +00:00
|
|
|
*/
|
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 '';
|
|
|
|
}
|
|
|
|
|
2012-11-28 22:30:47 +00:00
|
|
|
/**
|
|
|
|
* Print result
|
|
|
|
*
|
2014-06-06 17:57:48 +00:00
|
|
|
* @param PHPUnit_Framework_TestResult $result The result object
|
2014-04-02 01:09:42 +00:00
|
|
|
* @return void
|
2012-11-28 22:30:47 +00:00
|
|
|
*/
|
2011-02-12 23:39:25 +00:00
|
|
|
public function printResult(PHPUnit_Framework_TestResult $result) {
|
|
|
|
$this->paintFooter($result);
|
|
|
|
}
|
|
|
|
|
2012-11-28 22:30:47 +00:00
|
|
|
/**
|
|
|
|
* Paint result
|
|
|
|
*
|
2014-06-06 17:57:48 +00:00
|
|
|
* @param PHPUnit_Framework_TestResult $result The result object
|
2014-04-02 01:09:42 +00:00
|
|
|
* @return void
|
2012-11-28 22:30:47 +00:00
|
|
|
*/
|
2010-05-13 04:18:22 +00:00
|
|
|
public function paintResult(PHPUnit_Framework_TestResult $result) {
|
|
|
|
$this->paintFooter($result);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2012-03-05 02:51:44 +00:00
|
|
|
* An error occurred.
|
|
|
|
*
|
2014-06-28 02:58:34 +00: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 01:09:42 +00:00
|
|
|
* @return void
|
2012-03-05 02:51:44 +00:00
|
|
|
*/
|
2010-05-13 04:18:22 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2012-03-05 02:51:44 +00:00
|
|
|
* A failure occurred.
|
|
|
|
*
|
2014-06-28 02:58:34 +00: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 01:09:42 +00:00
|
|
|
* @return void
|
2012-03-05 02:51:44 +00:00
|
|
|
*/
|
2010-05-13 04:18:22 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2012-03-05 02:51:44 +00:00
|
|
|
* Incomplete test.
|
|
|
|
*
|
2014-06-28 02:58:34 +00: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 01:09:42 +00:00
|
|
|
* @return void
|
2012-03-05 02:51:44 +00:00
|
|
|
*/
|
2010-05-13 04:18:22 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2012-03-05 02:51:44 +00:00
|
|
|
* Skipped test.
|
|
|
|
*
|
2014-06-28 02:58:34 +00: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 01:09:42 +00:00
|
|
|
* @return void
|
2012-03-05 02:51:44 +00:00
|
|
|
*/
|
2010-05-13 04:18:22 +00:00
|
|
|
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.
|
|
|
|
*
|
2014-06-28 02:58:34 +00:00
|
|
|
* @param PHPUnit_Framework_TestSuite $suite The suite to start
|
2014-04-02 01:09:42 +00:00
|
|
|
* @return void
|
2010-05-13 04:18:22 +00:00
|
|
|
*/
|
|
|
|
public function startTestSuite(PHPUnit_Framework_TestSuite $suite) {
|
2011-02-13 04:07:39 +00:00
|
|
|
if (!$this->_headerSent) {
|
|
|
|
echo $this->paintHeader();
|
|
|
|
}
|
2011-03-20 15:35:43 +00:00
|
|
|
echo __d('cake_dev', 'Running %s', $suite->getName()) . "\n";
|
2010-05-13 04:18:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A test suite ended.
|
|
|
|
*
|
2014-06-28 02:58:34 +00:00
|
|
|
* @param PHPUnit_Framework_TestSuite $suite The suite that ended.
|
2014-04-02 01:09:42 +00:00
|
|
|
* @return void
|
2010-05-13 04:18:22 +00:00
|
|
|
*/
|
|
|
|
public function endTestSuite(PHPUnit_Framework_TestSuite $suite) {
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A test started.
|
|
|
|
*
|
2014-06-28 02:58:34 +00:00
|
|
|
* @param PHPUnit_Framework_Test $test The test that started.
|
2014-04-02 01:09:42 +00:00
|
|
|
* @return void
|
2010-05-13 04:18:22 +00:00
|
|
|
*/
|
|
|
|
public function startTest(PHPUnit_Framework_Test $test) {
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A test ended.
|
|
|
|
*
|
2014-06-28 02:58:34 +00:00
|
|
|
* @param PHPUnit_Framework_Test $test The test that ended
|
|
|
|
* @param float $time The current time.
|
2014-04-02 01:09:42 +00:00
|
|
|
* @return void
|
2010-05-13 04:18:22 +00:00
|
|
|
*/
|
|
|
|
public function endTest(PHPUnit_Framework_Test $test, $time) {
|
|
|
|
$this->numAssertions += $test->getNumAssertions();
|
2012-07-14 02:58:07 +00:00
|
|
|
if ($test->hasFailed()) {
|
|
|
|
return;
|
|
|
|
}
|
2010-05-13 04:18:22 +00:00
|
|
|
$this->paintPass($test, $time);
|
|
|
|
}
|
|
|
|
|
2011-11-03 03:25:09 +00:00
|
|
|
}
|