Skip to content

Commit

Permalink
Adding test cases to FixtureTask.
Browse files Browse the repository at this point in the history
Removing useless param.
  • Loading branch information
markstory committed May 5, 2009
1 parent e21cc3d commit f4dc4bc
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 2 deletions.
2 changes: 1 addition & 1 deletion cake/console/libs/tasks/fixture.php
Expand Up @@ -110,7 +110,7 @@ function all() {
*
* @access private
*/
function __interactive($modelName = false) {
function __interactive() {
$this->interactive = true;
$this->hr();
$this->out(sprintf("Bake Fixture\nPath: %s", $this->path));
Expand Down
59 changes: 58 additions & 1 deletion cake/tests/cases/console/libs/tasks/fixture.test.php
Expand Up @@ -50,6 +50,11 @@
'FixtureTask', 'MockFixtureTask',
array('in', 'out', 'err', 'createFile', '_stop')
);

Mock::generatePartial(
'Shell', 'MockFixtureModelTask',
array('in', 'out', 'err', 'createFile', '_stop', 'getName', 'getTable', 'listAll')
);
/**
* FixtureTaskTest class
*
Expand All @@ -71,7 +76,8 @@ class FixtureTaskTest extends CakeTestCase {
*/
function startTest() {
$this->Dispatcher =& new TestFixtureTaskMockShellDispatcher();
$this->Task =& new MockFixtureTask($this->Dispatcher);
$this->Task =& new MockFixtureTask();
$this->Task->Model =& new MockFixtureModelTask();
$this->Task->Dispatch = new $this->Dispatcher;
}
/**
Expand Down Expand Up @@ -116,6 +122,57 @@ function testImportOptions() {
$expected = array();
$this->assertEqual($result, $expected);
}
/**
* test that execute passes runs bake depending with named model.
*
* @return void
**/
function testExecuteWithNamedModel() {
$this->Task->connection = 'test_suite';
$this->Task->path = '/my/path/';
$this->Task->args = array('article');
$filename = '/my/path/article_fixture.php';
$this->Task->expectAt(0, 'createFile', array($filename, new PatternExpectation('/class ArticleFixture/')));
$this->Task->execute();
}

/**
* test that execute runs all() when args[0] = all
*
* @return void
**/
function testExecuteIntoAll() {
$this->Task->connection = 'test_suite';
$this->Task->path = '/my/path/';
$this->Task->args = array('all');
$this->Task->Model->setReturnValue('listAll', array('articles', 'comments'));

$filename = '/my/path/article_fixture.php';
$this->Task->expectAt(0, 'createFile', array($filename, new PatternExpectation('/class ArticleFixture/')));
$this->Task->execute();

$filename = '/my/path/comment_fixture.php';
$this->Task->expectAt(1, 'createFile', array($filename, new PatternExpectation('/class CommentFixture/')));
$this->Task->execute();
}

/**
* test interactive mode of execute
*
* @return void
**/
function testExecuteInteractive() {
$this->Task->connection = 'test_suite';
$this->Task->path = '/my/path/';

$this->Task->setReturnValue('in', 'y');
$this->Task->Model->setReturnValue('getName', 'Article');
$this->Task->Model->setReturnValue('getTable', 'articles', array('Article'));

$filename = '/my/path/article_fixture.php';
$this->Task->expectAt(0, 'createFile', array($filename, new PatternExpectation('/class ArticleFixture/')));
$this->Task->execute();
}
/**
* Test that bake works
*
Expand Down

0 comments on commit f4dc4bc

Please sign in to comment.