CakeBaseReporter.php 5.0 KB

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