diff --git a/src/Console/Command/Task/ModelTask.php b/src/Console/Command/Task/ModelTask.php index 9397b39ff08..7d6eb262ef8 100644 --- a/src/Console/Command/Task/ModelTask.php +++ b/src/Console/Command/Task/ModelTask.php @@ -504,7 +504,7 @@ public function bakeEntity($model, $data = []) { if (!empty($this->params['no-entity'])) { return; } - $name = $model->alias(); + $name = Inflector::singularize($model->alias()); $ns = Configure::read('App.namespace'); $pluginPath = ''; @@ -514,7 +514,7 @@ public function bakeEntity($model, $data = []) { } $data += [ - 'name' => Inflector::singularize($name), + 'name' => $name, 'namespace' => $ns, 'plugin' => $this->plugin, 'pluginPath' => $pluginPath, @@ -568,7 +568,7 @@ public function bakeTable($model, $data = []) { $out = $this->Template->generate('classes', 'table'); $path = $this->getPath(); - $filename = $path . 'Table/' . $name . '.php'; + $filename = $path . 'Table/' . $name . 'Table.php'; $this->out("\n" . __d('cake_console', 'Baking table class for %s...', $name), 1, Shell::QUIET); $this->createFile($filename, $out); TableRegistry::clear(); diff --git a/tests/TestCase/Console/Command/Task/ModelTaskTest.php b/tests/TestCase/Console/Command/Task/ModelTaskTest.php index 3014129662e..e7bdb6f3a24 100644 --- a/tests/TestCase/Console/Command/Task/ModelTaskTest.php +++ b/tests/TestCase/Console/Command/Task/ModelTaskTest.php @@ -570,28 +570,48 @@ public function testBakeEntityFields() { $this->assertContains("protected \$_accessible = ['title', 'body', 'published']", $result); } +/** + * test bake() with a -plugin param + * + * @return void + */ + public function testBakeTableWithPlugin() { + $this->Task->plugin = 'ControllerTest'; + + // fake plugin path + Plugin::load('ControllerTest', array('path' => APP . 'Plugin/ControllerTest/')); + $path = APP . 'Plugin/ControllerTest/Model/Table/BakeArticlesTable.php'; + $this->Task->expects($this->once())->method('createFile') + ->with($path, $this->logicalAnd( + $this->stringContains('namespace ControllerTest\\Model\\Table;'), + $this->stringContains('use Cake\\ORM\\Table;'), + $this->stringContains('class BakeArticlesTable extends Table {') + )); + $model = TableRegistry::get('BakeArticles'); + $this->Task->bakeTable($model); + } /** * test bake() with a -plugin param * * @return void */ - public function testBakeWithPlugin() { - $this->markTestIncomplete('Not done here yet'); + public function testBakeEntityWithPlugin() { $this->Task->plugin = 'ControllerTest'; - //fake plugin path + // fake plugin path Plugin::load('ControllerTest', array('path' => APP . 'Plugin/ControllerTest/')); - $path = APP . 'Plugin/ControllerTest/Model/BakeArticle.php'; + $path = APP . 'Plugin/ControllerTest/Model/Entity/BakeArticle.php'; $this->Task->expects($this->once())->method('createFile') - ->with($path, $this->stringContains('BakeArticle extends ControllerTestAppModel')); - - $result = $this->Task->bake('BakeArticle', array(), array()); - $this->assertContains("App::uses('ControllerTestAppModel', 'ControllerTest.Model');", $result); + ->with($path, $this->logicalAnd( + $this->stringContains('namespace ControllerTest\\Model\\Entity;'), + $this->stringContains('use Cake\\ORM\\Entity;'), + $this->stringContains('class BakeArticle extends Entity {') + )); - $this->assertEquals(count(ClassRegistry::keys()), 0); - $this->assertEquals(count(ClassRegistry::mapKeys()), 0); + $model = TableRegistry::get('BakeArticles'); + $this->Task->bakeEntity($model); } /**