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

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