Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Making schema dump work with plugins.

Adding tests.
Making output of dump file more flexible.
  • Loading branch information...
commit 2dc0fbf3b3a0bdb87d7bfd69edb4370aae4a8b18 1 parent 75f2106
@markstory markstory authored
View
28 cake/console/libs/schema.php
@@ -192,8 +192,10 @@ function generate() {
/**
* Dump Schema object to sql file
- * if first arg == write, file will be written to sql file
- * or it will output sql
+ * Use the `write` param to enable and control SQL file output location.
+ * Simply using -write will write the sql file to the same dir as the schema file.
+ * If -write contains a full path name the file will be saved there. If -write only
+ * contains no DS, that will be used as the file name, in the same dir as the schema file.
*
* @access public
*/
@@ -204,11 +206,11 @@ function dump() {
$this->err(__('Schema could not be loaded', true));
$this->_stop();
}
- if (!empty($this->args[0])) {
- if ($this->args[0] == 'write') {
+ if (isset($this->params['write'])) {
+ if ($this->params['write'] == 1) {
$write = Inflector::underscore($this->Schema->name);
} else {
- $write = $this->args[0];
+ $write = $this->params['write'];
}
}
$db =& ConnectionManager::getDataSource($this->Schema->connection);
@@ -219,7 +221,12 @@ function dump() {
if (strpos($write, '.sql') === false) {
$write .= '.sql';
}
- $File = new File($this->Schema->path . DS . $write, true);
+ if (strpos($write, DS) !== false) {
+ $File =& new File($write, true);
+ } else {
+ $File =& new File($this->Schema->path . DS . $write, true);
+ }
+
if ($File->write($contents)) {
$this->out(sprintf(__('SQL dump file created in %s', true), $File->pwd()));
$this->_stop();
@@ -259,16 +266,13 @@ function update() {
**/
function _loadSchema() {
$name = $plugin = null;
- if (isset($this->args[0])) {
- $name = $this->args[0];
- }
if (isset($this->params['name'])) {
$name = $this->params['name'];
}
- if (strpos($name, '.') !== false) {
- list($plugin, $name) = explode('.', $name);
+ if (isset($this->params['plugin'])) {
+ $plugin = $this->params['plugin'];
}
-
+
if (isset($this->params['dry'])) {
$this->__dry = true;
$this->out(__('Performing a dry run.', true));
View
49 cake/tests/cases/console/libs/schema.test.php
@@ -217,15 +217,12 @@ function testViewWithPlugins() {
* @return void
**/
function testDumpWithFileWriting() {
- $file =& new File(APP . 'config' . DS . 'schema' . DS . 'i18n.php');
- $contents = $file->read();
- $file =& new File(TMP . 'tests' . DS . 'i18n.php');
- $file->write($contents);
-
- $this->Shell->params = array('name' => 'i18n');
- $this->Shell->args = array('write');
+ $this->Shell->params = array(
+ 'name' => 'i18n',
+ 'write' => TMP . 'tests' . DS . 'i18n.sql'
+ );
+ $this->Shell->expectOnce('_stop');
$this->Shell->startup();
- $this->Shell->Schema->path = TMP . 'tests';
$this->Shell->dump();
$sql =& new File(TMP . 'tests' . DS . 'i18n.sql');
@@ -240,7 +237,35 @@ function testDumpWithFileWriting() {
$this->assertPattern('/content/', $contents);
$sql->delete();
+ }
+
+/**
+ * test that dump() can find and work with plugin schema files.
+ *
+ * @return void
+ **/
+ function testDumpFileWritingWithPlugins() {
+ App::build(array(
+ 'plugins' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'plugins' . DS)
+ ));
+ $this->Shell->args = array('TestPlugin.TestPluginApp');
+ $this->Shell->params = array(
+ 'connection' => 'test_suite',
+ 'write' => TMP . 'tests' . DS . 'dump_test.sql'
+ );
+ $this->Shell->startup();
+ $this->Shell->expectOnce('_stop');
+ $this->Shell->dump();
+
+ $file =& new File(TMP . 'tests' . DS . 'dump_test.sql');
+ $contents = $file->read();
+
+ $this->assertPattern('/CREATE TABLE `acos`/', $contents);
+ $this->assertPattern('/id/', $contents);
+ $this->assertPattern('/model/', $contents);
+
$file->delete();
+ App::build();
}
/**
@@ -310,7 +335,7 @@ function testGenerateOverwrite() {
*
* @return void
**/
- function testRunCreateNoArgs() {
+ function testCreateNoArgs() {
$this->Shell->params = array(
'connection' => 'test_suite',
'path' => APP . 'config' . DS . 'sql'
@@ -333,7 +358,7 @@ function testRunCreateNoArgs() {
*
* @return void
**/
- function testRunCreateWithTableArgs() {
+ function testCreateWithTableArgs() {
$this->Shell->params = array(
'connection' => 'test_suite',
'name' => 'DbAcl',
@@ -358,7 +383,7 @@ function testRunCreateWithTableArgs() {
*
* @return void
**/
- function testRunUpdateWithTable() {
+ function testUpdateWithTable() {
$this->Shell->params = array(
'connection' => 'test_suite',
'f' => true
@@ -401,7 +426,7 @@ function testPluginParam() {
*
* @return void
**/
- function testPluginDotSyntax() {
+ function testPluginDotSyntaxWithCreate() {
App::build(array(
'plugins' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'plugins' . DS)
));
Please sign in to comment.
Something went wrong with that request. Please try again.