Skip to content

Commit

Permalink
Fixing return values of methods, and updating tests to run properly i…
Browse files Browse the repository at this point in the history
…n Phpunit which uses exceptions instead of errors.
  • Loading branch information
markstory committed May 31, 2010
1 parent ea2f032 commit 02a04ab
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 45 deletions.
9 changes: 6 additions & 3 deletions cake/libs/folder.php
Expand Up @@ -66,7 +66,7 @@ class Folder {
* @var array
* @access private
*/
private $__errors = false;
private $__errors = array();

/**
* Holds array of complete directory paths.
Expand Down Expand Up @@ -678,11 +678,14 @@ public function move($options) {
$to = $options;
$options = (array)$options;
}
$options = array_merge(array('to' => $to, 'from' => $this->path, 'mode' => $this->mode, 'skip' => array()), $options);
$options = array_merge(
array('to' => $to, 'from' => $this->path, 'mode' => $this->mode, 'skip' => array()),
$options
);

if ($this->copy($options)) {
if ($this->delete($options['from'])) {
return $this->cd($options['to']);
return (bool)$this->cd($options['to']);
}
}
return false;
Expand Down
86 changes: 44 additions & 42 deletions cake/tests/cases/libs/folder.test.php
Expand Up @@ -35,7 +35,7 @@ class FolderTest extends CakeTestCase {
*/
function testBasic() {
$path = dirname(__FILE__);
$Folder =& new Folder($path);
$Folder = new Folder($path);

$result = $Folder->pwd();
$this->assertEqual($result, $path);
Expand All @@ -62,7 +62,7 @@ function testInPath() {
$path = dirname(dirname(__FILE__));
$inside = dirname($path) . DS;

$Folder =& new Folder($path);
$Folder = new Folder($path);

$result = $Folder->pwd();
$this->assertEqual($result, $path);
Expand All @@ -86,15 +86,15 @@ function testInPath() {
* @return void
*/
function testCreation() {
$folder =& new Folder(TMP . 'tests');
$folder = new Folder(TMP . 'tests');
$result = $folder->create(TMP . 'tests' . DS . 'first' . DS . 'second' . DS . 'third');
$this->assertTrue($result);

rmdir(TMP . 'tests' . DS . 'first' . DS . 'second' . DS . 'third');
rmdir(TMP . 'tests' . DS . 'first' . DS . 'second');
rmdir(TMP . 'tests' . DS . 'first');

$folder =& new Folder(TMP . 'tests');
$folder = new Folder(TMP . 'tests');
$result = $folder->create(TMP . 'tests' . DS . 'first');
$this->assertTrue($result);
rmdir(TMP . 'tests' . DS . 'first');
Expand All @@ -106,13 +106,13 @@ function testCreation() {
* @return void
*/
function testCreateWithTrailingDs() {
$folder =& new Folder(TMP);
$folder = new Folder(TMP);
$path = TMP . 'tests' . DS . 'trailing' . DS . 'dir' . DS;
$folder->create($path);

$this->assertTrue(is_dir($path), 'Folder was not made');

$folder =& new Folder(TMP . 'tests' . DS . 'trailing');
$folder = new Folder(TMP . 'tests' . DS . 'trailing');
$this->assertTrue($folder->delete());
}

Expand All @@ -129,11 +129,13 @@ function testRecursiveCreateFailure() {
mkdir($path);
chmod($path, '0444');

$this->expectError();

$folder =& new Folder($path);
$result = $folder->create($path . DS . 'two' . DS . 'three');
$this->assertFalse($result);
try {
$folder = new Folder($path);
$result = $folder->create($path . DS . 'two' . DS . 'three');
$this->assertFalse($result);
} catch (PHPUnit_Framework_Error $e) {
$this->assertTrue(true);
}

chmod($path, '0777');
rmdir($path);
Expand All @@ -146,7 +148,7 @@ function testRecursiveCreateFailure() {
*/
function testOperations() {
$path = TEST_CAKE_CORE_INCLUDE_PATH . 'console' . DS . 'templates' . DS . 'skel';
$Folder =& new Folder($path);
$Folder = new Folder($path);

$result = is_dir($Folder->pwd());
$this->assertTrue($result);
Expand All @@ -168,7 +170,7 @@ function testOperations() {
$this->assertTrue($result);

$result = $Folder->cd($copy);
$this->assertTrue($result);
$this->assertTrue((bool)$result);

$mv = TMP . 'test_folder_mv';
$result = $Folder->move($mv);
Expand Down Expand Up @@ -200,12 +202,12 @@ function testOperations() {
$this->assertTrue($result);

$result = $Folder->cd($new);
$this->assertTrue($result);
$this->assertTrue((bool)$result);

$result = $Folder->delete();
$this->assertTrue($result);

$Folder =& new Folder('non-existent');
$Folder = new Folder('non-existent');
$result = $Folder->pwd();
$this->assertNull($result);
}
Expand All @@ -219,7 +221,7 @@ public function testChmod() {
$this->skipIf(DIRECTORY_SEPARATOR === '\\', '%s Folder permissions tests not supported on Windows');

$path = TEST_CAKE_CORE_INCLUDE_PATH . 'console' . DS . 'templates' . DS . 'skel';
$Folder =& new Folder($path);
$Folder = new Folder($path);

$subdir = 'test_folder_new';
$new = TMP . $subdir;
Expand All @@ -229,7 +231,7 @@ public function testChmod() {
$this->assertTrue($Folder->create($new . DS . 'test2'));

$filePath = $new . DS . 'test1.php';
$File =& new File($filePath);
$File = new File($filePath);
$this->assertTrue($File->create());
$copy = TMP . 'test_folder_copy';

Expand Down Expand Up @@ -257,7 +259,7 @@ function testRealPathForWebroot() {
* @return void
*/
function testZeroAsDirectory() {
$Folder =& new Folder(TMP);
$Folder = new Folder(TMP);
$new = TMP . '0';
$this->assertTrue($Folder->create($new));

Expand Down Expand Up @@ -292,7 +294,7 @@ function testAddPathElement() {
* @return void
*/
function testFolderRead() {
$Folder =& new Folder(TMP);
$Folder = new Folder(TMP);

$expected = array('cache', 'logs', 'sessions', 'tests');
$result = $Folder->read(true, true);
Expand All @@ -311,7 +313,7 @@ function testFolderRead() {
* @return void
*/
function testFolderTree() {
$Folder =& new Folder();
$Folder = new Folder();
$expected = array(
array(
TEST_CAKE_CORE_INCLUDE_PATH . 'config',
Expand Down Expand Up @@ -458,7 +460,7 @@ function testCorrectSlashFor() {
* @return void
*/
function testInCakePath() {
$Folder =& new Folder();
$Folder = new Folder();
$Folder->cd(ROOT);
$path = 'C:\\path\\to\\file';
$result = $Folder->inCakePath($path);
Expand All @@ -483,7 +485,7 @@ function testInCakePath() {
* @return void
*/
function testFind() {
$Folder =& new Folder();
$Folder = new Folder();
$Folder->cd(TEST_CAKE_CORE_INCLUDE_PATH . 'config');
$result = $Folder->find();
$expected = array('config.php', 'paths.php');
Expand Down Expand Up @@ -536,7 +538,7 @@ function testFind() {
* @return void
*/
function testFindRecursive() {
$Folder =& new Folder();
$Folder = new Folder();
$Folder->cd(TEST_CAKE_CORE_INCLUDE_PATH);
$result = $Folder->findRecursive('(config|paths)\.php');
$expected = array(
Expand All @@ -556,15 +558,15 @@ function testFindRecursive() {
$Folder->cd(TMP);
$Folder->create($Folder->pwd() . DS . 'testme');
$Folder->cd('testme');
$File =& new File($Folder->pwd() . DS . 'paths.php');
$File = new File($Folder->pwd() . DS . 'paths.php');
$File->create();
$Folder->cd(TMP . 'sessions');
$result = $Folder->findRecursive('paths\.php');
$expected = array();
$this->assertIdentical($result, $expected);

$Folder->cd(TMP . 'testme');
$File =& new File($Folder->pwd() . DS . 'my.php');
$File = new File($Folder->pwd() . DS . 'my.php');
$File->create();
$Folder->cd($Folder->pwd() . '/../..');

Expand Down Expand Up @@ -596,7 +598,7 @@ function testFindRecursive() {
* @return void
*/
function testConstructWithNonExistantPath() {
$Folder =& new Folder(TMP . 'config_non_existant', true);
$Folder = new Folder(TMP . 'config_non_existant', true);
$this->assertTrue(is_dir(TMP . 'config_non_existant'));
$Folder->cd(TMP);
$Folder->delete($Folder->pwd() . 'config_non_existant');
Expand All @@ -609,10 +611,10 @@ function testConstructWithNonExistantPath() {
* @return void
*/
function testDirSize() {
$Folder =& new Folder(TMP . 'config_non_existant', true);
$Folder = new Folder(TMP . 'config_non_existant', true);
$this->assertEqual($Folder->dirSize(), 0);

$File =& new File($Folder->pwd() . DS . 'my.php', true, 0777);
$File = new File($Folder->pwd() . DS . 'my.php', true, 0777);
$File->create();
$File->write('something here');
$File->close();
Expand All @@ -630,7 +632,7 @@ function testDirSize() {
*/
function testDelete() {
$path = TMP . 'folder_delete_test';
$Folder =& new Folder($path, true);
$Folder = new Folder($path, true);
touch(TMP . 'folder_delete_test' . DS . 'file1');
touch(TMP . 'folder_delete_test' . DS . 'file2');

Expand All @@ -639,7 +641,7 @@ function testDelete() {

$messages = $Folder->messages();
$errors = $Folder->errors();
$this->assertEqual($errors, array());
$this->assertEquals($errors, array());

$expected = array(
$path . ' created',
Expand Down Expand Up @@ -677,35 +679,35 @@ function testCopy() {
touch($file1);
touch($file2);

$Folder =& new Folder($folder1);
$Folder = new Folder($folder1);
$result = $Folder->copy($folder3);
$this->assertTrue($result);
$this->assertTrue(file_exists($folder3 . DS . 'file1.php'));
$this->assertTrue(file_exists($folder3 . DS . 'folder2' . DS . 'file2.php'));

$Folder =& new Folder($folder3);
$Folder = new Folder($folder3);
$Folder->delete();

$Folder =& new Folder($folder1);
$Folder = new Folder($folder1);
$result = $Folder->copy($folder3);
$this->assertTrue($result);
$this->assertTrue(file_exists($folder3 . DS . 'file1.php'));
$this->assertTrue(file_exists($folder3 . DS . 'folder2' . DS . 'file2.php'));

$Folder =& new Folder($folder3);
$Folder = new Folder($folder3);
$Folder->delete();

new Folder($folder3, true);
new Folder($folder3 . DS . 'folder2', true);
file_put_contents($folder3 . DS . 'folder2' . DS . 'file2.php', 'untouched');

$Folder =& new Folder($folder1);
$Folder = new Folder($folder1);
$result = $Folder->copy($folder3);
$this->assertTrue($result);
$this->assertTrue(file_exists($folder3 . DS . 'file1.php'));
$this->assertEqual(file_get_contents($folder3 . DS . 'folder2' . DS . 'file2.php'), 'untouched');

$Folder =& new Folder($path);
$Folder = new Folder($path);
$Folder->delete();
}

Expand Down Expand Up @@ -736,7 +738,7 @@ function testMove() {
touch($file1);
touch($file2);

$Folder =& new Folder($folder1);
$Folder = new Folder($folder1);
$result = $Folder->move($folder3);
$this->assertTrue($result);
$this->assertTrue(file_exists($folder3 . DS . 'file1.php'));
Expand All @@ -746,15 +748,15 @@ function testMove() {
$this->assertFalse(file_exists($folder2));
$this->assertFalse(file_exists($file2));

$Folder =& new Folder($folder3);
$Folder = new Folder($folder3);
$Folder->delete();

new Folder($folder1, true);
new Folder($folder2, true);
touch($file1);
touch($file2);

$Folder =& new Folder($folder1);
$Folder = new Folder($folder1);
$result = $Folder->move($folder3);
$this->assertTrue($result);
$this->assertTrue(file_exists($folder3 . DS . 'file1.php'));
Expand All @@ -764,7 +766,7 @@ function testMove() {
$this->assertFalse(file_exists($folder2));
$this->assertFalse(file_exists($file2));

$Folder =& new Folder($folder3);
$Folder = new Folder($folder3);
$Folder->delete();

new Folder($folder1, true);
Expand All @@ -775,7 +777,7 @@ function testMove() {
touch($file2);
file_put_contents($folder3 . DS . 'folder2' . DS . 'file2.php', 'untouched');

$Folder =& new Folder($folder1);
$Folder = new Folder($folder1);
$result = $Folder->move($folder3);
$this->assertTrue($result);
$this->assertTrue(file_exists($folder3 . DS . 'file1.php'));
Expand All @@ -784,7 +786,7 @@ function testMove() {
$this->assertFalse(file_exists($folder2));
$this->assertFalse(file_exists($file2));

$Folder =& new Folder($path);
$Folder = new Folder($path);
$Folder->delete();
}
}

0 comments on commit 02a04ab

Please sign in to comment.