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

  • CakeTestCase
  • CakeTestLoader
  • CakeTestRunner
  • CakeTestSuite
  • CakeTestSuiteCommand
  • CakeTestSuiteDispatcher
  • ControllerTestCase
  • ControllerTestDispatcher
  • InterceptContentHelper
  1: <?php
  2: /**
  3:  * CakeTestSuiteDispatcher controls dispatching TestSuite web based requests.
  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:  * @package       Cake.TestSuite
 16:  * @since         CakePHP(tm) v 1.3
 17:  * @license       MIT License (http://www.opensource.org/licenses/mit-license.php)
 18:  */
 19: 
 20: define('CORE_TEST_CASES', CAKE . 'Test' . DS . 'Case');
 21: define('APP_TEST_CASES', TESTS . 'Case');
 22: 
 23: App::uses('CakeTestSuiteCommand', 'TestSuite');
 24: 
 25: /**
 26:  * CakeTestSuiteDispatcher handles web requests to the test suite and runs the correct action.
 27:  *
 28:  * @package       Cake.TestSuite
 29:  */
 30: class CakeTestSuiteDispatcher {
 31: /**
 32:  * 'Request' parameters
 33:  *
 34:  * @var array
 35:  */
 36:     public $params = array(
 37:         'codeCoverage' => false,
 38:         'case' => null,
 39:         'core' => false,
 40:         'app' => false,
 41:         'plugin' => null,
 42:         'output' => 'html',
 43:         'show' => 'groups',
 44:         'show_passes' => false,
 45:         'filter' => false,
 46:         'fixture' => null
 47:     );
 48: 
 49: /**
 50:  * Baseurl for the request
 51:  *
 52:  * @var string
 53:  */
 54:     protected $_baseUrl;
 55: 
 56: /**
 57:  * Base dir of the request.  Used for accessing assets.
 58:  *
 59:  * @var string
 60:  */
 61:     protected $_baseDir;
 62: 
 63: /**
 64:  * boolean to set auto parsing of params.
 65:  *
 66:  * @var boolean
 67:  */
 68:     protected $_paramsParsed = false;
 69: 
 70: /**
 71:  * reporter instance used for the request
 72:  *
 73:  * @var CakeBaseReporter
 74:  */
 75:     protected static $_Reporter = null;
 76: 
 77: /**
 78:  * constructor
 79:  *
 80:  * @return void
 81:  */
 82:     function __construct() {
 83:         $this->_baseUrl = $_SERVER['PHP_SELF'];
 84:         $dir = rtrim(dirname($this->_baseUrl), '\\');
 85:         $this->_baseDir = ($dir === '/') ? $dir : $dir . '/';
 86:     }
 87: 
 88: /**
 89:  * Runs the actions required by the URL parameters.
 90:  *
 91:  * @return void
 92:  */
 93:     public function dispatch() {
 94:         $this->_checkPHPUnit();
 95:         $this->_parseParams();
 96: 
 97:         if ($this->params['case']) {
 98:             $value = $this->_runTestCase();
 99:         } else {
100:             $value = $this->_testCaseList();
101:         }
102: 
103:         $output = ob_get_clean();
104:         echo $output;
105:         return $value;
106:     }
107: 
108: /**
109:  * Static method to initialize the test runner, keeps global space clean
110:  *
111:  * @return void
112:  */
113:     public static function run() {
114:         $dispatcher = new CakeTestSuiteDispatcher();
115:         $dispatcher->dispatch();
116:     }
117: 
118: /**
119:  * Checks that PHPUnit is installed.  Will exit if it doesn't
120:  *
121:  * @return void
122:  */
123:     protected function _checkPHPUnit() {
124:         $found = $this->loadTestFramework();
125:         if (!$found) {
126:             $baseDir = $this->_baseDir;
127:             include CAKE . 'TestSuite' . DS . 'templates' . DS . 'phpunit.php';
128:             exit();
129:         }
130:     }
131: 
132: /**
133:  * Checks for the existence of the test framework files
134:  *
135:  * @return boolean true if found, false otherwise
136:  */
137:     public function loadTestFramework() {
138:         $found = $path = null;
139: 
140:         if (@include 'PHPUnit' . DS . 'Autoload.php') {
141:             $found = true;
142:         }
143: 
144:         if (!$found) {
145:             foreach (App::path('vendors') as $vendor) {
146:                 if (is_dir($vendor . 'PHPUnit')) {
147:                     $path = $vendor;
148:                 }
149:             }
150: 
151:             if ($path && ini_set('include_path', $path . PATH_SEPARATOR . ini_get('include_path'))) {
152:                 $found = include 'PHPUnit' . DS . 'Autoload.php';
153:             }
154:         }
155:         return $found;
156:     }
157: 
158: /**
159:  * Checks for the xdebug extension required to do code coverage. Displays an error
160:  * if xdebug isn't installed.
161:  *
162:  * @return void
163:  */
164:     function _checkXdebug() {
165:         if (!extension_loaded('xdebug')) {
166:             $baseDir = $this->_baseDir;
167:             include CAKE . 'TestSuite' . DS . 'templates' . DS . 'xdebug.php';
168:             exit();
169:         }
170:     }
171: 
172: /**
173:  * Generates a page containing the a list of test cases that could be run.
174:  *
175:  * @return void
176:  */
177:     function _testCaseList() {
178:         $command = new CakeTestSuiteCommand('', $this->params);
179:         $Reporter = $command->handleReporter($this->params['output']);
180:         $Reporter->paintDocumentStart();
181:         $Reporter->paintTestMenu();
182:         $Reporter->testCaseList();
183:         $Reporter->paintDocumentEnd();
184:     }
185: 
186: /**
187:  * Sets the params, calling this will bypass the auto parameter parsing.
188:  *
189:  * @param array $params Array of parameters for the dispatcher
190:  * @return void
191:  */
192:     public function setParams($params) {
193:         $this->params = $params;
194:         $this->_paramsParsed = true;
195:     }
196: 
197: /**
198:  * Parse url params into a 'request'
199:  *
200:  * @return void
201:  */
202:     function _parseParams() {
203:         if (!$this->_paramsParsed) {
204:             if (!isset($_SERVER['SERVER_NAME'])) {
205:                 $_SERVER['SERVER_NAME'] = '';
206:             }
207:             foreach ($this->params as $key => $value) {
208:                 if (isset($_GET[$key])) {
209:                     $this->params[$key] = $_GET[$key];
210:                 }
211:             }
212:             if (isset($_GET['code_coverage'])) {
213:                 $this->params['codeCoverage'] = true;
214:                 $this->_checkXdebug();
215:             }
216:         }
217:         if (empty($this->params['plugin']) && empty($this->params['app'])) {
218:             $this->params['core'] = true;
219:         }
220:         $this->params['baseUrl'] = $this->_baseUrl;
221:         $this->params['baseDir'] = $this->_baseDir;
222:     }
223: 
224: /**
225:  * Runs a test case file.
226:  *
227:  * @return void
228:  */
229:     function _runTestCase() {
230:         $commandArgs = array(
231:             'case' => $this->params['case'],
232:             'core' => $this->params['core'],
233:             'app' => $this->params['app'],
234:             'plugin' => $this->params['plugin'],
235:             'codeCoverage' => $this->params['codeCoverage'],
236:             'showPasses' => !empty($this->params['show_passes']),
237:             'baseUrl' => $this->_baseUrl,
238:             'baseDir' => $this->_baseDir,
239:         );
240: 
241:         $options = array(
242:             '--filter', $this->params['filter'],
243:             '--output', $this->params['output'],
244:             '--fixture', $this->params['fixture']
245:         );
246:         restore_error_handler();
247: 
248:         try {
249:             $command = new CakeTestSuiteCommand('CakeTestLoader', $commandArgs);
250:             $result = $command->run($options);
251:         } catch (MissingConnectionException $exception) {
252:             ob_end_clean();
253:             $baseDir = $this->_baseDir;
254:             include CAKE . 'TestSuite' . DS . 'templates' . DS . 'missing_connection.php';
255:             exit();
256:         }
257:     }
258: }
259: 
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