mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +00:00
Fixing return values of methods, and updating tests to run properly in Phpunit which uses exceptions instead of errors.
This commit is contained in:
parent
ea2f0327f5
commit
02a04abf6b
2 changed files with 50 additions and 45 deletions
|
@ -66,7 +66,7 @@ class Folder {
|
|||
* @var array
|
||||
* @access private
|
||||
*/
|
||||
private $__errors = false;
|
||||
private $__errors = array();
|
||||
|
||||
/**
|
||||
* Holds array of complete directory paths.
|
||||
|
@ -678,11 +678,14 @@ class Folder {
|
|||
$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;
|
||||
|
|
|
@ -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);
|
||||
|
@ -62,7 +62,7 @@ class FolderTest extends CakeTestCase {
|
|||
$path = dirname(dirname(__FILE__));
|
||||
$inside = dirname($path) . DS;
|
||||
|
||||
$Folder =& new Folder($path);
|
||||
$Folder = new Folder($path);
|
||||
|
||||
$result = $Folder->pwd();
|
||||
$this->assertEqual($result, $path);
|
||||
|
@ -86,7 +86,7 @@ class FolderTest extends CakeTestCase {
|
|||
* @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);
|
||||
|
||||
|
@ -94,7 +94,7 @@ class FolderTest extends CakeTestCase {
|
|||
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');
|
||||
|
@ -106,13 +106,13 @@ class FolderTest extends CakeTestCase {
|
|||
* @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());
|
||||
}
|
||||
|
||||
|
@ -129,11 +129,13 @@ class FolderTest extends CakeTestCase {
|
|||
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);
|
||||
|
@ -146,7 +148,7 @@ class FolderTest extends CakeTestCase {
|
|||
*/
|
||||
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);
|
||||
|
@ -168,7 +170,7 @@ class FolderTest extends CakeTestCase {
|
|||
$this->assertTrue($result);
|
||||
|
||||
$result = $Folder->cd($copy);
|
||||
$this->assertTrue($result);
|
||||
$this->assertTrue((bool)$result);
|
||||
|
||||
$mv = TMP . 'test_folder_mv';
|
||||
$result = $Folder->move($mv);
|
||||
|
@ -200,12 +202,12 @@ class FolderTest extends CakeTestCase {
|
|||
$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);
|
||||
}
|
||||
|
@ -219,7 +221,7 @@ class FolderTest extends CakeTestCase {
|
|||
$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;
|
||||
|
@ -229,7 +231,7 @@ class FolderTest extends CakeTestCase {
|
|||
$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';
|
||||
|
||||
|
@ -257,7 +259,7 @@ class FolderTest extends CakeTestCase {
|
|||
* @return void
|
||||
*/
|
||||
function testZeroAsDirectory() {
|
||||
$Folder =& new Folder(TMP);
|
||||
$Folder = new Folder(TMP);
|
||||
$new = TMP . '0';
|
||||
$this->assertTrue($Folder->create($new));
|
||||
|
||||
|
@ -292,7 +294,7 @@ class FolderTest extends CakeTestCase {
|
|||
* @return void
|
||||
*/
|
||||
function testFolderRead() {
|
||||
$Folder =& new Folder(TMP);
|
||||
$Folder = new Folder(TMP);
|
||||
|
||||
$expected = array('cache', 'logs', 'sessions', 'tests');
|
||||
$result = $Folder->read(true, true);
|
||||
|
@ -311,7 +313,7 @@ class FolderTest extends CakeTestCase {
|
|||
* @return void
|
||||
*/
|
||||
function testFolderTree() {
|
||||
$Folder =& new Folder();
|
||||
$Folder = new Folder();
|
||||
$expected = array(
|
||||
array(
|
||||
TEST_CAKE_CORE_INCLUDE_PATH . 'config',
|
||||
|
@ -458,7 +460,7 @@ class FolderTest extends CakeTestCase {
|
|||
* @return void
|
||||
*/
|
||||
function testInCakePath() {
|
||||
$Folder =& new Folder();
|
||||
$Folder = new Folder();
|
||||
$Folder->cd(ROOT);
|
||||
$path = 'C:\\path\\to\\file';
|
||||
$result = $Folder->inCakePath($path);
|
||||
|
@ -483,7 +485,7 @@ class FolderTest extends CakeTestCase {
|
|||
* @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');
|
||||
|
@ -536,7 +538,7 @@ class FolderTest extends CakeTestCase {
|
|||
* @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(
|
||||
|
@ -556,7 +558,7 @@ class FolderTest extends CakeTestCase {
|
|||
$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');
|
||||
|
@ -564,7 +566,7 @@ class FolderTest extends CakeTestCase {
|
|||
$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() . '/../..');
|
||||
|
||||
|
@ -596,7 +598,7 @@ class FolderTest extends CakeTestCase {
|
|||
* @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');
|
||||
|
@ -609,10 +611,10 @@ class FolderTest extends CakeTestCase {
|
|||
* @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();
|
||||
|
@ -630,7 +632,7 @@ class FolderTest extends CakeTestCase {
|
|||
*/
|
||||
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');
|
||||
|
||||
|
@ -639,7 +641,7 @@ class FolderTest extends CakeTestCase {
|
|||
|
||||
$messages = $Folder->messages();
|
||||
$errors = $Folder->errors();
|
||||
$this->assertEqual($errors, array());
|
||||
$this->assertEquals($errors, array());
|
||||
|
||||
$expected = array(
|
||||
$path . ' created',
|
||||
|
@ -677,35 +679,35 @@ class FolderTest extends CakeTestCase {
|
|||
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();
|
||||
}
|
||||
|
||||
|
@ -736,7 +738,7 @@ class FolderTest extends CakeTestCase {
|
|||
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'));
|
||||
|
@ -746,7 +748,7 @@ class FolderTest extends CakeTestCase {
|
|||
$this->assertFalse(file_exists($folder2));
|
||||
$this->assertFalse(file_exists($file2));
|
||||
|
||||
$Folder =& new Folder($folder3);
|
||||
$Folder = new Folder($folder3);
|
||||
$Folder->delete();
|
||||
|
||||
new Folder($folder1, true);
|
||||
|
@ -754,7 +756,7 @@ class FolderTest extends CakeTestCase {
|
|||
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'));
|
||||
|
@ -764,7 +766,7 @@ class FolderTest extends CakeTestCase {
|
|||
$this->assertFalse(file_exists($folder2));
|
||||
$this->assertFalse(file_exists($file2));
|
||||
|
||||
$Folder =& new Folder($folder3);
|
||||
$Folder = new Folder($folder3);
|
||||
$Folder->delete();
|
||||
|
||||
new Folder($folder1, true);
|
||||
|
@ -775,7 +777,7 @@ class FolderTest extends CakeTestCase {
|
|||
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'));
|
||||
|
@ -784,7 +786,7 @@ class FolderTest extends CakeTestCase {
|
|||
$this->assertFalse(file_exists($folder2));
|
||||
$this->assertFalse(file_exists($file2));
|
||||
|
||||
$Folder =& new Folder($path);
|
||||
$Folder = new Folder($path);
|
||||
$Folder->delete();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue