Skip to content
This repository was archived by the owner on Sep 10, 2021. It is now read-only.

Commit 3c4ba70

Browse files
author
Michael Grauer
committed
BUG: Refs #212. Moved recursiveRemoveDirectory calls as it moved to KWUtils.
1 parent d46a043 commit 3c4ba70

File tree

2 files changed

+4
-64
lines changed

2 files changed

+4
-64
lines changed

modules/batchmake/tests/controllers/components/KWBatchmakeComponentTest.php

Lines changed: 1 addition & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -24,58 +24,6 @@ class KWBatchmakeComponentTest extends BatchmakeControllerTest
2424
protected $applicationConfig;
2525

2626

27-
/** Helper function to recursively delete a directory
28-
* @TODO temporary usage of this function, this should
29-
* get into KWUtils
30-
*
31-
* @param type $directorypath Directory to be deleted
32-
* @return bool Success or not
33-
*/
34-
private function _recursiveRemoveDirectory($directorypath)
35-
{
36-
// if the path has a slash at the end, remove it here
37-
$directorypath = rtrim($directorypath, '/');
38-
// open the directory
39-
$handle = opendir($directorypath);
40-
41-
if(!is_readable($directorypath))
42-
{
43-
return false;
44-
}
45-
// and scan through the items inside
46-
while(false !== ($item = readdir($handle)))
47-
{
48-
// if the filepointer is not the current directory or the parent directory
49-
if($item != '.' && $item != '..')
50-
{
51-
// build the new path to delete
52-
$path = $directorypath.'/'.$item;
53-
// if the new path is a directory
54-
if(is_dir($path))
55-
{
56-
// call this function with the new path
57-
$this->_recursiveRemoveDirectory($path);
58-
// if the new path is a file
59-
}
60-
else
61-
{
62-
// remove the file
63-
unlink($path);
64-
}
65-
}
66-
}
67-
closedir($handle);
68-
// try to delete the now empty directory
69-
if(!rmdir($directorypath))
70-
{
71-
return false;
72-
}
73-
return true;
74-
}
75-
76-
77-
78-
7927
/** set up tests*/
8028
public function setUp()
8129
{
@@ -97,7 +45,7 @@ public function tearDown()
9745
{
9846
// remove the temporary tests dir
9947
$testTmpDir = $this->getTempDirectory() . '/batchmake/tests';
100-
$this->_recursiveRemoveDirectory($testTmpDir);
48+
KWUtils::recursiveRemoveDirectory($testTmpDir);
10149
}
10250

10351

@@ -147,7 +95,6 @@ protected function clearDirFiles($dirToClear)
14795
}
14896
}
14997

150-
15198
/**
15299
* helper function to run a test case
153100
*/

tests/library/KWUtilsTest.php

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public function testMkDir()
3838
$tmpDir = $this->getTempDirectory() . '/KWUtilsTest';
3939
$this->assertTrue(KWUtils::mkDir($tmpDir));
4040
// now clean up
41-
rmdir($tmpDir);
41+
KWUtils::recursiveRemoveDirectory($tmpDir);
4242
}
4343

4444
/** tests createSubDirectories function */
@@ -66,15 +66,8 @@ public function testCreateSubDirectories()
6666
$this->assertTrue(is_dir($currDir));
6767
}
6868

69-
// now walk back up the tree and clean up these tmp dirs
70-
foreach($subDirs as $subdir)
71-
{
72-
// we aren't doing anything with $subdir, just iterating once per subdir
73-
rmdir($currDir);
74-
$parts = explode('/', $currDir);
75-
$parts = array_slice($parts, 0, count($parts)-1);
76-
$currDir = implode('/', $parts);
77-
}
69+
$topDir = $this->getTempDirectory() . '/KWUtilsTest';
70+
KWUtils::recursiveRemoveDirectory($topDir);
7871
}
7972

8073

0 commit comments

Comments
 (0)