PageRenderTime 46ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/lib/Cake/TestSuite/Reporter/CakeTextReporter.php

https://bitbucket.org/udeshika/fake_twitter
PHP | 187 lines | 85 code | 20 blank | 82 comment | 8 complexity | d9dbc6bbe3b066da81dee8ca1bfe7e70 MD5 | raw file
  1. <?php
  2. /**
  3. * CakeTextReporter contains reporting features used for plain text based output
  4. *
  5. * PHP 5
  6. *
  7. * CakePHP(tm) Tests <http://book.cakephp.org/view/1196/Testing>
  8. * Copyright 2005-2011, 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-2011, 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. App::uses('CakeBaseReporter', 'TestSuite/Reporter');
  19. App::uses('TextCoverageReport', 'TestSuite/Coverage');
  20. /**
  21. * CakeTextReporter contains reporting features used for plain text based output
  22. *
  23. * @package Cake.TestSuite.Reporter
  24. */
  25. class CakeTextReporter extends CakeBaseReporter {
  26. /**
  27. * Sets the text/plain header if the test is not a CLI test.
  28. *
  29. * @return void
  30. */
  31. public function paintDocumentStart() {
  32. if (!headers_sent()) {
  33. header('Content-type: text/plain');
  34. }
  35. }
  36. /**
  37. * Paints a pass
  38. *
  39. * @return void
  40. */
  41. public function paintPass() {
  42. echo '.';
  43. }
  44. /**
  45. * Paints a failing test.
  46. *
  47. * @param $message PHPUnit_Framework_AssertionFailedError $message Failure object displayed in
  48. * the context of the other tests.
  49. * @return void
  50. */
  51. public function paintFail($message) {
  52. $context = $message->getTrace();
  53. $realContext = $context[3];
  54. $context = $context[2];
  55. printf(
  56. "FAIL on line %s\n%s in\n%s %s()\n\n",
  57. $context['line'], $message->toString(), $context['file'], $realContext['function']
  58. );
  59. }
  60. /**
  61. * Paints the end of the test with a summary of
  62. * the passes and failures.
  63. *
  64. * @param PHPUnit_Framework_TestResult $result Result object
  65. * @return void
  66. */
  67. public function paintFooter($result) {
  68. if ($result->failureCount() + $result->errorCount() == 0) {
  69. echo "\nOK\n";
  70. } else {
  71. echo "FAILURES!!!\n";
  72. }
  73. echo "Test cases run: " . $result->count() .
  74. "/" . ($result->count() - $result->skippedCount()) .
  75. ', Passes: ' . $this->numAssertions .
  76. ', Failures: ' . $result->failureCount() .
  77. ', Exceptions: ' . $result->errorCount() . "\n";
  78. echo 'Time: ' . $result->time() . " seconds\n";
  79. echo 'Peak memory: ' . number_format(memory_get_peak_usage()) . " bytes\n";
  80. if (isset($this->params['codeCoverage']) && $this->params['codeCoverage']) {
  81. $coverage = $result->getCodeCoverage()->getSummary();
  82. echo $this->paintCoverage($coverage);
  83. }
  84. }
  85. /**
  86. * Paints the title only.
  87. *
  88. * @param string $test_name Name class of test.
  89. * @return void
  90. */
  91. public function paintHeader() {
  92. $this->paintDocumentStart();
  93. flush();
  94. }
  95. /**
  96. * Paints a PHP exception.
  97. *
  98. * @param Exception $exception Exception to describe.
  99. * @return void
  100. */
  101. public function paintException($exception) {
  102. $message = 'Unexpected exception of type [' . get_class($exception) .
  103. '] with message ['. $exception->getMessage() .
  104. '] in ['. $exception->getFile() .
  105. ' line ' . $exception->getLine() . ']';
  106. echo $message . "\n\n";
  107. }
  108. /**
  109. * Prints the message for skipping tests.
  110. *
  111. * @param string $message Text of skip condition.
  112. * @return void
  113. */
  114. public function paintSkip($message) {
  115. printf("Skip: %s\n", $message->getMessage());
  116. }
  117. /**
  118. * Paints formatted text such as dumped variables.
  119. *
  120. * @param string $message Text to show.
  121. * @return void
  122. */
  123. public function paintFormattedMessage($message) {
  124. echo "$message\n";
  125. flush();
  126. }
  127. /**
  128. * Generate a test case list in plain text.
  129. * Creates as series of url's for tests that can be run.
  130. * One case per line.
  131. *
  132. * @return void
  133. */
  134. public function testCaseList() {
  135. $testCases = parent::testCaseList();
  136. $app = $this->params['app'];
  137. $plugin = $this->params['plugin'];
  138. $buffer = "Core Test Cases:\n";
  139. $urlExtra = '';
  140. if ($app) {
  141. $buffer = "App Test Cases:\n";
  142. $urlExtra = '&app=true';
  143. } elseif ($plugin) {
  144. $buffer = Inflector::humanize($plugin) . " Test Cases:\n";
  145. $urlExtra = '&plugin=' . $plugin;
  146. }
  147. if (1 > count($testCases)) {
  148. $buffer .= "EMPTY";
  149. echo $buffer;
  150. }
  151. foreach ($testCases as $testCaseFile => $testCase) {
  152. $buffer .= $_SERVER['SERVER_NAME'] . $this->baseUrl() ."?case=" . $testCase . "&output=text"."\n";
  153. }
  154. $buffer .= "\n";
  155. echo $buffer;
  156. }
  157. /**
  158. * Generates a Text summary of the coverage data.
  159. *
  160. * @param array $coverage Array of coverage data.
  161. * @return string
  162. */
  163. public function paintCoverage($coverage) {
  164. $reporter = new TextCoverageReport($coverage, $this);
  165. echo $reporter->report();
  166. }
  167. }