Task class for creating and updating test files.
$_fixtures protected array$baseTypes public arrayMapping between packages, and their baseclass + package. This is used to generate App::uses() call to autoload base classes if a developer has forgotten to do so.
$classTypes public array$path public string$tasks public arrayconnection, interactive, plugin OptionParser, Tasks, _helpers, _lastWritten, _taskMap, args, command, modelClass, name, params, stderr, stdin, stdout, taskNames, uses Add class name to the fixture list. Sets the app. or plugin.plugin_name. prefix.
Process all the models attached to a controller and generate a fixture list.
Process a model recursively and pull out all the model names converting them to fixture names.
Construct an instance of the class to be tested. So that fixtures can be detected
Generate the list of fixtures that will be required to run this test based on loaded models.
Gets the real class name from the cake short form. If the class name is already suffixed with the type, the type will not be duplicated.
Get methods declared in the class given. No parent methods will be returned
Is a mock class required for this type of test? Controllers require a mock class.
Make the filename for the test case. resolve the suffixes for controllers and get the plugin path if needed.
Checks whether the chosen type can find its own fixtures. Currently only model, and controller are supported
_addFixture( string $name )
Add class name to the fixture list. Sets the app. or plugin.plugin_name. prefix.
$name _interactive( string $type null )
Handles interactive baking
$type optional null _processController( Controller $subject )
Process all the models attached to a controller and generate a fixture list.
Controller $subject _processModel( Model $subject )
Process a model recursively and pull out all the model names converting them to fixture names.
Model $subject bake( string $type , string $className )
Completes final steps for generating data to create test case.
$type $className buildTestSubject( string $type , string $class )
Construct an instance of the class to be tested. So that fixtures can be detected
$type $class execute( )
Execution method always used for tasks
BakeTask::execute() generateConstructor( string $type , string $fullClassName , string $plugin )
Generate a constructor code snippet for the type and class name
$type $fullClassName $plugin generateFixtureList( object $subject )
Generate the list of fixtures that will be required to run this test based on loaded models.
$subject generateUses( string $type , string $realType , string $className )
Generate the uses() calls for a type & class name
$type $realType $className getBaseType( string $type )
Get the base class and package name for a given type.
$type The type the class having a test generated for is in.
CakeExceptiongetClassName( string $objectType )
Get the user chosen Class name for the chosen type
$objectType getObjectType( )
Interact with the user and get their chosen type. Can exit the script.
getOptionParser( )
Gets the option parser instance and configures it.
ConsoleOptionParserShell::getOptionParser() getRealClassName( string $type , string $class )
Gets the real class name from the cake short form. If the class name is already suffixed with the type, the type will not be duplicated.
$type $class getTestableMethods( string $className )
Get methods declared in the class given. No parent methods will be returned
$className getUserFixtures( )
Interact with the user to get additional fixtures they want to use.
hasMockClass( string $type )
Is a mock class required for this type of test? Controllers require a mock class.
$type isLoadableClass( string $package , string $class )
Check if a class with the given package is loaded or can be loaded.
$package $class mapType( string $type , string $plugin )
Map the types that TestTask uses to concrete types that App::uses can use.
$type $plugin CakeExceptiontestCaseFileName( string $type , string $className )
Make the filename for the test case. resolve the suffixes for controllers and get the plugin path if needed.
$type $className typeCanDetectFixtures( string $type )
Checks whether the chosen type can find its own fixtures. Currently only model, and controller are supported
$type getPath( )
Gets the path for output. Checks the plugin property and returns the correct path.
startup( )
Disable caching and enable debug for baking. This forces the most current database schema to be used.
Shell::startup() __construct( ConsoleOutput $stdout null , ConsoleOutput $stderr null , ConsoleInput $stdin null )
Constructs this Shell instance.
ConsoleOutput $stdout optional null ConsoleOutput $stderr optional null ConsoleInput $stdin optional null Object::__construct() __get( string $name )
Overload get for lazy building of tasks
$name Shell__isset( string $name )
Lazy loads models using the loadModel() method if declared in $uses
$name _checkUnitTest( )
Action to create a Unit Test
_controllerName( string $name )
Creates the proper controller plural name for the specified controller class name
$name _controllerPath( string $name )
Creates the proper controller path for the specified controller class name
$name _displayHelp( string $command )
Display the help in the correct format
$command _getInput( string $prompt , string|array $options , string $default )
Prompts the user for input, and returns it.
$prompt $options $default _loadModels( )
If $uses is an array load each of the models in the array
_modelKey( string $name )
Creates the proper underscored model key for associations
$name _modelName( string $name )
Creates the proper model camelized name (singularized) for the specified name
$name _modelNameFromKey( string $key )
Creates the proper model name from a foreign key
$key _pluginPath( string $pluginName )
Find the correct path for a plugin. Scans $pluginPaths for the plugin you want.
$pluginName _pluralHumanName( string $name )
Creates the plural human name used in views
$name _pluralName( string $name )
Creates the plural name for views
$name _singularHumanName( string $name )
Creates the singular human name used in views
$name _singularName( string $name )
creates the singular name for use in views.
$name _useLogger( boolean $enable true )
Used to enable or disable logging stream output to stdout and stderr If you don't wish to see in your stdout or stderr everything that is logged through CakeLog, call this function with first param as false
$enable optional true clear( )
Clear the console
createFile( string $path , string $contents )
Creates a file at given path
$path $contents dispatchShell( )
Dispatch a command to another Shell. Similar to Object::requestAction() but intended for running shells from other shells.
With a string command:
return $this->dispatchShell('schema create DbAcl');
Avoid using this form if you have string arguments, with spaces in them. The dispatched will be invoked incorrectly. Only use this form for simple command dispatching.
With an array command:
return $this->dispatchShell('schema', 'create', 'i18n', '--dry');
err( string|array $message null , integer $newlines 1 )
Outputs a single or multiple error messages to stderr. If no parameters are passed outputs just a newline.
$message optional null $newlines optional 1 error( string $title , string $message null )
Displays a formatted error message and exits the application with status code 1
$title $message optional null hasMethod( string $name )
Check to see if this shell has a callable method by the given name.
$name hasTask( string $task )
Check to see if this shell has a task with the provided name.
$task helper( string $name )
Load given shell helper class
$name BaseShellHelperhr( integer $newlines 0 , integer $width 63 )
Outputs a series of minus characters to the standard output, acts as a visual separator.
$newlines optional 0 $width optional 63 in( string $prompt , string|array $options null , string $default null )
Prompts the user for input, and returns it.
$prompt $options optional null $default optional null initialize( )
Initializes the Shell acts as constructor for subclasses allows configuration of tasks prior to shell execution
loadModel( string $modelClass null , mixed $id null )
Loads and instantiates models required by this shell.
$modelClass optional null $id optional null MissingModelExceptionnl( integer $multiplier 1 )
Returns a single or multiple linefeeds sequences.
$multiplier optional 1 out( string|array $message null , integer $newlines 1 , integer $level Shell::NORMAL )
Outputs a single or multiple messages to stdout. If no parameters are passed outputs just a newline.
There are 3 built-in output level. Shell::QUIET, Shell::NORMAL, Shell::VERBOSE. The verbose and quiet output levels, map to the verbose and quiet output switches present in most shells. Using Shell::QUIET for a message means it will always display. While using Shell::VERBOSE means it will only display when verbose output is toggled.
$message optional null $newlines optional 1 $level optional Shell::NORMAL overwrite( array|string $message , integer $newlines 1 , integer $size null )
Overwrite some already output text.
Useful for building progress bars, or when you want to replace text already output to the screen with new text.
Warning You cannot overwrite text that contains newlines.
$message $newlines optional 1 $size optional null param( string $name )
Safely access the values in $this->params.
$name runCommand( string $command , array $argv )
Runs the Shell with the provided argv.
Delegates calls to Tasks and resolves methods inside the class. Commands are looked up with the following order:
main() method.If a shell implements a main() method, all missing method calls will be sent to main() with the original method name in the argv.
$command The command name to run on this shell. If this argument is empty, and the shell has a main() method, that will be called instead.
$argv shortPath( string $file )
Makes absolute file path easier to read
$file wrapText( string $text , string|integer|array $options array() )
Wrap a block of text. Allows you to set the width, and indenting on a block of text.
width The width to wrap to. Defaults to 72wordWrap Only wrap on words breaks (spaces) Defaults to true.indent Indent the text with the string provided. Defaults to null.$text $options optional array() _mergeVars( array $properties , string $class , boolean $normalize true )
Merges this objects $property with the property in $class' definition. This classes value for the property will be merged on top of $class'
This provides some of the DRY magic CakePHP provides. If you want to shut it off, redefine this method as an empty function.
$properties $class $normalize optional true _set( array $properties array() )
Allows setting of multiple properties of the object in a single line of code. Will only set properties that are part of a class declaration.
$properties optional array() _stop( integer|string $status 0 )
Stop execution of the current script. Wraps exit() making testing easier.
$status optional 0 dispatchMethod( string $method , array $params array() )
Calls a method on this object with the given parameters. Provides an OO wrapper for call_user_func_array
$method $params optional array() log( string $msg , integer $type LOG_ERR , null|string|array $scope null )
Convenience method to write a message to CakeLog. See CakeLog::write() for more information on writing to logs.
$msg $type optional LOG_ERR $scope optional null The scope(s) a log message is being created in. See CakeLog::config() for more information on logging scopes.
requestAction( string|array $url , array $extra array() )
Calls a controller's method from any location. Can be used to connect controllers together or tie plugins into a main application. requestAction can be used to return rendered views or fetch the return value from controller actions.
Under the hood this method uses Router::reverse() to convert the $url parameter into a string URL. You should use URL formats that are compatible with Router::reverse()
POST and GET data can be simulated in requestAction. Use $extra['url'] for GET data. The $extra['data'] parameter allows POST data simulation.
$url String or array-based URL. Unlike other URL arrays in CakePHP, this URL will not automatically handle passed and named arguments in the $url parameter.
$extra optional array() if array includes the key "return" it sets the AutoRender to true. Can also be used to submit GET/POST data, and named/passed arguments.
Boolean true or false on success/failure, or contents of rendered action if 'return' is set in $extra.
toString( )
Object-to-string conversion. Each class can override this method as necessary.
public array
Mapping between packages, and their baseclass + package. This is used to generate App::uses() call to autoload base classes if a developer has forgotten to do so.
array(
'Model' => array('Model', 'Model'),
'Behavior' => array('ModelBehavior', 'Model'),
'Controller' => array('Controller', 'Controller'),
'Component' => array('Component', 'Controller'),
'Helper' => array('Helper', 'View')
) public array
class types that methods can be generated for
array(
'Model' => 'Model',
'Controller' => 'Controller',
'Component' => 'Controller/Component',
'Behavior' => 'Model/Behavior',
'Helper' => 'View/Helper'
)
© 2005–2016 The Cake Software Foundation, Inc.
Licensed under the MIT License.
CakePHP is a registered trademark of Cake Software Foundation, Inc.
We are not endorsed by or affiliated with CakePHP.
http://api.cakephp.org/2.8/class-TestTask.html