Skip to content
Permalink
Browse files

Moving test generation to a temporary home

  • Loading branch information...
markstory committed May 15, 2009
1 parent 8a5d6ca commit ad930f277d0eb1966f634f63b07df99d20e9bf26
Showing with 61 additions and 54 deletions.
  1. +0 −54 cake/console/libs/tasks/model.php
  2. +61 −0 cake/console/libs/tasks/test.php
@@ -723,60 +723,6 @@ function bakeTest($className, $useTable = null, $associations = array()) {
$this->Test->plugin = $this->plugin;
$this->Test->connection = $this->connection;
return $this->Test->bake('Model', $className);
$fixtureInc = 'app';
if ($this->plugin) {
$fixtureInc = 'plugin.'.Inflector::underscore($this->plugin);
}
$fixture[] = "'{$fixtureInc}." . Inflector::underscore($className) ."'";
if (!empty($associations)) {
$assoc[] = Set::extract($associations, 'belongsTo.{n}.className');
$assoc[] = Set::extract($associations, 'hasOne.{n}.className');
$assoc[] = Set::extract($associations, 'hasMany.{n}.className');
foreach ($assoc as $key => $value) {
if (is_array($value)) {
foreach ($value as $class) {
$fixture[] = "'{$fixtureInc}." . Inflector::underscore($class) ."'";
}
}
}
}
$fixture = join(", ", $fixture);
$import = $className;
if (isset($this->plugin)) {
$import = $this->plugin . '.' . $className;
}
$out = "App::import('Model', '$import');\n\n";
$out .= "class {$className}TestCase extends CakeTestCase {\n";
$out .= "\tvar \${$className} = null;\n";
$out .= "\tvar \$fixtures = array($fixture);\n\n";
$out .= "\tfunction startTest() {\n";
$out .= "\t\t\$this->{$className} =& ClassRegistry::init('{$className}');\n";
$out .= "\t}\n\n";
$out .= "\tfunction endTest() {\n";
$out .= "\t\tunset(\$this->{$className});\n";
$out .= "\t}\n\n";
$out .= "\tfunction test{$className}Instance() {\n";
$out .= "\t\t\$this->assertTrue(is_a(\$this->{$className}, '{$className}'));\n";
$out .= "\t}\n\n";
$out .= "}\n";
$path = MODEL_TESTS;
if (isset($this->plugin)) {
$pluginPath = 'plugins' . DS . Inflector::underscore($this->plugin) . DS;
$path = APP . $pluginPath . 'tests' . DS . 'cases' . DS . 'models' . DS;
}
$filename = Inflector::underscore($className).'.test.php';
$this->out("\nBaking unit test for $className...");
$header = '$Id';
$content = "<?php \n/* SVN FILE: $header$ */\n/* ". $className ." Test cases generated on: " . date('Y-m-d H:m:s') . " : ". time() . "*/\n{$out}?>";
return $this->createFile($path . $filename, $content);
}
/**
@@ -199,5 +199,66 @@ function __extras($class) {
}
return $extras;
}
/**
* Create a test for a Model object.
*
* @return void
**/
function bakeModelTest($className) {
$fixtureInc = 'app';
if ($this->plugin) {
$fixtureInc = 'plugin.'.Inflector::underscore($this->plugin);
}
$fixture[] = "'{$fixtureInc}." . Inflector::underscore($className) ."'";
if (!empty($associations)) {
$assoc[] = Set::extract($associations, 'belongsTo.{n}.className');
$assoc[] = Set::extract($associations, 'hasOne.{n}.className');
$assoc[] = Set::extract($associations, 'hasMany.{n}.className');
foreach ($assoc as $key => $value) {
if (is_array($value)) {
foreach ($value as $class) {
$fixture[] = "'{$fixtureInc}." . Inflector::underscore($class) ."'";
}
}
}
}
$fixture = join(", ", $fixture);
$import = $className;
if (isset($this->plugin)) {
$import = $this->plugin . '.' . $className;
}
$out = "App::import('Model', '$import');\n\n";
$out .= "class {$className}TestCase extends CakeTestCase {\n";
$out .= "\tvar \${$className} = null;\n";
$out .= "\tvar \$fixtures = array($fixture);\n\n";
$out .= "\tfunction startTest() {\n";
$out .= "\t\t\$this->{$className} =& ClassRegistry::init('{$className}');\n";
$out .= "\t}\n\n";
$out .= "\tfunction endTest() {\n";
$out .= "\t\tunset(\$this->{$className});\n";
$out .= "\t}\n\n";
$out .= "\tfunction test{$className}Instance() {\n";
$out .= "\t\t\$this->assertTrue(is_a(\$this->{$className}, '{$className}'));\n";
$out .= "\t}\n\n";
$out .= "}\n";
$path = MODEL_TESTS;
if (isset($this->plugin)) {
$pluginPath = 'plugins' . DS . Inflector::underscore($this->plugin) . DS;
$path = APP . $pluginPath . 'tests' . DS . 'cases' . DS . 'models' . DS;
}
$filename = Inflector::underscore($className).'.test.php';
$this->out("\nBaking unit test for $className...");
$header = '$Id';
$content = "<?php \n/* SVN FILE: $header$ */\n/* ". $className ." Test cases generated on: " . date('Y-m-d H:m:s') . " : ". time() . "*/\n{$out}?>";
return $this->createFile($path . $filename, $content);
}
}
?>

0 comments on commit ad930f2

Please sign in to comment.
You can’t perform that action at this time.