Skip to content

Commit

Permalink
Prevent name param from overwriting file if both are passed
Browse files Browse the repository at this point in the history
  • Loading branch information
ricog committed Oct 10, 2013
1 parent ce1939c commit a091c63
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/Cake/Console/Command/SchemaShell.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public function startup() {
$name = $this->params['name'] = $splitName;
}

if ($name) {
if ($name && empty($this->params['file'])) {
$this->params['file'] = Inflector::underscore($name);
}

Expand Down
36 changes: 36 additions & 0 deletions lib/Cake/Test/Case/Console/Command/SchemaShellTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -585,6 +585,42 @@ public function testName() {
CakePlugin::unload();
}

/**
* test that passing name and file creates the passed filename with the
* passed classname
*
* @return void
*/
public function testNameAndFile() {
App::build(array(
'Plugin' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'Plugin' . DS)
));
CakePlugin::load('TestPlugin');
$this->Shell->params = array(
'plugin' => 'TestPlugin',
'connection' => 'test',
'name' => 'custom_name',
'file' => 'other_name',
'force' => false,
'overwrite' => true,
);
$this->Shell->startup();
$file = $this->Shell->Schema->path . DS . 'other_name.php';
if (file_exists($file)) {
unlink($file);
}
$this->Shell->generate();

$this->assertFileExists($file);
$contents = file_get_contents($file);
$this->assertRegExp('/class CustomNameSchema/', $contents);

if (file_exists($file)) {
unlink($file);
}
CakePlugin::unload();
}

/**
* test that using Plugin.name with write.
*
Expand Down

0 comments on commit a091c63

Please sign in to comment.