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

  • Overview
  • Tree
  • Deprecated
  • Version:
    • 2.4
      • 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

  • CakeTestCase
  • CakeTestLoader
  • CakeTestRunner
  • CakeTestSuite
  • CakeTestSuiteCommand
  • CakeTestSuiteDispatcher
  • ControllerTestCase
  • ControllerTestDispatcher
  • InterceptContentHelper
  1: <?php
  2: /**
  3:  * TestRunner for CakePHP Test suite.
  4:  *
  5:  * CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
  6:  * Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
  7:  *
  8:  * Licensed under The MIT License
  9:  * For full copyright and license information, please see the LICENSE.txt
 10:  * Redistributions of files must retain the above copyright notice.
 11:  *
 12:  * @copyright     Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
 13:  * @link          http://cakephp.org CakePHP(tm) Project
 14:  * @package       Cake.TestSuite
 15:  * @since         CakePHP(tm) v 2.0
 16:  * @license       http://www.opensource.org/licenses/mit-license.php MIT License
 17:  */
 18: 
 19: require_once 'PHPUnit/TextUI/Command.php';
 20: 
 21: App::uses('CakeTestRunner', 'TestSuite');
 22: App::uses('CakeTestLoader', 'TestSuite');
 23: App::uses('CakeTestSuite', 'TestSuite');
 24: App::uses('CakeTestCase', 'TestSuite');
 25: App::uses('ControllerTestCase', 'TestSuite');
 26: App::uses('CakeTestModel', 'TestSuite/Fixture');
 27: 
 28: /**
 29:  * Class to customize loading of test suites from CLI
 30:  *
 31:  * @package       Cake.TestSuite
 32:  */
 33: class CakeTestSuiteCommand extends PHPUnit_TextUI_Command {
 34: 
 35: /**
 36:  * Construct method
 37:  *
 38:  * @param mixed $loader
 39:  * @param array $params list of options to be used for this run
 40:  * @throws MissingTestLoaderException When a loader class could not be found.
 41:  */
 42:     public function __construct($loader, $params = array()) {
 43:         if ($loader && !class_exists($loader)) {
 44:             throw new MissingTestLoaderException(array('class' => $loader));
 45:         }
 46:         $this->arguments['loader'] = $loader;
 47:         $this->arguments['test'] = $params['case'];
 48:         $this->arguments['testFile'] = $params;
 49:         $this->_params = $params;
 50: 
 51:         $this->longOptions['fixture='] = 'handleFixture';
 52:         $this->longOptions['output='] = 'handleReporter';
 53:     }
 54: 
 55: /**
 56:  * Ugly hack to get around PHPUnit having a hard coded class name for the Runner. :(
 57:  *
 58:  * @param array   $argv
 59:  * @param boolean $exit
 60:  * @return void
 61:  */
 62:     public function run(array $argv, $exit = true) {
 63:         $this->handleArguments($argv);
 64: 
 65:         $runner = $this->getRunner($this->arguments['loader']);
 66: 
 67:         if (is_object($this->arguments['test']) &&
 68:             $this->arguments['test'] instanceof PHPUnit_Framework_Test) {
 69:             $suite = $this->arguments['test'];
 70:         } else {
 71:             $suite = $runner->getTest(
 72:                 $this->arguments['test'],
 73:                 $this->arguments['testFile']
 74:             );
 75:         }
 76: 
 77:         if ($this->arguments['listGroups']) {
 78:             PHPUnit_TextUI_TestRunner::printVersionString();
 79: 
 80:             print "Available test group(s):\n";
 81: 
 82:             $groups = $suite->getGroups();
 83:             sort($groups);
 84: 
 85:             foreach ($groups as $group) {
 86:                 print " - $group\n";
 87:             }
 88: 
 89:             exit(PHPUnit_TextUI_TestRunner::SUCCESS_EXIT);
 90:         }
 91: 
 92:         unset($this->arguments['test']);
 93:         unset($this->arguments['testFile']);
 94: 
 95:         try {
 96:             $result = $runner->doRun($suite, $this->arguments);
 97:         } catch (PHPUnit_Framework_Exception $e) {
 98:             print $e->getMessage() . "\n";
 99:         }
100: 
101:         if ($exit) {
102:             if (isset($result) && $result->wasSuccessful()) {
103:                 exit(PHPUnit_TextUI_TestRunner::SUCCESS_EXIT);
104:             } elseif (!isset($result) || $result->errorCount() > 0) {
105:                 exit(PHPUnit_TextUI_TestRunner::EXCEPTION_EXIT);
106:             }
107:             exit(PHPUnit_TextUI_TestRunner::FAILURE_EXIT);
108:         }
109:     }
110: 
111: /**
112:  * Create a runner for the command.
113:  *
114:  * @param mixed $loader The loader to be used for the test run.
115:  * @return CakeTestRunner
116:  */
117:     public function getRunner($loader) {
118:         return new CakeTestRunner($loader, $this->_params);
119:     }
120: 
121: /**
122:  * Handler for customizing the FixtureManager class/
123:  *
124:  * @param string $class Name of the class that will be the fixture manager
125:  * @return void
126:  */
127:     public function handleFixture($class) {
128:         $this->arguments['fixtureManager'] = $class;
129:     }
130: 
131: /**
132:  * Handles output flag used to change printing on webrunner.
133:  *
134:  * @param string $reporter
135:  * @return void
136:  */
137:     public function handleReporter($reporter) {
138:         $object = null;
139: 
140:         $reporter = ucwords($reporter);
141:         $coreClass = 'Cake' . $reporter . 'Reporter';
142:         App::uses($coreClass, 'TestSuite/Reporter');
143: 
144:         $appClass = $reporter . 'Reporter';
145:         App::uses($appClass, 'TestSuite/Reporter');
146: 
147:         if (!class_exists($appClass)) {
148:             $object = new $coreClass(null, $this->_params);
149:         } else {
150:             $object = new $appClass(null, $this->_params);
151:         }
152:         return $this->arguments['printer'] = $object;
153:     }
154: 
155: }
156: 
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