Task class for creating and updating test files.
_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 string|boolean
_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
string|boolean
buildTestSubject( string $type , string $class )
Construct an instance of the class to be tested. So that fixtures can be detected
$type
$class
object
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
array
generateFixtureList( object $subject )
Generate the list of fixtures that will be required to run this test based on loaded models.
$subject
array
generateUses( string $type , string $realType , string $className )
Generate the uses() calls for a type & class name
$type
$realType
$className
array
getBaseType( string $type )
Get the base class and package name for a given type.
$type
array
CakeException
getClassName( string $objectType )
Get the user chosen Class name for the chosen type
$objectType
string
getObjectType( )
Interact with the user and get their chosen type. Can exit the script.
string
getOptionParser( )
Gets the option parser instance and configures it.
ConsoleOptionParser
Shell::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
string
getTestableMethods( string $className )
Get methods declared in the class given. No parent methods will be returned
$className
array
getUserFixtures( )
Interact with the user to get additional fixtures they want to use.
array
hasMockClass( string $type )
Is a mock class required for this type of test? Controllers require a mock class.
$type
boolean
isLoadableClass( string $package , string $class )
Check if a class with the given package is loaded or can be loaded.
$package
$class
boolean
mapType( string $type , string $plugin )
Map the types that TestTask uses to concrete types that App::uses can use.
$type
$plugin
string
CakeException
testCaseFileName( 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
string
typeCanDetectFixtures( string $type )
Checks whether the chosen type can find its own fixtures. Currently only model, and controller are supported
$type
boolean
getPath( )
Gets the path for output. Checks the plugin property and returns the correct path.
string
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
boolean
_controllerName( string $name )
Creates the proper controller plural name for the specified controller class name
$name
string
_controllerPath( string $name )
Creates the proper controller path for the specified controller class name
$name
string
_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
Either
_loadModels( )
If $uses is an array load each of the models in the array
boolean
_modelKey( string $name )
Creates the proper underscored model key for associations
$name
string
_modelName( string $name )
Creates the proper model camelized name (singularized) for the specified name
$name
string
_modelNameFromKey( string $key )
Creates the proper model name from a foreign key
$key
string
_pluginPath( string $pluginName )
Find the correct path for a plugin. Scans $pluginPaths for the plugin you want.
$pluginName
string
_pluralHumanName( string $name )
Creates the plural human name used in views
$name
string
_pluralName( string $name )
Creates the plural name for views
$name
string
_singularHumanName( string $name )
Creates the singular human name used in views
$name
string
_singularName( string $name )
creates the singular name for use in views.
$name
string
_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
boolean
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');
mixed
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
boolean
hasTask( string $task )
Check to see if this shell has a task with the provided name.
$task
boolean
hr( 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 mixed
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 mixed
MissingModelException
nl( integer $multiplier 1 )
Returns a single or multiple linefeeds sequences.
$multiplier
optional 1 string
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
integer|boolean
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 integer|boolean
param( string $name )
Safely access the values in $this->params.
$name
string|boolean|null
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
main()
method, that will be called instead.$argv
shortPath( string $file )
Makes absolute file path easier to read
$file
string
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() string
CakeText::wrap()
_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() mixed
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 boolean
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
$extra
optional array() mixed
toString( )
Object-to-string conversion. Each class can override this method as necessary.
string
CODE_ERROR, NORMAL, QUIET, VERBOSE |
public ConsoleOptionParser
An instance of ConsoleOptionParser that has been configured for this class.
protected integer
The number of bytes last written to the output stream used when overwriting the previous message.
public string
This shell's primary model class name, the first model in the $uses property
null
public array
Contains models to load and instantiate
array()
© 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.7/class-TestTask.html