From 62dee78ca5ab69356a026d89e025c0b2d762886b Mon Sep 17 00:00:00 2001 From: euromark Date: Wed, 8 Aug 2012 14:15:28 +0200 Subject: [PATCH] adding models for schema generate --- lib/Cake/Console/Command/SchemaShell.php | 10 ++++-- .../Case/Console/Command/SchemaShellTest.php | 35 +++++++++++++++++++ 2 files changed, 43 insertions(+), 2 deletions(-) diff --git a/lib/Cake/Console/Command/SchemaShell.php b/lib/Cake/Console/Command/SchemaShell.php index eb3321500..4fed54b7f 100644 --- a/lib/Cake/Console/Command/SchemaShell.php +++ b/lib/Cake/Console/Command/SchemaShell.php @@ -127,7 +127,9 @@ class SchemaShell extends AppShell { $this->out(__d('cake_console', 'Generating Schema...')); $options = array(); if ($this->params['force']) { - $options = array('models' => false); + $options['models'] = false; + } elseif (!empty($this->params['models'])) { + $options['models'] = String::tokenize($this->params['models']); } $snapshot = false; @@ -464,6 +466,10 @@ class SchemaShell extends AppShell { 'short' => 's', 'help' => __d('cake_console', 'Snapshot number to use/make.') ); + $models = array( + 'short' => 'm', + 'help' => __d('cake_console', 'Specify models as comma separated list.'), + ); $dry = array( 'help' => __d('cake_console', 'Perform a dry run on create and update commands. Queries will be output instead of run.'), 'boolean' => true @@ -489,7 +495,7 @@ class SchemaShell extends AppShell { ))->addSubcommand('generate', array( 'help' => __d('cake_console', 'Reads from --connection and writes to --path. Generate snapshots with -s'), 'parser' => array( - 'options' => compact('plugin', 'path', 'file', 'name', 'connection', 'snapshot', 'force'), + 'options' => compact('plugin', 'path', 'file', 'name', 'connection', 'snapshot', 'force', 'models'), 'arguments' => array( 'snapshot' => array('help' => __d('cake_console', 'Generate a snapshot.')) ) diff --git a/lib/Cake/Test/Case/Console/Command/SchemaShellTest.php b/lib/Cake/Test/Case/Console/Command/SchemaShellTest.php index 7d2175389..3c3be73aa 100644 --- a/lib/Cake/Test/Case/Console/Command/SchemaShellTest.php +++ b/lib/Cake/Test/Case/Console/Command/SchemaShellTest.php @@ -362,6 +362,41 @@ class SchemaShellTest extends CakeTestCase { CakePlugin::unload(); } +/** + * test generate with specific models + * + * @return void + */ + public function testGenerateModels() { + App::build(array( + 'Plugin' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'Plugin' . DS) + ), App::RESET); + CakePlugin::load('TestPlugin'); + + $this->db->cacheSources = false; + $this->Shell->params = array( + 'plugin' => 'TestPlugin', + 'connection' => 'test', + 'models' => 'TestPluginComment', + 'force' => false, + 'overwrite' => true + ); + $this->Shell->startup(); + $this->Shell->Schema->path = TMP . 'tests' . DS; + + $this->Shell->generate(); + $this->file = new File(TMP . 'tests' . DS . 'schema.php'); + $contents = $this->file->read(); + + $this->assertRegExp('/class TestPluginSchema/', $contents); + $this->assertRegExp('/public \$test_plugin_comments/', $contents); + $this->assertNotRegExp('/public \$authors/', $contents); + $this->assertNotRegExp('/public \$auth_users/', $contents); + $this->assertNotRegExp('/public \$posts/', $contents); + CakePlugin::unload(); + } + + /** * Test schema run create with no table args. *