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.3 API

  • Overview
  • Tree
  • Deprecated
  • Version:
    • 2.3
      • 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
        • Acl
        • Auth
    • Core
    • Error
    • Event
    • I18n
    • Log
      • Engine
    • Model
      • Behavior
      • Datasource
        • Database
        • Session
      • Validator
    • Network
      • Email
      • Http
    • Routing
      • Filter
      • 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/2.0/en/development/testing.html>
  8:  * Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
  9:  *
 10:  * Licensed under The MIT License
 11:  * For full copyright and license information, please see the LICENSE.txt
 12:  * Redistributions of files must retain the above copyright notice
 13:  *
 14:  * @copyright     Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
 15:  * @link          http://cakephp.org CakePHP(tm) Project
 16:  * @since         CakePHP(tm) v 1.3
 17:  * @license       http://www.opensource.org/licenses/mit-license.php MIT License
 18:  */
 19: 
 20: App::uses('CakeBaseReporter', 'TestSuite/Reporter');
 21: App::uses('TextCoverageReport', 'TestSuite/Coverage');
 22: 
 23: /**
 24:  * CakeTextReporter contains reporting features used for plain text based output
 25:  *
 26:  * @package       Cake.TestSuite.Reporter
 27:  */
 28: class CakeTextReporter extends CakeBaseReporter {
 29: 
 30: /**
 31:  * Sets the text/plain header if the test is not a CLI test.
 32:  *
 33:  * @return void
 34:  */
 35:     public function paintDocumentStart() {
 36:         if (!headers_sent()) {
 37:             header('Content-type: text/plain');
 38:         }
 39:     }
 40: 
 41: /**
 42:  * Paints a pass
 43:  *
 44:  * @return void
 45:  */
 46:     public function paintPass() {
 47:         echo '.';
 48:     }
 49: 
 50: /**
 51:  * Paints a failing test.
 52:  *
 53:  * @param PHPUnit_Framework_AssertionFailedError $message Failure object displayed in
 54:  *   the context of the other tests.
 55:  * @return void
 56:  */
 57:     public function paintFail($message) {
 58:         $context = $message->getTrace();
 59:         $realContext = $context[3];
 60:         $context = $context[2];
 61: 
 62:         printf(
 63:             "FAIL on line %s\n%s in\n%s %s()\n\n",
 64:             $context['line'], $message->toString(), $context['file'], $realContext['function']
 65:         );
 66:     }
 67: 
 68: /**
 69:  * Paints the end of the test with a summary of
 70:  * the passes and failures.
 71:  *
 72:  * @param PHPUnit_Framework_TestResult $result Result object
 73:  * @return void
 74:  */
 75:     public function paintFooter($result) {
 76:         if ($result->failureCount() + $result->errorCount()) {
 77:             echo "FAILURES!!!\n";
 78:         } else {
 79:             echo "\nOK\n";
 80:         }
 81: 
 82:         echo "Test cases run: " . $result->count() .
 83:             "/" . ($result->count() - $result->skippedCount()) .
 84:             ', Passes: ' . $this->numAssertions .
 85:             ', Failures: ' . $result->failureCount() .
 86:             ', Exceptions: ' . $result->errorCount() . "\n";
 87: 
 88:         echo 'Time: ' . $result->time() . " seconds\n";
 89:         echo 'Peak memory: ' . number_format(memory_get_peak_usage()) . " bytes\n";
 90: 
 91:         if (isset($this->params['codeCoverage']) && $this->params['codeCoverage']) {
 92:             $coverage = $result->getCodeCoverage()->getSummary();
 93:             echo $this->paintCoverage($coverage);
 94:         }
 95:     }
 96: 
 97: /**
 98:  * Paints the title only.
 99:  *
100:  * @return void
101:  */
102:     public function paintHeader() {
103:         $this->paintDocumentStart();
104:         flush();
105:     }
106: 
107: /**
108:  * Paints a PHP exception.
109:  *
110:  * @param Exception $exception Exception to describe.
111:  * @return void
112:  */
113:     public function paintException($exception) {
114:         $message = 'Unexpected exception of type [' . get_class($exception) .
115:             '] with message [' . $exception->getMessage() .
116:             '] in [' . $exception->getFile() .
117:             ' line ' . $exception->getLine() . ']';
118:         echo $message . "\n\n";
119:     }
120: 
121: /**
122:  * Prints the message for skipping tests.
123:  *
124:  * @param string $message Text of skip condition.
125:  * @return void
126:  */
127:     public function paintSkip($message) {
128:         printf("Skip: %s\n", $message->getMessage());
129:     }
130: 
131: /**
132:  * Paints formatted text such as dumped variables.
133:  *
134:  * @param string $message Text to show.
135:  * @return void
136:  */
137:     public function paintFormattedMessage($message) {
138:         echo "$message\n";
139:         flush();
140:     }
141: 
142: /**
143:  * Generate a test case list in plain text.
144:  * Creates as series of url's for tests that can be run.
145:  * One case per line.
146:  *
147:  * @return void
148:  */
149:     public function testCaseList() {
150:         $testCases = parent::testCaseList();
151:         $app = $this->params['app'];
152:         $plugin = $this->params['plugin'];
153: 
154:         $buffer = "Core Test Cases:\n";
155:         $urlExtra = '';
156:         if ($app) {
157:             $buffer = "App Test Cases:\n";
158:             $urlExtra = '&app=true';
159:         } elseif ($plugin) {
160:             $buffer = Inflector::humanize($plugin) . " Test Cases:\n";
161:             $urlExtra = '&plugin=' . $plugin;
162:         }
163: 
164:         if (1 > count($testCases)) {
165:             $buffer .= 'EMPTY';
166:             echo $buffer;
167:         }
168: 
169:         foreach ($testCases as $testCase) {
170:             $buffer .= $_SERVER['SERVER_NAME'] . $this->baseUrl() . "?case=" . $testCase . "&output=text\n";
171:         }
172: 
173:         $buffer .= "\n";
174:         echo $buffer;
175:     }
176: 
177: /**
178:  * Generates a Text summary of the coverage data.
179:  *
180:  * @param array $coverage Array of coverage data.
181:  * @return void
182:  */
183:     public function paintCoverage($coverage) {
184:         $reporter = new TextCoverageReport($coverage, $this);
185:         echo $reporter->report();
186:     }
187: 
188: }
189: 
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