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

  • Overview
  • Tree
  • Deprecated
  • Version:
    • 2.4
      • 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

  • BakeTask
  • ControllerTask
  • DbConfigTask
  • ExtractTask
  • FixtureTask
  • ModelTask
  • PluginTask
  • ProjectTask
  • TemplateTask
  • TestTask
  • ViewTask

Class TestTask

Task class for creating and updating test files.

AppShell
Extended by BakeTask
Extended by TestTask
Package: Cake\Console\Command\Task
Copyright: Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
License: MIT License
Location: Cake/Console/Command/Task/TestTask.php

Properties summary

  • $_fixtures protected
    array
    Internal list of fixtures that have been added so far.
  • $baseTypes 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.

  • $classTypes public
    array
    class types that methods can be generated for
  • $path public
    string
    path to TESTS directory
  • $tasks public
    array
    Tasks used.

Inherited Properties

  • connection, interactive, plugin

Method Summary

  • _addFixture() protected

    Add class name to the fixture list. Sets the app. or plugin.plugin_name. prefix.

  • _interactive() protected
    Handles interactive baking
  • _processController() protected

    Process all the models attached to a controller and generate a fixture list.

  • _processModel() protected

    Process a model recursively and pull out all the model names converting them to fixture names.

  • bake() public
    Completes final steps for generating data to create test case.
  • buildTestSubject() public

    Construct an instance of the class to be tested. So that fixtures can be detected

  • execute() public
    Execution method always used for tasks
  • generateConstructor() public
    Generate a constructor code snippet for the type and class name
  • generateFixtureList() public

    Generate the list of fixtures that will be required to run this test based on loaded models.

  • generateUses() public
    Generate the uses() calls for a type & class name
  • getBaseType() public
    Get the base class and package name for a given type.
  • getClassName() public
    Get the user chosen Class name for the chosen type
  • getObjectType() public
    Interact with the user and get their chosen type. Can exit the script.
  • getOptionParser() public
    get the option parser.
  • getRealClassName() public

    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.

  • getTestableMethods() public

    Get methods declared in the class given. No parent methods will be returned

  • getUserFixtures() public
    Interact with the user to get additional fixtures they want to use.
  • hasMockClass() public

    Is a mock class required for this type of test? Controllers require a mock class.

  • isLoadableClass() public
    Check if a class with the given package is loaded or can be loaded.
  • mapType() public
    Map the types that TestTask uses to concrete types that App::uses can use.
  • testCaseFileName() public

    Make the filename for the test case. resolve the suffixes for controllers and get the plugin path if needed.

  • typeCanDetectFixtures() public

    Checks whether the chosen type can find its own fixtures. Currently only model, and controller are supported

Method Detail

_addFixture() protected ¶

_addFixture( string $name )

Add class name to the fixture list. Sets the app. or plugin.plugin_name. prefix.

Parameters
string $name
Name of the Model class that a fixture might be required for.

_interactive() protected ¶

_interactive( string $type = null )

Handles interactive baking

Parameters
string $type optional null
Returns
string|boolean

_processController() protected ¶

_processController( Controller $subject )

Process all the models attached to a controller and generate a fixture list.

Parameters
Controller $subject
A controller to pull model names off of.

_processModel() protected ¶

_processModel( Model $subject )

Process a model recursively and pull out all the model names converting them to fixture names.

Parameters
Model $subject
A Model class to scan for associations and pull fixtures off of.

bake() public ¶

bake( string $type , string $className )

Completes final steps for generating data to create test case.

Parameters
string $type
Type of object to bake test case for ie. Model, Controller
string $className
the 'cake name' for the class ie. Posts for the PostsController
Returns
string|boolean

buildTestSubject() public ¶

buildTestSubject( string $type , string $class )

Construct an instance of the class to be tested. So that fixtures can be detected

Parameters
string $type
The Type of object you are generating tests for eg. controller
string $class
the Classname of the class the test is being generated for.
Returns
object
And instance of the class that is going to be tested.

execute() public ¶

execute( )

Execution method always used for tasks

Overrides
BakeTask::execute()

generateConstructor() public ¶

generateConstructor( string $type , string $fullClassName , string $plugin )

