From d5ea6b7c2a99bbda503f2247702aa4a6953dcf1b Mon Sep 17 00:00:00 2001 From: "renan.saddam" Date: Fri, 12 Feb 2010 01:57:04 -0200 Subject: [PATCH] Flushing the CR after a model is baked, tests added. Refs #310. --- cake/console/libs/tasks/model.php | 1 + .../cases/console/libs/tasks/model.test.php | 22 +++++++++++++++++-- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/cake/console/libs/tasks/model.php b/cake/console/libs/tasks/model.php index fac911605..95136bb88 100644 --- a/cake/console/libs/tasks/model.php +++ b/cake/console/libs/tasks/model.php @@ -666,6 +666,7 @@ class ModelTask extends Shell { } $out .= "}\n"; $out .= "?>"; + ClassRegistry::flush(); $filename = $this->path . Inflector::underscore($name) . '.php'; $this->out("\nBaking model class for $name..."); return $this->createFile($filename, $out); diff --git a/cake/tests/cases/console/libs/tasks/model.test.php b/cake/tests/cases/console/libs/tasks/model.test.php index f61262f21..0b4fc2af0 100644 --- a/cake/tests/cases/console/libs/tasks/model.test.php +++ b/cake/tests/cases/console/libs/tasks/model.test.php @@ -44,7 +44,7 @@ Mock::generatePartial( ); Mock::generatePartial( 'ModelTask', 'MockModelTask', - array('in', 'out', 'createFile') + array('in', 'out', 'createFile', '_checkUnitTest') ); /** * ModelTaskTest class @@ -53,7 +53,7 @@ Mock::generatePartial( * @subpackage cake.tests.cases.console.libs.tasks */ class ModelTaskTest extends CakeTestCase { - var $fixtures = array('core.datatype', 'core.binary_test'); + var $fixtures = array('core.datatype', 'core.binary_test', 'core.article'); /** * setUp method * @@ -88,5 +88,23 @@ class ModelTaskTest extends CakeTestCase { $result = $this->Task->fixture('BinaryTest'); $this->assertPattern("/'data' => 'Lorem ipsum dolor sit amet'/", $result); } +/** + * test that execute passes runs bake depending with named model. + * + * @return void + * @access public + */ + function testBakeModel() { + $this->Task->connection = 'test_suite'; + $this->Task->path = '/my/path/'; + $filename = '/my/path/article.php'; + $this->Task->setReturnValue('_checkUnitTest', 1); + $this->Task->expectAt(0, 'createFile', array($filename, new PatternExpectation('/class Article extends AppModel/'))); + $model =& new Model(array('name' => 'Article', 'table' => 'articles', 'ds' => 'test_suite')); + $this->Task->bake($model); + + $this->assertEqual(count(ClassRegistry::keys()), 0); + $this->assertEqual(count(ClassRegistry::mapKeys()), 0); + } } ?> \ No newline at end of file