|
|
@@ -139,7 +139,8 @@ class TestTask extends BakeTask {
|
|
|
$methods = $this->getTestableMethods($fullClassName);
|
|
|
}
|
|
|
$mock = $this->hasMockClass($type, $fullClassName);
|
|
|
- $construction = $this->generateConstructor($type, $fullClassName);
|
|
|
+ list($preConstruct, $construction, $postConstruct) = $this->generateConstructor($type, $fullClassName);
|
|
|
+ $uses = $this->generateUses($type, $realType, $fullClassName);
|
|
|
|
|
|
$this->out("\n" . __d('cake_console', 'Baking test case for %s %s ...', $className, $type), 1, Shell::QUIET);
|
|
|
|
|
|
@@ -147,7 +148,8 @@ class TestTask extends BakeTask {
|
|
|
$this->Template->set('plugin', $plugin);
|
|
|
$this->Template->set(compact(
|
|
|
'className', 'methods', 'type', 'fullClassName', 'mock',
|
|
|
- 'construction', 'realType'
|
|
|
+ 'realType', 'preConstruct', 'postConstruct', 'construction',
|
|
|
+ 'uses'
|
|
|
));
|
|
|
$out = $this->Template->generate('classes', 'test');
|
|
|
|
|
|
@@ -434,18 +436,49 @@ class TestTask extends BakeTask {
|
|
|
*
|
|
|
* @param string $type The Type of object you are generating tests for eg. controller
|
|
|
* @param string $fullClassName The Classname of the class the test is being generated for.
|
|
|
- * @return string Constructor snippet for the thing you are building.
|
|
|
+ * @return array Constructor snippets for the thing you are building.
|
|
|
*/
|
|
|
public function generateConstructor($type, $fullClassName) {
|
|
|
$type = strtolower($type);
|
|
|
+ $pre = $post = '';
|
|
|
if ($type == 'model') {
|
|
|
- return "ClassRegistry::init('$fullClassName');\n";
|
|
|
+ $construct = "ClassRegistry::init('$fullClassName');\n";
|
|
|
}
|
|
|
if ($type == 'controller') {
|
|
|
$className = substr($fullClassName, 0, strlen($fullClassName) - 10);
|
|
|
- return "new Test$fullClassName();\n\t\t\$this->{$className}->constructClasses();\n";
|
|
|
+ $construct = "new Test$fullClassName();\n";
|
|
|
+ $post = "\$this->{$className}->constructClasses();\n";
|
|
|
}
|
|
|
- return "new $fullClassName();\n";
|
|
|
+ if ($type == 'helper') {
|
|
|
+ $pre = "\$View = new View();\n";
|
|
|
+ $construct = "new {$fullClassName}(\$View);\n";
|
|
|
+ }
|
|
|
+ if ($type == 'component') {
|
|
|
+ $pre = "\$Collection = new ComponentCollection();\n";
|
|
|
+ $construct = "new {$fullClassName}(\$Collection);\n";
|
|
|
+ }
|
|
|
+ return array($pre, $construct, $post);
|
|
|
+ }
|
|
|
+
|
|
|
+/**
|
|
|
+ * Generate the uses() calls for a type & classname
|
|
|
+ *
|
|
|
+ * @param string $type The Type of object you are generating tests for eg. controller
|
|
|
+ * @param string $className The Classname of the class the test is being generated for.
|
|
|
+ * @return array Constructor snippets for the thing you are building.
|
|
|
+ */
|
|
|
+ public function generateUses($type, $realType, $className) {
|
|
|
+ $uses = array();
|
|
|
+ if ($type == 'component') {
|
|
|
+ $uses[] = array('ComponentCollection', 'Controller');
|
|
|
+ $uses[] = array('Component', 'Controller');
|
|
|
+ }
|
|
|
+ if ($type == 'helper') {
|
|
|
+ $uses[] = array('View', 'View');
|
|
|
+ $uses[] = array('Helper', 'View');
|
|
|
+ }
|
|
|
+ $uses[] = array($className, $realType);
|
|
|
+ return $uses;
|
|
|
}
|
|
|
|
|
|
/**
|