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

  • Overview
  • Tree
  • Deprecated
  • Version:
    • 2.2
      • 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 2005-2012, 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-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
 14:  * @link          http://cakephp.org CakePHP(tm) Project
 15:  * @package       Cake.TestSuite
 16:  * @since         CakePHP(tm) v 2.0
 17:  * @license       MIT License (http://www.opensource.org/licenses/mit-license.php)
 18:  */
 19: 
 20: require_once 'PHPUnit/TextUI/Command.php';
 21: 
 22: App::uses('CakeTestRunner', 'TestSuite');
 23: App::uses('CakeTestLoader', 'TestSuite');
 24: App::uses('CakeTestSuite', 'TestSuite');
 25: App::uses('CakeTestCase', 'TestSuite');
 26: App::uses('ControllerTestCase', 'TestSuite');
 27: App::uses('CakeTestModel', 'TestSuite/Fixture');
 28: 
 29: /**
 30:  * Class to customize loading of test suites from CLI
 31:  *
 32:  * @package       Cake.TestSuite
 33:  */
 34: class CakeTestSuiteCommand extends PHPUnit_TextUI_Command {
 35: 
 36: /**
 37:  * Construct method
 38:  *
 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 classname for the Runner. :(
 57:  *
 58:  * @param array   $argv
 59:  * @param boolean $exit
 60:  */
 61:     public function run(array $argv, $exit = true) {
 62:         $this->handleArguments($argv);
 63: 
 64:         $runner = $this->getRunner($this->arguments['loader']);
 65: 
 66:         if (is_object($this->arguments['test']) &&
 67:             $this->arguments['test'] instanceof PHPUnit_Framework_Test) {
 68:             $suite = $this->arguments['test'];
 69:         } else {
 70:             $suite = $runner->getTest(
 71:                 $this->arguments['test'],
 72:                 $this->arguments['testFile']
 73:             );
 74:         }
 75: 
 76:         if (count($suite) == 0) {
 77:             $skeleton = new PHPUnit_Util_Skeleton_Test(
 78:                 $suite->getName(),
 79:                 $this->arguments['testFile']
 80:             );
 81: 
 82:             $result = $skeleton->generate(true);
 83: 
 84:             if (!$result['incomplete']) {
 85:                 //@codingStandardsIgnoreStart
 86:                 eval(str_replace(array('<?php', '?>'), '', $result['code']));
 87:                 //@codingStandardsIgnoreEnd
 88:                 $suite = new PHPUnit_Framework_TestSuite(
 89:                     $this->arguments['test'] . 'Test'
 90:                 );
 91:             }
 92:         }
 93: 
 94:         if ($this->arguments['listGroups']) {
 95:             PHPUnit_TextUI_TestRunner::printVersionString();
 96: 
 97:             print "Available test group(s):\n";
 98: 
 99:             $groups = $suite->getGroups();
100:             sort($groups);
101: 
102:             foreach ($groups as $group) {
103:                 print " - $group\n";
104:             }
105: 
106:             exit(PHPUnit_TextUI_TestRunner::SUCCESS_EXIT);
107:         }
108: 
109:         unset($this->arguments['test']);
110:         unset($this->arguments['testFile']);
111: 
112:         try {
113:             $result = $runner->doRun($suite, $this->arguments);
114:         } catch (PHPUnit_Framework_Exception $e) {
115:             print $e->getMessage() . "\n";
116:         }
117: 
118:         if ($exit) {
119:             if (isset($result) && $result->wasSuccessful()) {
120:                 exit(PHPUnit_TextUI_TestRunner::SUCCESS_EXIT);
121:             } elseif (!isset($result) || $result->errorCount() > 0) {
122:                 exit(PHPUnit_TextUI_TestRunner::EXCEPTION_EXIT);
123:             } else {
124:                 exit(PHPUnit_TextUI_TestRunner::FAILURE_EXIT);
125:             }
126:         }
127:     }
128: 
129: /**
130:  * Create a runner for the command.
131:  *
132:  * @param $loader The loader to be used for the test run.
133:  * @return CakeTestRunner
134:  */
135:     public function getRunner($loader) {
136:         return new CakeTestRunner($loader, $this->_params);
137:     }
138: 
139: /**
140:  * Handler for customizing the FixtureManager class/
141:  *
142:  * @param string $class Name of the class that will be the fixture manager
143:  * @return void
144:  */
145:     public function handleFixture($class) {
146:         $this->arguments['fixtureManager'] = $class;
147:     }
148: 
149: /**
150:  * Handles output flag used to change printing on webrunner.
151:  *
152:  * @return void
153:  */
154:     public function handleReporter($reporter) {
155:         $object = null;
156: 
157:         $type = strtolower($reporter);
158:         $reporter = ucwords($reporter);
159:         $coreClass = 'Cake' . $reporter . 'Reporter';
160:         App::uses($coreClass, 'TestSuite/Reporter');
161: 
162:         $appClass = $reporter . 'Reporter';
163:         App::uses($appClass, 'TestSuite/Reporter');
164: 
165:         if (!class_exists($appClass)) {
166:             $object = new $coreClass(null, $this->_params);
167:         } else {
168:             $object = new $appClass(null, $this->_params);
169:         }
170:         return $this->arguments['printer'] = $object;
171:     }
172: 
173: }
174: 
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