PHP Class Bake\Shell\Task\TestTask

Inheritance: extends Bake\Shell\Task\BakeTask
ファイルを表示 Open project: cakephp/bake Class Usage Examples

Public Properties

Property Type Description
$classSuffixes array class types that methods can be generated for
$classTypes array class types that methods can be generated for
$tasks array Tasks used.

Protected Properties

Property Type Description
$_fixtures array Internal list of fixtures that have been added so far.

Public Methods

Method Description
bake ( string $type, string $className ) : string | boolean Completes final steps for generating data to create test case.
buildTestSubject ( string $type, string $class ) : object Construct an instance of the class to be tested.
generateConstructor ( string $type, string $fullClassName ) : array Generate a constructor code snippet for the type and class name
generateFixtureList ( object $subject ) : array Generate the list of fixtures that will be required to run this test based on loaded models.
generateProperties ( string $type, string $subject, string $fullClassName ) : array Generate property info for the type and class name
generateUses ( string $type, string $fullClassName ) : array Generate the uses() calls for a type & class name
getOptionParser ( ) : Cake\Console\ConsoleOptionParser Gets the option parser instance and configures it.
getPath ( ) : string Get the file path.
getRealClassName ( string $type, string $class ) : string 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.
getSubspacePath ( string $type ) : string Gets the subspace path for a test.
getTestableMethods ( string $className ) : array Get methods declared in the class given.
hasMockClass ( string $type ) : boolean Is a mock class required for this type of test? Controllers require a mock class.
main ( string | null $type = null, string | null $name = null ) : void | array Execution method always used for tasks
mapType ( string $type ) : string Map the types that TestTask uses to concrete types that App::className can use.
outputClassChoices ( string $type ) : array Output a list of possible classnames you might want to generate a test for.
outputTypeChoices ( ) : void Output a list of class types you can bake a test for.
testCaseFileName ( string $type, string $className ) : string Make the filename for the test case. resolve the suffixes for controllers and get the plugin path if needed.
typeCanDetectFixtures ( string $type ) : boolean Checks whether the chosen type can find its own fixtures.

Protected Methods

Method Description
_addFixture ( string $name ) : void Add class name to the fixture list.
_bakeAll ( string $type ) : void
_getClassOptions ( string $namespace ) : array Get the possible classes for a given type.
_processController ( Controller $subject ) : void Process all the models attached to a controller and generate a fixture list.
_processModel ( Model $subject ) : void Process a model recursively and pull out all the model names converting them to fixture names.

Method Details

_addFixture() protected method

Sets the app. or plugin.plugin_name. prefix.
protected _addFixture ( string $name ) : void
$name string Name of the Model class that a fixture might be required for.
return void

_bakeAll() protected method

protected _bakeAll ( string $type ) : void
$type string The typename to get bake all classes for.
return void

_getClassOptions() protected method

Get the possible classes for a given type.
protected _getClassOptions ( string $namespace ) : array
$namespace string The namespace fragment to look for classes in.
return array

_processController() protected method

Process all the models attached to a controller and generate a fixture list.
protected _processController ( Controller $subject ) : void
$subject Cake\Controller\Controller A controller to pull model names off of.
return void

_processModel() protected method

Process a model recursively and pull out all the model names converting them to fixture names.
protected _processModel ( Model $subject ) : void
$subject Model A Model class to scan for associations and pull fixtures off of.
return void

bake() public method

Completes final steps for generating data to create test case.
public bake ( string $type, string $className ) : string | boolean
$type string Type of object to bake test case for ie. Model, Controller
$className string the 'cake name' for the class ie. Posts for the PostsController
return string | boolean

buildTestSubject() public method

So that fixtures can be detected
public buildTestSubject ( string $type, string $class ) : object
$type string The type of object you are generating tests for eg. controller
$class string The classname of the class the test is being generated for.
return object And instance of the class that is going to be tested.

generateConstructor() public method

Generate a constructor code snippet for the type and class name
public generateConstructor ( string $type, string $fullClassName ) : array
$type string The Type of object you are generating tests for eg. controller
$fullClassName string The full classname of the class the test is being generated for.
return array Constructor snippets for the thing you are building.

generateFixtureList() public method

Generate the list of fixtures that will be required to run this test based on loaded models.
public generateFixtureList ( object $subject ) : array
$subject object The object you want to generate fixtures for.
return array Array of fixtures to be included in the test.

generateProperties() public method

The generated property info consists of a set of arrays that hold the following keys: - description (the property description) - type (the property docblock type) - name (the property name) - value (optional - the properties initial value)
public generateProperties ( string $type, string $subject, string $fullClassName ) : array
$type string The Type of object you are generating tests for eg. controller
$subject string The name of the test subject.
$fullClassName string The Classname of the class the test is being generated for.
return array An array containing property info

generateUses() public method

Generate the uses() calls for a type & class name
public generateUses ( string $type, string $fullClassName ) : array
$type string The Type of object you are generating tests for eg. controller
$fullClassName string The Classname of the class the test is being generated for.
return array An array containing used classes

getOptionParser() public method

Gets the option parser instance and configures it.
public getOptionParser ( ) : Cake\Console\ConsoleOptionParser
return Cake\Console\ConsoleOptionParser

getPath() public method

Get the file path.
public getPath ( ) : string
return string

getRealClassName() public method

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.
public getRealClassName ( string $type, string $class ) : string
$type string The Type of object you are generating tests for eg. controller.
$class string the Classname of the class the test is being generated for.
return string Real class name

getSubspacePath() public method

Gets the subspace path for a test.
public getSubspacePath ( string $type ) : string
$type string The Type of object you are generating tests for eg. controller.
return string Path of the subspace.

getTestableMethods() public method

No parent methods will be returned
public getTestableMethods ( string $className ) : array
$className string Name of class to look at.
return array Array of method names.

hasMockClass() public method

Is a mock class required for this type of test? Controllers require a mock class.
public hasMockClass ( string $type ) : boolean
$type string The type of object tests are being generated for eg. controller.
return boolean

main() public method

Execution method always used for tasks
public main ( string | null $type = null, string | null $name = null ) : void | array
$type string | null Class type.
$name string | null Name.
return void | array

mapType() public method

Map the types that TestTask uses to concrete types that App::className can use.
public mapType ( string $type ) : string
$type string The type of thing having a test generated.
return string

outputClassChoices() public method

Output a list of possible classnames you might want to generate a test for.
public outputClassChoices ( string $type ) : array
$type string The typename to get classes for.
return array

outputTypeChoices() public method

Output a list of class types you can bake a test for.
public outputTypeChoices ( ) : void
return void

testCaseFileName() public method

Make the filename for the test case. resolve the suffixes for controllers and get the plugin path if needed.
public testCaseFileName ( string $type, string $className ) : string
$type string The Type of object you are generating tests for eg. controller
$className string The fully qualified classname of the class the test is being generated for.
return string filename the test should be created on.

typeCanDetectFixtures() public method

Currently only model, and controller are supported
public typeCanDetectFixtures ( string $type ) : boolean
$type string The Type of object you are generating tests for eg. controller
return boolean

Property Details

$_fixtures protected_oe property

Internal list of fixtures that have been added so far.
protected array $_fixtures
return array

$classSuffixes public_oe property

class types that methods can be generated for
public array $classSuffixes
return array

$classTypes public_oe property

class types that methods can be generated for
public array $classTypes
return array

$tasks public_oe property

Tasks used.
public array $tasks
return array