Skip to content

Commit

Permalink
Fix issue where omitting a base class would break test generation.
Browse files Browse the repository at this point in the history
Fixes #3115
  • Loading branch information
markstory committed Aug 16, 2012
1 parent bc2d449 commit 73f2906
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions lib/Cake/Console/Command/Task/TestTask.php
Expand Up @@ -54,6 +54,21 @@ class TestTask extends BakeTask {
'Helper' => 'View/Helper'
);

/**
* 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.
*
* @var array
*/
public $baseTypes = array(
'Model' => array('Model', 'Model'),
'Behavior' => array('ModelBehavior', 'Model'),
'Controller' => array('Controller', 'Controller'),
'Component' => array('Component', 'Controller'),
'Helper' => array('Helper', 'View')
);

/**
* Internal list of fixtures that have been added so far.
*
Expand Down Expand Up @@ -132,6 +147,8 @@ public function bake($type, $className) {
} elseif ($this->interactive) {
$this->getUserFixtures();
}
list($baseClass, $baseType) = $this->getBaseType($type);
App::uses($baseClass, $baseType);
App::uses($fullClassName, $realType);

$methods = array();
Expand Down Expand Up @@ -311,6 +328,20 @@ public function mapType($type, $plugin) {
return $real;
}

/**
* Get the base class and package name for a given type.
*
* @param string $package The package the class having a test
* generated for is in.
* @return array Array of class, type)
*/
public function getBaseType($type) {
if (empty($this->baseTypes[$type])) {
throw new CakeException(__d('cake_dev', 'Invalid package name'));
}
return $this->baseTypes[$type];
}

/**
* Get methods declared in the class given.
* No parent methods will be returned
Expand Down

0 comments on commit 73f2906

Please sign in to comment.