CakePHP
  • Documentation
    • Book
    • API
    • Videos
    • Reporting Security Issues
    • Privacy Policy
    • Logos & Trademarks
  • Business Solutions
  • Swag
  • Road Trip
  • Team
  • Community
    • Community
    • Get Involved
    • Issues (GitHub)
    • Bakery
    • Featured Resources
    • Training
    • Meetups
    • My CakePHP
    • CakeFest
    • Newsletter
    • Linkedin
    • YouTube
    • Facebook
    • Twitter
    • Mastodon
    • Help & Support
    • Forum
    • Stack Overflow
    • Slack
    • Paid Support
CakePHP

C CakePHP 2.0 API

  • Overview
  • Tree
  • Deprecated
  • Version:
    • 2.0
      • 4.2
      • 4.1
      • 4.0
      • 3.9
      • 3.8
      • 3.7
      • 3.6
      • 3.5
      • 3.4
      • 3.3
      • 3.2
      • 3.1
      • 3.0
      • 2.10
      • 2.9
      • 2.8
      • 2.7
      • 2.6
      • 2.5
      • 2.4
      • 2.3
      • 2.2
      • 2.1
      • 2.0
      • 1.3
      • 1.2

Packages

  • Cake
    • Cache
      • Engine
    • Configure
    • Console
      • Command
        • Task
    • Controller
      • Component
        • Auth
    • Core
    • Error
    • I18n
    • Log
      • Engine
    • Model
      • Behavior
      • Datasource
        • Database
        • Session
    • Network
      • Email
      • Http
    • Routing
      • Route
    • TestSuite
      • Coverage
      • Fixture
      • Reporter
    • Utility
    • View
      • Helper

