From f4dc4bc1ede057ce55dec929f8e1f7f464f08225 Mon Sep 17 00:00:00 2001 From: mark_story Date: Mon, 4 May 2009 23:08:15 -0400 Subject: [PATCH] Adding test cases to FixtureTask. Removing useless param. --- cake/console/libs/tasks/fixture.php | 2 +- .../cases/console/libs/tasks/fixture.test.php | 59 ++++++++++++++++++- 2 files changed, 59 insertions(+), 2 deletions(-) diff --git a/cake/console/libs/tasks/fixture.php b/cake/console/libs/tasks/fixture.php index 8af08bdbafc..52cf69a8b2c 100644 --- a/cake/console/libs/tasks/fixture.php +++ b/cake/console/libs/tasks/fixture.php @@ -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)); diff --git a/cake/tests/cases/console/libs/tasks/fixture.test.php b/cake/tests/cases/console/libs/tasks/fixture.test.php index 0f8f2a3c6af..871efbbb26b 100644 --- a/cake/tests/cases/console/libs/tasks/fixture.test.php +++ b/cake/tests/cases/console/libs/tasks/fixture.test.php @@ -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 * @@ -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; } /** @@ -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 *