Skip to content

Commit

Permalink
Add additional test coverage for createFile().
Browse files Browse the repository at this point in the history
  • Loading branch information
markstory committed Mar 21, 2014
1 parent 92c89f7 commit 116062b
Showing 1 changed file with 49 additions and 6 deletions.
55 changes: 49 additions & 6 deletions tests/TestCase/Console/ShellTest.php
Expand Up @@ -531,25 +531,68 @@ public function testShortPath() {
*/
public function testCreateFileNonInteractive() {
$eol = PHP_EOL;

$path = TMP . 'shell_test';
$file = $path . DS . 'file1.php';

new Folder($path, true);

$this->Shell->interactive = false;

$contents = "<?php{$eol}echo '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);
}

/**
* Test that files are not changed with a 'n' reply.
*
* @return void
*/
public function testCreateFileNoReply() {
$eol = PHP_EOL;
$path = TMP . 'shell_test';
$file = $path . DS . 'file1.php';

new Folder($path, true);

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

$contents = "<?php\necho 'another test';\n\$te = 'st';\n";
touch($file);
$this->assertTrue(file_exists($file));

$contents = "My content";
$result = $this->Shell->createFile($file, $contents);
$this->assertTrue(file_exists($file));
$this->assertTextEquals('', file_get_contents($file));
$this->assertFalse($result, 'Did not create file.');
}

/**
* Test that files are changed with a 'y' reply.
*
* @return void
*/
public function testCreateFileOverwrite() {
$eol = PHP_EOL;
$path = TMP . 'shell_test';
$file = $path . DS . 'file1.php';

new Folder($path, true);

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

touch($file);
$this->assertTrue(file_exists($file));

$contents = "My content";
$result = $this->Shell->createFile($file, $contents);
$this->assertTrue($result);
$this->assertTrue(file_exists($file));
$this->assertTextEquals(file_get_contents($file), $contents);
$this->assertTextEquals($contents, file_get_contents($file));
$this->assertTrue($result, 'Did create file.');
}

/**
Expand Down

0 comments on commit 116062b

Please sign in to comment.