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

  • Overview
  • Tree
  • Deprecated
  • Version:
    • 2.1
      • 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
    • 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:  * 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:                 eval(str_replace(array('<?php', '?>'), '', $result['code']));
 86:                 $suite = new PHPUnit_Framework_TestSuite(
 87:                     $this->arguments['test'] . 'Test'
 88:                 );
 89:             }
 90:         }
 91: 
 92:         if ($this->arguments['listGroups']) {
 93:             PHPUnit_TextUI_TestRunner::printVersionString();
 94: 
 95:             print "Available test group(s):\n";
 96: 
 97:             $groups = $suite->getGroups();
 98:             sort($groups);
 99: 
100:             foreach ($groups as $group) {
101:                 print " - $group\n";
102:             }
103: 
104:             exit(PHPUnit_TextUI_TestRunner::SUCCESS_EXIT);
105:         }
106: 
107:         unset($this->arguments['test']);
108:         unset($this->arguments['testFile']);
109: 
110:         try {
111:             $result = $runner->doRun($suite, $this->arguments);
112:         } catch (PHPUnit_Framework_Exception $e) {
113:             print $e->getMessage() . "\n";
114:         }
115: 
116:         if ($exit) {
117:             if (isset($result) && $result->wasSuccessful()) {
118:                 exit(PHPUnit_TextUI_TestRunner::SUCCESS_EXIT);
119:             } elseif (!isset($result) || $result->errorCount() > 0) {
120:                 exit(PHPUnit_TextUI_TestRunner::EXCEPTION_EXIT);
121:             } else {
122:                 exit(PHPUnit_TextUI_TestRunner::FAILURE_EXIT);
123:             }
124:         }
125:     }
126: 
127: /**
128:  * Create a runner for the command.
129:  *
130:  * @param $loader The loader to be used for the test run.
131:  * @return CakeTestRunner
132:  */
133:     public function getRunner($loader) {
134:         return new CakeTestRunner($loader, $this->_params);
135:     }
136: 
137: /**
138:  * Handler for customizing the FixtureManager class/
139:  *
140:  * @param string $class Name of the class that will be the fixture manager
141:  * @return void
142:  */
143:     public function handleFixture($class) {
144:         $this->arguments['fixtureManager'] = $class;
145:     }
146: 
147: /**
148:  * Handles output flag used to change printing on webrunner.
149:  *
150:  * @return void
151:  */
152:     public function handleReporter($reporter) {
153:         $object = null;
154: 
155:         $type = strtolower($reporter);
156:         $reporter = ucwords($reporter);
157:         $coreClass = 'Cake' . $reporter . 'Reporter';
158:         App::uses($coreClass, 'TestSuite/Reporter');
159: 
160:         $appClass = $reporter . 'Reporter';
161:         App::uses($appClass, 'TestSuite/Reporter');
162: 
163:         if (!class_exists($appClass)) {
164:             $object = new $coreClass(null, $this->_params);
165:         } else {
166:             $object = new $appClass(null, $this->_params);
167:         }
168:         return $this->arguments['printer'] = $object;
169:     }
170: 
171: }
172: 
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