TestTask Class Info:
- Class Declaration:
class TestTask extends BakeTask
- File name:
- Cake/Console/Command/Task/TestTask.php
- Description:
Task class for creating and updating test files.
- Class Inheritance
- Package
- Cake.Console.Command.Task
Properties:
-
args array
Contains arguments parsed from the command line.
-
classTypes array
class types that methods can be generated for
-
command string
The command (method/task) that is being run.
-
connection string
The db connection being used for baking
-
_fixtures array
Internal list of fixtures that have been added so far.
-
interactive boolean
Flag for interactive mode
-
name string
The name of the shell in camelized.
-
OptionParser ConsoleOptionParser
An instance of ConsoleOptionParser that has been configured for this class.
-
params array
Contains command switches parsed from the command line.
-
path string
path to TESTS directory
-
plugin string
Name of plugin
-
stderr ConsoleOutput
stderr object.
-
stdin ConsoleInput
stdin object
-
stdout ConsoleOutput
stdout object.
-
_taskMap string
Normalized map of tasks.
-
taskNames array
Contains the loaded tasks
-
tasks array
Tasks used.
-
Tasks TaskCollection
Task Collection for the command, used to create Tasks.
-
uses array
Contains models to load and instantiate
Method Summary:
- _addFixture( $name )
- bake( $type, $className )
- buildTestSubject( $type, $class )
- _checkUnitTest( )
- clear( )
- __construct( $stdout = NULL, $stderr = NULL, $stdin = NULL )
- _controllerName( $name )
- _controllerPath( $name )
- createFile( $path, $contents )
- dispatchMethod( $method, $params = array ( ) )
- dispatchShell( )
- _displayHelp( $command )
- err( $message = NULL, $newlines = 1 )
- error( $title, $message = NULL )
- execute( )
- generateConstructor( $type, $fullClassName )
- generateFixtureList( $subject )
- generateUses( $type, $realType, $className )
- __get( $name )
- getClassName( $objectType )
- _getInput( $prompt, $options, $default )
- getObjectType( )
- getOptionParser( )
- getPath( )
- getRealClassName( $type, $class )
- getTestableMethods( $className )
- getUserFixtures( )
- hasMethod( $name )
- hasMockClass( $type )
- hasTask( $task )
- hr( $newlines = 0, $width = 63 )
- in( $prompt, $options = NULL, $default = NULL )
- initialize( )
- _interactive( $type = NULL )
- isLoadableClass( $package, $class )
- _loadModels( )
- loadTasks( )
- log( $msg, $type = 2 )
- mapType( $type, $plugin )
- _mergeVars( $properties, $class, $normalize = true )
- _modelKey( $name )
- _modelName( $name )
- _modelNameFromKey( $key )
- nl( $multiplier = 1 )
- out( $message = NULL, $newlines = 1, $level = 1 )
- _pluginPath( $pluginName )
- _pluralHumanName( $name )
- _pluralName( $name )
- _processController( $subject )
- _processModel( $subject )
- requestAction( $url, $extra = array ( ) )
- runCommand( $command, $argv )
- _set( $properties = array ( ) )
- shortPath( $file )
- _singularHumanName( $name )
- _singularName( $name )
- startup( )
- _stop( $status = 0 )
- testCaseFileName( $type, $className )
- toString( )
- typeCanDetectFixtures( $type )
- _welcome( )
- wrapText( $text, $options = array ( ) )
_addFixture
topAdd classname to the fixture list. Sets the app. or plugin.plugin_name. prefix.
- Parameters:
-
-
string $name required
Name of the Model class that a fixture might be required for.
-
- Method defined in:
- Cake/Console/Command/Task/TestTask.php on line 398
- Return
void
bake
topCompletes final steps for generating data to create test case.
- Parameters:
-
-
string $type required
Type of object to bake test case for ie. Model, Controller
-
string $className required
the 'cake name' for the class ie. Posts for the PostsController
-
- Method defined in:
- Cake/Console/Command/Task/TestTask.php on line 119
- Return
string|boolean
buildTestSubject
topConstruct an instance of the class to be tested. So that fixtures can be detected
- Parameters:
-
-
string $type required
The Type of object you are generating tests for eg. controller
-
string $class required
the Classname of the class the test is being generated for.
-
- Method defined in:
- Cake/Console/Command/Task/TestTask.php on line 255
- Return
object And instance of the class that is going to be tested.
_checkUnitTest
topAction to create a Unit Test
- Method defined in:
- Cake/Console/Shell.php on line 682
- Return
boolean Success
clear
topClear the console
- Method defined in:
- Cake/Console/Shell.php on line 627
- Return
void
- Link
- http://book.cakephp.org/2.0/en/console-and-shells.html#Shell::clear
__construct
topConstructs this Shell instance.
- Parameters:
-
-
ConsoleOutput $stdout optional NULL
A ConsoleOutput object for stdout.
-
ConsoleOutput $stderr optional NULL
A ConsoleOutput object for stderr.
-
ConsoleInput $stdin optional NULL
A ConsoleInput object for stdin.
-
- Method defined in:
- Cake/Console/Shell.php on line 156
_controllerName
topCreates the proper controller plural name for the specified controller class name
- Parameters:
-
-
string $name required
Controller class name
-
- Method defined in:
- Cake/Console/Shell.php on line 729
- Return
string Controller plural name
_controllerPath
topCreates the proper controller path for the specified controller class name
- Parameters:
-
-
string $name required
Controller class name
-
- Method defined in:
- Cake/Console/Shell.php on line 719
- Return
string Path to controller
createFile
topCreates a file at given path
- Parameters:
-
-
string $path required
Where to put the file.
-
string $contents required
Content to put in the file.
-
- Method defined in:
- Cake/Console/Shell.php on line 645
- Return
boolean Success
- Link
- http://book.cakephp.org/2.0/en/console-and-shells.html#Shell::createFile
dispatchMethod
topCalls a method on this object with the given parameters. Provides an OO wrapper
for call_user_func_array
- Parameters:
-
-
string $method required
Name of the method to call
-
array $params optional array ( )
Parameter list to use when calling $method
-
- Method defined in:
- Cake/Core/Object.php on line 110
- Return
mixed Returns the result of the method call
dispatchShell
topDispatch a command to another Shell. Similar to Object::requestAction() but intended for running shells from other shells.
Usage:
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');
- Method defined in:
- Cake/Console/Shell.php on line 326
- Return
mixed The return of the other shell.
- Link
- http://book.cakephp.org/2.0/en/console-and-shells.html#Shell::dispatchShell
_displayHelp
topDisplay the help in the correct format
- Parameters:
-
-
string $command required
-
- Method defined in:
- Cake/Console/Shell.php on line 401
- Return
void
err
topOutputs a single or multiple error messages to stderr. If no parameters are passed outputs just a newline.
- Parameters:
-
-
mixed $message optional NULL
A string or a an array of strings to output
-
integer $newlines optional 1
Number of newlines to append
-
- Method defined in:
- Cake/Console/Shell.php on line 574
- Return
void
- Link
- http://book.cakephp.org/2.0/en/console-and-shells.html#Shell::err
error
topDisplays a formatted error message and exits the application with status code 1
- Parameters:
-
-
string $title required
Title of the error
-
string $message optional NULL
An optional error message
-
- Method defined in:
- Cake/Console/Shell.php on line 612
- Return
void
- Link
- http://book.cakephp.org/2.0/en/console-and-shells.html#Shell::error
execute
topExecution method always used for tasks
- Method defined in:
- Cake/Console/Command/Task/TestTask.php on line 69
- Return
void
generateConstructor
topGenerate a constructor code snippet for the type and classname
- Parameters:
-
-
string $type required
The Type of object you are generating tests for eg. controller
-
string $fullClassName required
The Classname of the class the test is being generated for.
-
- Method defined in:
- Cake/Console/Command/Task/TestTask.php on line 445
- Return
array Constructor snippets for the thing you are building.
generateFixtureList
topGenerate the list of fixtures that will be required to run this test based on loaded models.
- Parameters:
-
-
object $subject required
The object you want to generate fixtures for.
-
- Method defined in:
- Cake/Console/Command/Task/TestTask.php on line 335
- Return
array Array of fixtures to be included in the test.
generateUses
topGenerate the uses() calls for a type & classname
- Parameters:
-
-
string $type required
The Type of object you are generating tests for eg. controller
-
string $realType required
The package name for the class.
-
string $className required
The Classname of the class the test is being generated for.
-
- Method defined in:
- Cake/Console/Command/Task/TestTask.php on line 478
- Return
array An array containing used classes
__get
topOverload get for lazy building of tasks
- Parameters:
-
-
string $name required
-
- Method defined in:
- Cake/Console/Shell.php on line 431
- Return
Shell Object of Task
getClassName
topGet the user chosen Class name for the chosen type
- Parameters:
-
-
string $objectType required
Type of object to list classes for i.e. Model, Controller.
-
- Method defined in:
- Cake/Console/Command/Task/TestTask.php on line 195
- Return
string Class name the user chose.
_getInput
topPrompts the user for input, and returns it.
- Parameters:
-
-
string $prompt required
Prompt text.
-
mixed $options required
Array or string of options.
-
string $default required
Default input value.
-
- Method defined in:
- Cake/Console/Shell.php on line 489
- Return
Either the default value, or the user-provided input.
getObjectType
topInteract with the user and get their chosen type. Can exit the script.
- Method defined in:
- Cake/Console/Command/Task/TestTask.php on line 169
- Return
string Users chosen type.
getOptionParser
topget the option parser.
- Method defined in:
- Cake/Console/Command/Task/TestTask.php on line 515
- Return
void
getPath
topGets the path for output. Checks the plugin property and returns the correct path.
- Method defined in:
- Cake/Console/Command/Task/BakeTask.php on line 67
- Return
string Path to output.
getRealClassName
topGets 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.
- Parameters:
-
-
string $type required
The Type of object you are generating tests for eg. controller
-
string $class required
the Classname of the class the test is being generated for.
-
- Method defined in:
- Cake/Console/Command/Task/TestTask.php on line 275
- Return
string Real classname
getTestableMethods
topGet methods declared in the class given. No parent methods will be returned
- Parameters:
-
-
string $className required
Name of class to look at.
-
- Method defined in:
- Cake/Console/Command/Task/TestTask.php on line 315
- Return
array Array of method names.
getUserFixtures
topInteract with the user to get additional fixtures they want to use.
- Method defined in:
- Cake/Console/Command/Task/TestTask.php on line 414
- Return
array Array of fixtures the user wants to add.
hasMethod
topCheck to see if this shell has a callable method by the given name.
- Parameters:
-
-
string $name required
The method name to check.
-
- Method defined in:
- Cake/Console/Shell.php on line 290
- Return
boolean
- Link
- http://book.cakephp.org/2.0/en/console-and-shells.html#Shell::hasMethod
hasMockClass
topIs a mock class required for this type of test? Controllers require a mock class.
- Parameters:
-
-
string $type required
The type of object tests are being generated for eg. controller.
-
- Method defined in:
- Cake/Console/Command/Task/TestTask.php on line 433
- Return
boolean
hasTask
topCheck to see if this shell has a task with the provided name.
- Parameters:
-
-
string $task required
The task name to check.
-
- Method defined in:
- Cake/Console/Shell.php on line 279
- Return
boolean Success
- Link
- http://book.cakephp.org/2.0/en/console-and-shells.html#Shell::hasTask
hr
topOutputs a series of minus characters to the standard output, acts as a visual separator.
- Parameters:
-
-
integer $newlines optional 0
Number of newlines to pre- and append
-
integer $width optional 63
Width of the line, defaults to 63
-
- Method defined in:
- Cake/Console/Shell.php on line 597
- Return
void
- Link
- http://book.cakephp.org/2.0/en/console-and-shells.html#Shell::hr
in
topPrompts the user for input, and returns it.
- Parameters:
-
-
string $prompt required
Prompt text.
-
mixed $options optional NULL
Array or string of options.
-
string $default optional NULL
Default input value.
-
- Method defined in:
- Cake/Console/Shell.php on line 452
- Return
mixed Either the default value, or the user-provided input.
- Link
- http://book.cakephp.org/2.0/en/console-and-shells.html#Shell::in
initialize
topInitializes the Shell acts as constructor for subclasses allows configuration of tasks prior to shell execution
- Method defined in:
- Cake/Console/Shell.php on line 192
_interactive
topHandles interactive baking
- Parameters:
-
-
string $type optional NULL
-
- Method defined in:
- Cake/Console/Command/Task/TestTask.php on line 93
- Return
string|boolean
isLoadableClass
topCheck if a class with the given package is loaded or can be loaded.
- Parameters:
-
-
string $package required
The package of object you are generating tests for eg. controller
-
string $class required
the Classname of the class the test is being generated for.
-
- Method defined in:
- Cake/Console/Command/Task/TestTask.php on line 242
- Return
boolean
_loadModels
topIf $uses = true Loads AppModel file and constructs AppModel class makes $this->AppModel available to subclasses If public $uses is an array of models will load those models
- Method defined in:
- Cake/Console/Shell.php on line 232
- Return
boolean
loadTasks
topLoads tasks defined in public $tasks
- Method defined in:
- Cake/Console/Shell.php on line 261
- Return
boolean
log
topConvenience method to write a message to CakeLog. See CakeLog::write() for more information on writing to logs.
- Parameters:
-
-
string $msg required
Log message
-
integer $type optional 2
Error type constant. Defined in app/Config/core.php.
-
- Method defined in:
- Cake/Core/Object.php on line 149
- Return
boolean Success of log write
mapType
topMap the types that TestTask uses to concrete types that App::uses can use.
- Parameters:
-
-
string $type required
The type of thing having a test generated.
-
string $plugin required
The plugin name.
-
- Method defined in:
- Cake/Console/Command/Task/TestTask.php on line 296
- Return
string
- Throws
CakeException When invalid object types are requested.
_mergeVars
topMerges 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.
- Parameters:
-
-
array $properties required
The name of the properties to merge.
-
string $class required
The class to merge the property with.
-
boolean $normalize optional true
Set to true to run the properties through Set::normalize() before merging.
-
- Method defined in:
- Cake/Core/Object.php on line 187
- Return
void
_modelKey
topCreates the proper underscored model key for associations
- Parameters:
-
-
string $name required
Model class name
-
- Method defined in:
- Cake/Console/Shell.php on line 749
- Return
string Singular model key
_modelName
topCreates the proper model camelized name (singularized) for the specified name
- Parameters:
-
-
string $name required
Name
-
- Method defined in:
- Cake/Console/Shell.php on line 739
- Return
string Camelized and singularized model name
_modelNameFromKey
topCreates the proper model name from a foreign key
- Parameters:
-
-
string $key required
Foreign key
-
- Method defined in:
- Cake/Console/Shell.php on line 759
- Return
string Model name
nl
topReturns a single or multiple linefeeds sequences.
- Parameters:
-
-
integer $multiplier optional 1
Number of times the linefeed sequence should be repeated
-
- Method defined in:
- Cake/Console/Shell.php on line 585
- Return
string
- Link
- http://book.cakephp.org/2.0/en/console-and-shells.html#Shell::nl
out
topOutputs a single or multiple messages to stdout. If no parameters are passed outputs just a newline.
Output levels
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.
- Parameters:
-
-
mixed $message optional NULL
A string or a an array of strings to output
-
integer $newlines optional 1
Number of newlines to append
-
integer $level optional 1
The message's output level, see above.
-
- Method defined in:
- Cake/Console/Shell.php on line 551
- Return
integer|boolean Returns the number of bytes returned from writing to stdout.
- Link
- http://book.cakephp.org/2.0/en/console-and-shells.html#Shell::out
_pluginPath
topFind the correct path for a plugin. Scans $pluginPaths for the plugin you want.
- Parameters:
-
-
string $pluginName required
Name of the plugin you want ie. DebugKit
-
- Method defined in:
- Cake/Console/Shell.php on line 809
- Return
string $path path to the correct plugin.
_pluralHumanName
topCreates the plural human name used in views
- Parameters:
-
-
string $name required
Controller name
-
- Method defined in:
- Cake/Console/Shell.php on line 799
- Return
string Plural human name
_pluralName
topCreates the plural name for views
- Parameters:
-
-
string $name required
Name to use
-
- Method defined in:
- Cake/Console/Shell.php on line 779
- Return
string Plural name for views
_processController
topProcess all the models attached to a controller and generate a fixture list.
- Parameters:
-
-
Controller $subject required
A controller to pull model names off of.
-
- Method defined in:
- Cake/Console/Command/Task/TestTask.php on line 380
- Return
void
_processModel
topProcess a model recursively and pull out all the model names converting them to fixture names.
- Parameters:
-
-
Model $subject required
A Model class to scan for associations and pull fixtures off of.
-
- Method defined in:
- Cake/Console/Command/Task/TestTask.php on line 352
- Return
void
requestAction
topCalls 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()
Passing POST and GET data
POST and GET data can be simulated in requestAction. Use $extra['url'] for
GET data. The $extra['data'] parameter allows POST data simulation.
- Parameters:
-
-
mixed $url required
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.
-
array $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.
-
- Method defined in:
- Cake/Core/Object.php on line 66
- Return
mixed Boolean true or false on success/failure, or contents of rendered action if 'return' is set in $extra.
runCommand
topRuns the Shell with the provided argv.
Delegates calls to Tasks and resolves methods inside the class. Commands are looked up with the following order:
- Method on the shell.
- Matching task name.
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.
- Parameters:
-
-
string $command required
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. -
array $argv required
Array of arguments to run the shell with. This array should be missing the shell name.
-
- Method defined in:
- Cake/Console/Shell.php on line 355
_set
topAllows setting of multiple properties of the object in a single line of code. Will only set properties that are part of a class declaration.
- Parameters:
-
-
array $properties optional array ( )
An associative array containing properties and corresponding values.
-
- Method defined in:
- Cake/Core/Object.php on line 164
- Return
void
shortPath
topMakes absolute file path easier to read
- Parameters:
-
-
string $file required
Absolute file path
-
- Method defined in:
- Cake/Console/Shell.php on line 707
- Return
string short path
- Link
- http://book.cakephp.org/2.0/en/console-and-shells.html#Shell::shortPath
_singularHumanName
topCreates the singular human name used in views
- Parameters:
-
-
string $name required
Controller name
-
- Method defined in:
- Cake/Console/Shell.php on line 789
- Return
string Singular human name
_singularName
topcreates the singular name for use in views.
- Parameters:
-
-
string $name required
-
- Method defined in:
- Cake/Console/Shell.php on line 769
- Return
string $name
startup
topDisable caching and enable debug for baking. This forces the most current database schema to be used.
- Method defined in:
- Cake/Console/Command/Task/BakeTask.php on line 55
- Return
void
_stop
topStop execution of the current script. Wraps exit() making testing easier.
- Parameters:
-
-
integer|string $status optional 0
see http://php.net/exit for values
-
- Method defined in:
- Cake/Core/Object.php on line 137
- Return
void
testCaseFileName
topMake the filename for the test case. resolve the suffixes for controllers and get the plugin path if needed.
- Parameters:
-
-
string $type required
The Type of object you are generating tests for eg. controller
-
string $className required
the Classname of the class the test is being generated for.
-
- Method defined in:
- Cake/Console/Command/Task/TestTask.php on line 500
- Return
string filename the test should be created on.
toString
topObject-to-string conversion. Each class can override this method as necessary.
- Method defined in:
- Cake/Core/Object.php on line 41
- Return
string The name of this class
typeCanDetectFixtures
topChecks whether the chosen type can find its own fixtures. Currently only model, and controller are supported
- Parameters:
-
-
string $type required
The Type of object you are generating tests for eg. controller
-
- Method defined in:
- Cake/Console/Command/Task/TestTask.php on line 230
- Return
boolean
_welcome
topwrapText
topWrap a block of text. Allows you to set the width, and indenting on a block of text.
Options
widthThe width to wrap to. Defaults to 72wordWrapOnly wrap on words breaks (spaces) Defaults to true.indentIndent the text with the string provided. Defaults to null.
- Parameters:
-
-
string $text required
Text the text to format.
-
mixed $options optional array ( )
Array of options to use, or an integer to wrap the text to.
-
- Method defined in:
- Cake/Console/Shell.php on line 530
- Return
string Wrapped / indented text
- See
- Link
- http://book.cakephp.org/2.0/en/console-and-shells.html#Shell::wrapText