Classes

  • CakeBaseReporter
  • CakeHtmlReporter
  • CakeTextReporter
  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: /**
 22:  * CakeTextReporter contains reporting features used for plain text based output
 23:  *
 24:  * @package       Cake.TestSuite.Reporter
 25:  */
 26: class CakeTextReporter extends CakeBaseReporter {
 27: 
 28: /**
 29:  * Sets the text/plain header if the test is not a CLI test.
 30:  *
 31:  * @return void
 32:  */
 33:     public function paintDocumentStart() {
 34:         if (!headers_sent()) {
 35:             header('Content-type: text/plain');
 36:         }
 37:     }
 38: 
 39: /**
 40:  * Paints a pass
 41:  *
 42:  * @return void
 43:  */
 44:     public function paintPass() {
 45:         echo '.';
 46:     }
 47: 
 48: /**
 49:  * Paints a failing test.
 50:  *
 51:  * @param $message PHPUnit_Framework_AssertionFailedError $message Failure object displayed in
 52:  *   the context of the other tests.
 53:  * @return void
 54:  */
 55:     public function paintFail($message) {
 56:         $context = $message->getTrace();
 57:         $realContext = $context[3];
 58:         $context = $context[2];
 59: 
 60:         printf(
 61:             "FAIL on line %s\n%s in\n%s %s()\n\n",
 62:             $context['line'], $message->toString(), $context['file'], $realContext['function']
 63:         );
 64:     }
 65: 
 66: /**
 67:  * Paints the end of the test with a summary of
 68:  * the passes and failures.
 69:  *
 70:  * @param PHPUnit_Framework_TestResult $result Result object
 71:  * @return void
 72:  */
 73:     public function paintFooter($result) {
 74:         if ($result->failureCount() + $result->errorCount() == 0) {
 75:             echo "\nOK\n";
 76:         } else {
 77:             echo "FAILURES!!!\n";
 78:         }
 79: 
 80:         echo "Test cases run: " . $result->count() .
 81:             "/" . ($result->count() - $result->skippedCount()) .
 82:             ', Passes: ' . $this->numAssertions .
 83:             ', Failures: ' . $result->failureCount() .
 84:             ', Exceptions: ' . $result->errorCount() . "\n";
 85: 
 86:         echo 'Time: ' . $result->time() . " seconds\n";
 87:         echo 'Peak memory: ' . number_format(memory_get_peak_usage()) . " bytes\n";
 88: 
 89:         if (isset($this->params['codeCoverage']) && $this->params['codeCoverage']) {
 90:             $coverage = $result->getCodeCoverage()->getSummary();
 91:             echo $this->paintCoverage($coverage);
 92:         }
 93:     }
 94: 
 95: /**
 96:  * Paints the title only.
 97:  *
 98:  * @param string $test_name Name class of test.
 99:  * @return void
100:  */
101:     public function paintHeader() {
102:         $this->paintDocumentStart();
103:         flush();
104:     }
105: 
106: /**
107:  * Paints a PHP exception.
108:  *
109:  * @param Exception $exception Exception to describe.
110:  * @return void
111:  */
112:     public function paintException($exception) {
113:         $message = 'Unexpected exception of type [' . get_class($exception) .
114:             '] with message ['. $exception->getMessage() .
115:             '] in ['. $exception->getFile() .
116:             ' line ' . $exception->getLine() . ']';
117:         echo $message . "\n\n";
118:     }
119: 
120: /**
121:  * Prints the message for skipping tests.
122:  *
123:  * @param string $message Text of skip condition.
124:  * @return void
125:  */
126:     public function paintSkip($message) {
127:         printf("Skip: %s\n", $message->getMessage());
128:     }
129: 
130: /**
131:  * Paints formatted text such as dumped variables.
132:  *
133:  * @param string $message Text to show.
134:  * @return void
135:  */
136:     public function paintFormattedMessage($message) {
137:         echo "$message\n";
138:         flush();
139:     }
140: 
141: /**
142:  * Generate a test case list in plain text.
143:  * Creates as series of url's for tests that can be run.
144:  * One case per line.
145:  *
146:  * @return void
147:  */
148:     public function testCaseList() {
149:         $testCases = parent::testCaseList();
150:         $app = $this->params['app'];
151:         $plugin = $this->params['plugin'];
152: 
153:         $buffer = "Core Test Cases:\n";
154:         $urlExtra = '';
155:         if ($app) {
156:             $buffer = "App Test Cases:\n";
157:             $urlExtra = '&app=true';
158:         } elseif ($plugin) {
159:             $buffer = Inflector::humanize($plugin) . " Test Cases:\n";
160:             $urlExtra = '&plugin=' . $plugin;
161:         }
162: 
163:         if (1 > count($testCases)) {
164:             $buffer .= "EMPTY";
165:             echo $buffer;
166:         }
167: 
168:         foreach ($testCases as $testCaseFile => $testCase) {
169:             $buffer .= $_SERVER['SERVER_NAME'] . $this->baseUrl() ."?case=" . $testCase . "&output=text"."\n";
170:         }
171: 
172:         $buffer .= "\n";
173:         echo $buffer;
174:     }
175: 
176: /**
177:  * Generates a Text summary of the coverage data.
178:  *
179:  * @param array $coverage Array of coverage data.
180:  * @return string
181:  */
182:     public function paintCoverage($coverage) {
183:         $reporter = new TextCoverageReport($coverage, $this);
184:         echo $reporter->report();
185:     }
186: 
187: }
188: 
OpenHub
Rackspace
Rackspace
  • Business Solutions
  • Showcase
  • Documentation
  • Book
  • API
  • Videos
  • Reporting Security Issues
  • Privacy Policy
  • Logos & Trademarks
  • Community
  • Get Involved
  • Issues (GitHub)
  • Bakery
  • Featured Resources
  • Training
  • Meetups
  • My CakePHP
  • CakeFest
  • Newsletter
  • Linkedin
  • YouTube
  • Facebook
  • Twitter
  • Mastodon
  • Help & Support
  • Forum
  • Stack Overflow
  • Slack
  • Paid Support

Generated using CakePHP API Docs