CakeBaseReporter.php 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  1. <?php
  2. /**
  3. * CakeBaseReporter contains common functionality to all cake test suite reporters.
  4. *
  5. * CakePHP(tm) Tests <http://book.cakephp.org/2.0/en/development/testing.html>
  6. * Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
  7. *
  8. * Licensed under The MIT License
  9. * For full copyright and license information, please see the LICENSE.txt
  10. * Redistributions of files must retain the above copyright notice
  11. *
  12. * @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
  13. * @link http://cakephp.org CakePHP(tm) Project
  14. * @since CakePHP(tm) v 1.3
  15. * @license http://www.opensource.org/licenses/mit-license.php MIT License
  16. */
  17. require_once 'PHPUnit/TextUI/ResultPrinter.php';
  18. /**
  19. * CakeBaseReporter contains common reporting features used in the CakePHP Test suite
  20. *
  21. * @package Cake.TestSuite.Reporter
  22. */
  23. class CakeBaseReporter extends PHPUnit_TextUI_ResultPrinter {
  24. /**
  25. * Headers sent
  26. *
  27. * @var boolean
  28. */
  29. protected $_headerSent = false;
  30. /**
  31. * Array of request parameters. Usually parsed GET params.
  32. *
  33. * @var array
  34. */
  35. public $params = array();
  36. /**
  37. * Character set for the output of test reporting.
  38. *
  39. * @var string
  40. */
  41. protected $_characterSet;
  42. /**
  43. * Does nothing yet. The first output will
  44. * be sent on the first test start.
  45. *
  46. * ### Params
  47. *
  48. * - show_passes - Should passes be shown
  49. * - plugin - Plugin test being run?
  50. * - core - Core test being run.
  51. * - case - The case being run
  52. * - codeCoverage - Whether the case/group being run is being code covered.
  53. *
  54. * @param string $charset The character set to output with. Defaults to UTF-8
  55. * @param array $params Array of request parameters the reporter should use. See above.
  56. */
  57. public function __construct($charset = 'utf-8', $params = array()) {
  58. if (!$charset) {
  59. $charset = 'utf-8';
  60. }
  61. $this->_characterSet = $charset;
  62. $this->params = $params;
  63. }
  64. /**
  65. * Retrieves a list of test cases from the active Manager class,
  66. * displaying it in the correct format for the reporter subclass
  67. *
  68. * @return mixed
  69. */
  70. public function testCaseList() {
  71. $testList = CakeTestLoader::generateTestList($this->params);
  72. return $testList;
  73. }
  74. /**
  75. * Paints the start of the response from the test suite.
  76. * Used to paint things like head elements in an html page.
  77. *
  78. * @return void
  79. */
  80. public function paintDocumentStart() {
  81. }
  82. /**
  83. * Paints the end of the response from the test suite.
  84. * Used to paint things like </body> in an html page.
  85. *
  86. * @return void
  87. */
  88. public function paintDocumentEnd() {
  89. }
  90. /**
  91. * Paint a list of test sets, core, app, and plugin test sets
  92. * available.
  93. *
  94. * @return void
  95. */
  96. public function paintTestMenu() {
  97. }
  98. /**
  99. * Get the baseUrl if one is available.
  100. *
  101. * @return string The base URL for the request.
  102. */
  103. public function baseUrl() {
  104. if (!empty($_SERVER['PHP_SELF'])) {
  105. return $_SERVER['PHP_SELF'];
  106. }
  107. return '';
  108. }
  109. /**
  110. * Print result
  111. *
  112. * @param PHPUnit_Framework_TestResult $result The result object
  113. * @return void
  114. */
  115. public function printResult(PHPUnit_Framework_TestResult $result) {
  116. $this->paintFooter($result);
  117. }
  118. /**
  119. * Paint result
  120. *
  121. * @param PHPUnit_Framework_TestResult $result The result object
  122. * @return void
  123. */
  124. public function paintResult(PHPUnit_Framework_TestResult $result) {
  125. $this->paintFooter($result);
  126. }
  127. /**
  128. * An error occurred.
  129. *
  130. * @param PHPUnit_Framework_Test $test The test to add an error for.
  131. * @param Exception $e The exception object to add.
  132. * @param float $time The current time.
  133. * @return void
  134. */
  135. public function addError(PHPUnit_Framework_Test $test, Exception $e, $time) {
  136. $this->paintException($e, $test);
  137. }
  138. /**
  139. * A failure occurred.
  140. *
  141. * @param PHPUnit_Framework_Test $test The test that failed
  142. * @param PHPUnit_Framework_AssertionFailedError $e The assertion that failed.
  143. * @param float $time The current time.
  144. * @return void
  145. */
  146. public function addFailure(PHPUnit_Framework_Test $test, PHPUnit_Framework_AssertionFailedError $e, $time) {
  147. $this->paintFail($e, $test);
  148. }
  149. /**
  150. * Incomplete test.
  151. *
  152. * @param PHPUnit_Framework_Test $test The test that was incomplete.
  153. * @param Exception $e The incomplete exception
  154. * @param float $time The current time.
  155. * @return void
  156. */
  157. public function addIncompleteTest(PHPUnit_Framework_Test $test, Exception $e, $time) {
  158. $this->paintSkip($e, $test);
  159. }
  160. /**
  161. * Skipped test.
  162. *
  163. * @param PHPUnit_Framework_Test $test The test that failed.
  164. * @param Exception $e The skip object.
  165. * @param float $time The current time.
  166. * @return void
  167. */
  168. public function addSkippedTest(PHPUnit_Framework_Test $test, Exception $e, $time) {
  169. $this->paintSkip($e, $test);
  170. }
  171. /**
  172. * A test suite started.
  173. *
  174. * @param PHPUnit_Framework_TestSuite $suite The suite to start
  175. * @return void
  176. */
  177. public function startTestSuite(PHPUnit_Framework_TestSuite $suite) {
  178. if (!$this->_headerSent) {
  179. echo $this->paintHeader();
  180. }
  181. echo __d('cake_dev', 'Running %s', $suite->getName()) . "\n";
  182. }
  183. /**
  184. * A test suite ended.
  185. *
  186. * @param PHPUnit_Framework_TestSuite $suite The suite that ended.
  187. * @return void
  188. */
  189. public function endTestSuite(PHPUnit_Framework_TestSuite $suite) {
  190. }
  191. /**
  192. * A test started.
  193. *
  194. * @param PHPUnit_Framework_Test $test The test that started.
  195. * @return void
  196. */
  197. public function startTest(PHPUnit_Framework_Test $test) {
  198. }
  199. /**
  200. * A test ended.
  201. *
  202. * @param PHPUnit_Framework_Test $test The test that ended
  203. * @param float $time The current time.
  204. * @return void
  205. */
  206. public function endTest(PHPUnit_Framework_Test $test, $time) {
  207. $this->numAssertions += $test->getNumAssertions();
  208. if ($test->hasFailed()) {
  209. return;
  210. }
  211. $this->paintPass($test, $time);
  212. }
  213. }