Fix issue where omitting a base class would break test generation.

Fixes #3115
This commit is contained in:
mark_story 2012-08-15 20:50:11 -04:00
parent bc2d449487
commit 73f29069de

View file

@ -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.
*
@ -132,6 +147,8 @@ class TestTask extends BakeTask {
} elseif ($this->interactive) {
$this->getUserFixtures();
}
list($baseClass, $baseType) = $this->getBaseType($type);
App::uses($baseClass, $baseType);
App::uses($fullClassName, $realType);
$methods = array();
@ -311,6 +328,20 @@ class TestTask extends BakeTask {
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