Adding test and fixture generation to ModelTask::all

This commit is contained in:
mark_story 2009-07-15 10:00:35 -04:00
parent 7e1f9eeebd
commit 80b9692856
2 changed files with 24 additions and 4 deletions

View file

@ -110,6 +110,7 @@ class ModelTask extends Shell {
$object = $this->_getModelObject($model);
if ($this->bake($object, false)) {
if ($this->_checkUnitTest()) {
$this->bakeFixture($model);
$this->bakeTest($model);
}
}
@ -123,12 +124,15 @@ class ModelTask extends Shell {
**/
function all() {
$this->listAll($this->connection, false);
$unitTestExists = $this->_checkUnitTest();
foreach ($this->__tables as $table) {
$modelClass = Inflector::classify($table);
$this->out(sprintf(__('Baking %s', true), $modelClass));
$object = $this->_getModelObject($modelClass);
$this->bake($object, false);
if ($this->bake($object, false) && $unitTestExists) {
$this->bakeFixture($modelClass);
$this->bakeTest($modelClass);
}
}
}
@ -749,7 +753,7 @@ class ModelTask extends Shell {
* @param string $className Model class name
* @access private
*/
function bakeTest($className, $useTable = null, $associations = array()) {
function bakeTest($className) {
$this->Test->plugin = $this->plugin;
$this->Test->connection = $this->connection;
return $this->Test->bake('Model', $className);

View file

@ -483,6 +483,19 @@ class ModelTaskTest extends CakeTestCase {
$this->assertEqual($this->Task->connection, $this->Task->Fixture->connection);
}
/**
* Ensure that the test object is correctly called.
*
* @return void
**/
function testBakeTest() {
$this->Task->Test->expectAt(0, 'bake', array('Model', 'Article'));
$this->Task->bakeTest('Article');
$this->assertEqual($this->Task->plugin, $this->Task->Test->plugin);
$this->assertEqual($this->Task->connection, $this->Task->Test->connection);
}
/**
* test confirming of associations, and that when an association is hasMany
* a question for the hasOne is also not asked.
@ -670,10 +683,13 @@ class ModelTaskTest extends CakeTestCase {
$this->Task->connection = 'test_suite';
$this->Task->path = '/my/path/';
$this->Task->args = array('all');
$this->Task->setReturnValue('_checkUnitTest', true);
$this->Task->Fixture->expectCallCount('bake', 5);
$this->Task->Test->expectCallCount('bake', 5);
$filename = '/my/path/article.php';
$this->Task->expectAt(0, 'createFile', array($filename, new PatternExpectation('/class Article/')));
$this->Task->execute();
$filename = '/my/path/articles_tag.php';
$this->Task->expectAt(1, 'createFile', array($filename, new PatternExpectation('/class ArticlesTag/')));