From e4ceb0df9304e3855342d16b3d71e97de01828a6 Mon Sep 17 00:00:00 2001 From: Walther Lalk Date: Thu, 4 Jun 2015 11:26:03 +0200 Subject: [PATCH] Add test for overwrite all --- tests/TestCase/Console/ShellTest.php | 33 ++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/tests/TestCase/Console/ShellTest.php b/tests/TestCase/Console/ShellTest.php index 954771657e2..95fd35ee1c1 100644 --- a/tests/TestCase/Console/ShellTest.php +++ b/tests/TestCase/Console/ShellTest.php @@ -525,6 +525,39 @@ public function testCreateFileOverwriteNonInteractive() $this->assertEquals(file_get_contents($file), 'My content'); } + /** + * Test that all files are changed with a 'a' reply. + * + * @return void + */ + public function testCreateFileOverwriteAll() + { + $eol = PHP_EOL; + $path = TMP . 'shell_test'; + $files = [ + $path . DS . 'file1.php' => 'My first content', + $path . DS . 'file2.php' => 'My second content', + $path . DS . 'file3.php' => 'My third content' + ]; + + new Folder($path, true); + + $this->io->expects($this->once()) + ->method('askChoice') + ->will($this->returnValue('a')); + + foreach ($files as $file => $content) { + touch($file); + $this->assertTrue(file_exists($file)); + + $contents = "My content"; + $result = $this->Shell->createFile($file, $contents); + $this->assertTrue(file_exists($file)); + $this->assertTextEquals($contents, file_get_contents($file)); + $this->assertTrue($result, 'Did create file.'); + } + } + /** * Test that you can't create files that aren't writable. *