diff --git a/cake/console/libs/tasks/model.php b/cake/console/libs/tasks/model.php index efa8ad7a8..2203028c4 100644 --- a/cake/console/libs/tasks/model.php +++ b/cake/console/libs/tasks/model.php @@ -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); diff --git a/cake/tests/cases/console/libs/tasks/model.test.php b/cake/tests/cases/console/libs/tasks/model.test.php index addd57007..186ae003c 100644 --- a/cake/tests/cases/console/libs/tasks/model.test.php +++ b/cake/tests/cases/console/libs/tasks/model.test.php @@ -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/')));