Skip to content
Permalink
Browse files

Adding test and fixture generation to ModelTask::all

  • Loading branch information...
markstory committed Jul 15, 2009
1 parent 7e1f9ee commit 80b9692856aec7143fbfa1d9c04da7b5ff4489b9
Showing with 24 additions and 4 deletions.
  1. +7 −3 cake/console/libs/tasks/model.php
  2. +17 −1 cake/tests/cases/console/libs/tasks/model.test.php
@@ -110,6 +110,7 @@ function execute() {
$object = $this->_getModelObject($model);
if ($this->bake($object, false)) {
if ($this->_checkUnitTest()) {
$this->bakeFixture($model);
$this->bakeTest($model);
}
}
@@ -123,12 +124,15 @@ function execute() {
**/
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 @@ function bake($name, $data = array()) {
* @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);
@@ -483,6 +483,19 @@ function testBakeFixture() {
$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 @@ function testExecuteIntoAll() {
$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/')));

0 comments on commit 80b9692

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