Browse Source

Merge pull request #5692 from kminek/patch-1

Update Shell.php
José Lorenzo Rodríguez 11 years ago
parent
commit
08a1c83578
2 changed files with 24 additions and 1 deletions
  1. 1 1
      src/Console/Shell.php
  2. 23 0
      tests/TestCase/Console/ShellTest.php

+ 1 - 1
src/Console/Shell.php

@@ -608,7 +608,7 @@ class Shell
 
 
         $this->_io->out();
         $this->_io->out();
 
 
-        if (is_file($path) && empty($this->params['force'])) {
+        if (is_file($path) && empty($this->params['force']) && $this->interactive) {
             $this->_io->out(sprintf('<warning>File `%s` exists</warning>', $path));
             $this->_io->out(sprintf('<warning>File `%s` exists</warning>', $path));
             $key = $this->_io->askChoice('Do you want to overwrite?', ['y', 'n', 'q'], 'n');
             $key = $this->_io->askChoice('Do you want to overwrite?', ['y', 'n', 'q'], 'n');
 
 

+ 23 - 0
tests/TestCase/Console/ShellTest.php

@@ -500,6 +500,29 @@ class ShellTest extends TestCase
         $this->assertTextEquals($contents, file_get_contents($file));
         $this->assertTextEquals($contents, file_get_contents($file));
         $this->assertTrue($result, 'Did create file.');
         $this->assertTrue($result, 'Did create file.');
     }
     }
+    
+    /**
+     * Test that there is no user prompt in non-interactive mode while file already exists.
+     *
+     * @return void
+     */
+    public function testCreateFileOverwriteNonInteractive()
+    {
+        $path = TMP . 'shell_test';
+        $file = $path . DS . 'file1.php';
+        
+        new Folder($path, true);
+        
+        touch($file);
+        $this->assertTrue(file_exists($file));
+        
+        $this->io->expects($this->never())->method('askChoice');
+        
+        $this->Shell->interactive = false;
+        $result = $this->Shell->createFile($file, 'My content');
+        $this->assertTrue($result);
+        $this->assertEquals(file_get_contents($file), 'My content');
+    }
 
 
     /**
     /**
      * Test that you can't create files that aren't writable.
      * Test that you can't create files that aren't writable.