PageRenderTime 36ms CodeModel.GetById 14ms RepoModel.GetById 1ms app.codeStats 0ms

/cake/tests/lib/reporter/cake_text_reporter.php

https://github.com/cgajardo/repositorium
PHP | 198 lines | 96 code | 15 blank | 87 comment | 10 complexity | 7f35251b51614b203ef05fce51b6b22d MD5 | raw file
  1. <?php
  2. /**
  3. * CakeTextReporter contains reporting features used for plain text based output
  4. *
  5. * PHP versions 4 and 5
  6. *
  7. * CakePHP(tm) Tests <http://book.cakephp.org/view/1196/Testing>
  8. * Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
  9. *
  10. * Licensed under The Open Group Test Suite License
  11. * Redistributions of files must retain the above copyright notice.
  12. *
  13. * @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
  14. * @link http://cakephp.org CakePHP(tm) Project
  15. * @package cake
  16. * @subpackage cake.tests.libs.reporter
  17. * @since CakePHP(tm) v 1.3
  18. * @license http://www.opensource.org/licenses/opengroup.php The Open Group Test Suite License
  19. */
  20. include_once dirname(__FILE__) . DS . 'cake_base_reporter.php';
  21. /**
  22. * CakeTextReporter contains reporting features used for plain text based output
  23. *
  24. * @package cake
  25. * @subpackage cake.tests.lib
  26. */
  27. class CakeTextReporter extends CakeBaseReporter {
  28. /**
  29. * Sets the text/plain header if the test is not a CLI test.
  30. *
  31. * @return void
  32. */
  33. function paintDocumentStart() {
  34. if (!SimpleReporter::inCli()) {
  35. header('Content-type: text/plain');
  36. }
  37. }
  38. /**
  39. * Paints the end of the test with a summary of
  40. * the passes and failures.
  41. *
  42. * @param string $test_name Name class of test.
  43. * @return void
  44. * @access public
  45. */
  46. function paintFooter($test_name) {
  47. if ($this->getFailCount() + $this->getExceptionCount() == 0) {
  48. echo "OK\n";
  49. } else {
  50. echo "FAILURES!!!\n";
  51. }
  52. echo "Test cases run: " . $this->getTestCaseProgress() .
  53. "/" . $this->getTestCaseCount() .
  54. ", Passes: " . $this->getPassCount() .
  55. ", Failures: " . $this->getFailCount() .
  56. ", Exceptions: " . $this->getExceptionCount() . "\n";
  57. echo 'Time taken by tests (in seconds): ' . $this->_timeDuration . "\n";
  58. if (function_exists('memory_get_peak_usage')) {
  59. echo 'Peak memory use: (in bytes): ' . number_format(memory_get_peak_usage()) . "\n";
  60. }
  61. if (
  62. isset($this->params['codeCoverage']) &&
  63. $this->params['codeCoverage'] &&
  64. class_exists('CodeCoverageManager')
  65. ) {
  66. CodeCoverageManager::report();
  67. }
  68. }
  69. /**
  70. * Paints the title only.
  71. *
  72. * @param string $test_name Name class of test.
  73. * @return void
  74. * @access public
  75. */
  76. function paintHeader($test_name) {
  77. $this->paintDocumentStart();
  78. echo "$test_name\n";
  79. flush();
  80. }
  81. /**
  82. * Paints the test failure as a stack trace.
  83. *
  84. * @param string $message Failure message displayed in
  85. * the context of the other tests.
  86. * @return void
  87. * @access public
  88. */
  89. function paintFail($message) {
  90. parent::paintFail($message);
  91. echo $this->getFailCount() . ") $message\n";
  92. $breadcrumb = $this->getTestList();
  93. array_shift($breadcrumb);
  94. echo "\tin " . implode("\n\tin ", array_reverse($breadcrumb));
  95. echo "\n";
  96. }
  97. /**
  98. * Paints a PHP error.
  99. *
  100. * @param string $message Message to be shown.
  101. * @return void
  102. * @access public
  103. */
  104. function paintError($message) {
  105. parent::paintError($message);
  106. echo "Exception " . $this->getExceptionCount() . "!\n$message\n";
  107. $breadcrumb = $this->getTestList();
  108. array_shift($breadcrumb);
  109. echo "\tin " . implode("\n\tin ", array_reverse($breadcrumb));
  110. echo "\n";
  111. }
  112. /**
  113. * Paints a PHP exception.
  114. *
  115. * @param Exception $exception Exception to describe.
  116. * @return void
  117. * @access public
  118. */
  119. function paintException($exception) {
  120. parent::paintException($exception);
  121. $message = 'Unexpected exception of type [' . get_class($exception) .
  122. '] with message ['. $exception->getMessage() .
  123. '] in ['. $exception->getFile() .
  124. ' line ' . $exception->getLine() . ']';
  125. echo "Exception " . $this->getExceptionCount() . "!\n$message\n";
  126. $breadcrumb = $this->getTestList();
  127. array_shift($breadcrumb);
  128. echo "\tin " . implode("\n\tin ", array_reverse($breadcrumb));
  129. echo "\n";
  130. }
  131. /**
  132. * Prints the message for skipping tests.
  133. *
  134. * @param string $message Text of skip condition.
  135. * @return void
  136. * @access public
  137. */
  138. function paintSkip($message) {
  139. parent::paintSkip($message);
  140. echo "Skip: $message\n";
  141. }
  142. /**
  143. * Paints formatted text such as dumped variables.
  144. *
  145. * @param string $message Text to show.
  146. * @return void
  147. * @access public
  148. */
  149. function paintFormattedMessage($message) {
  150. echo "$message\n";
  151. flush();
  152. }
  153. /**
  154. * Generate a test case list in plain text.
  155. * Creates as series of url's for tests that can be run.
  156. * One case per line.
  157. *
  158. * @return void
  159. */
  160. function testCaseList() {
  161. $testCases = parent::testCaseList();
  162. $app = $this->params['app'];
  163. $plugin = $this->params['plugin'];
  164. $buffer = "Core Test Cases:\n";
  165. $urlExtra = '';
  166. if ($app) {
  167. $buffer = "App Test Cases:\n";
  168. $urlExtra = '&app=true';
  169. } elseif ($plugin) {
  170. $buffer = Inflector::humanize($plugin) . " Test Cases:\n";
  171. $urlExtra = '&plugin=' . $plugin;
  172. }
  173. if (1 > count($testCases)) {
  174. $buffer .= "EMPTY";
  175. echo $buffer;
  176. }
  177. foreach ($testCases as $testCaseFile => $testCase) {
  178. $buffer .= $_SERVER['SERVER_NAME'] . $this->baseUrl() ."?case=" . $testCase . "&output=text"."\n";
  179. }
  180. $buffer .= "\n";
  181. echo $buffer;
  182. }
  183. }