Skip to content

Commit

Permalink
Make Shell::createFile() always work the same.
Browse files Browse the repository at this point in the history
Ignoring the force param is annoying and not always obvious.
  • Loading branch information
markstory committed Mar 21, 2014
1 parent 45c532e commit 1affe70
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 44 deletions.
2 changes: 1 addition & 1 deletion src/Console/Shell.php
Expand Up @@ -643,7 +643,7 @@ public function createFile($path, $contents) {

$this->out();

if (is_file($path) && empty($this->params['force']) && $this->interactive === true) {
if (is_file($path) && empty($this->params['force'])) {
$this->out(__d('cake_console', '<warning>File `%s` exists</warning>', $path));
$key = $this->in(__d('cake_console', 'Do you want to overwrite?'), ['y', 'n', 'q'], 'n');

Expand Down
43 changes: 0 additions & 43 deletions tests/TestCase/Console/ShellTest.php
Expand Up @@ -552,49 +552,6 @@ public function testCreateFileNonInteractive() {
$this->assertTextEquals(file_get_contents($file), $contents);
}

/**
* test createFile when the shell is interactive.
*
* @return void
*/
public function testCreateFileInteractive() {
$eol = PHP_EOL;

$path = TMP . 'shell_test';
$file = $path . DS . 'file1.php';
new Folder($path, true);

$this->Shell->interactive = true;

$this->Shell->stdin->expects($this->at(0))
->method('read')
->will($this->returnValue('n'));

$this->Shell->stdin->expects($this->at(1))
->method('read')
->will($this->returnValue('y'));

$contents = "<?php{$eol}echo 'yet another test';{$eol}\$te = 'st';{$eol}";
$result = $this->Shell->createFile($file, $contents);
$this->assertTrue($result);
$this->assertTrue(file_exists($file));
$this->assertEquals(file_get_contents($file), $contents);

// no overwrite
$contents = 'new contents';
$result = $this->Shell->createFile($file, $contents);
$this->assertFalse($result);
$this->assertTrue(file_exists($file));
$this->assertNotEquals($contents, file_get_contents($file));

// overwrite
$contents = 'more new contents';
$result = $this->Shell->createFile($file, $contents);
$this->assertTrue($result);
$this->assertTrue(file_exists($file));
$this->assertEquals($contents, file_get_contents($file));
}

/**
* Test that you can't create files that aren't writable.
*
Expand Down

0 comments on commit 1affe70

Please sign in to comment.