Generate a constructor code snippet for the type and class name

Parameters
string $type
The Type of object you are generating tests for eg. controller
string $fullClassName
The Classname of the class the test is being generated for.
string $plugin
The plugin name.
Returns
array
Constructor snippets for the thing you are building.

generateFixtureList() public ¶

generateFixtureList( object $subject )

Generate the list of fixtures that will be required to run this test based on loaded models.

Parameters
object $subject
The object you want to generate fixtures for.
Returns
array
Array of fixtures to be included in the test.

generateUses() public ¶

generateUses( string $type , string $realType , string $className )

Generate the uses() calls for a type & class name

Parameters
string $type
The Type of object you are generating tests for eg. controller
string $realType
The package name for the class.
string $className
The Classname of the class the test is being generated for.
Returns
array
An array containing used classes

getBaseType() public ¶

getBaseType( string $type )

Get the base class and package name for a given type.

Parameters
string $type

The type the class having a test generated for is in.

Returns
array
Array of (class, type)
Throws
CakeException
on invalid types.

getClassName() public ¶

getClassName( string $objectType )

Get the user chosen Class name for the chosen type

Parameters
string $objectType
Type of object to list classes for i.e. Model, Controller.
Returns
string
Class name the user chose.

getObjectType() public ¶

getObjectType( )

Interact with the user and get their chosen type. Can exit the script.

Returns
string
Users chosen type.

getOptionParser() public ¶

getOptionParser( )

get the option parser.

getRealClassName() public ¶

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.

Parameters
string $type
The Type of object you are generating tests for eg. controller
string $class
the Classname of the class the test is being generated for.
Returns
string
Real class name

getTestableMethods() public ¶

getTestableMethods( string $className )

Get methods declared in the class given. No parent methods will be returned

Parameters
string $className
Name of class to look at.
Returns
array
Array of method names.

getUserFixtures() public ¶

getUserFixtures( )

Interact with the user to get additional fixtures they want to use.

Returns
array
Array of fixtures the user wants to add.

hasMockClass() public ¶

hasMockClass( string $type )

Is a mock class required for this type of test? Controllers require a mock class.

Parameters
string $type
The type of object tests are being generated for eg. controller.
Returns
boolean

isLoadableClass() public ¶

isLoadableClass( string $package , string $class )

Check if a class with the given package is loaded or can be loaded.

Parameters
string $package
The package of object you are generating tests for eg. controller
string $class
the Classname of the class the test is being generated for.
Returns
boolean

mapType() public ¶

mapType( string $type , string $plugin )

Map the types that TestTask uses to concrete types that App::uses can use.

Parameters
string $type
The type of thing having a test generated.
string $plugin
The plugin name.
Returns
string
Throws
CakeException
When invalid object types are requested.

testCaseFileName() public ¶

testCaseFileName( string $type , string $className )

Make the filename for the test case. resolve the suffixes for controllers and get the plugin path if needed.

Parameters
string $type
The Type of object you are generating tests for eg. controller
string $className
the Classname of the class the test is being generated for.
Returns
string
filename the test should be created on.

typeCanDetectFixtures() public ¶

typeCanDetectFixtures( string $type )

Checks whether the chosen type can find its own fixtures. Currently only model, and controller are supported

Parameters
string $type
The Type of object you are generating tests for eg. controller
Returns
boolean

Methods inherited from BakeTask

getPath() public ¶

getPath( )

Gets the path for output. Checks the plugin property and returns the correct path.

Returns
string
Path to output.

startup() public ¶

startup( )

Disable caching and enable debug for baking. This forces the most current database schema to be used.

Properties detail

$_fixtures ¶

protected array

Internal list of fixtures that have been added so far.

array()

$baseTypes ¶

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')
)

$classTypes ¶

public array

class types that methods can be generated for

array(
    'Model' => 'Model',
    'Controller' => 'Controller',
    'Component' => 'Controller/Component',
    'Behavior' => 'Model/Behavior',
    'Helper' => 'View/Helper'
)

$path ¶

public string

path to TESTS directory

TESTS

$tasks ¶

public array

Tasks used.

array('Template')
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