Skip to content

Commit

Permalink
#165 - added a unit test for the FileUtils::deleteDirectoryContents()…
Browse files Browse the repository at this point in the history
… method
  • Loading branch information
alphadevx committed Aug 12, 2015
1 parent e1e44fd commit f2eb6b5
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
5 changes: 3 additions & 2 deletions Alpha/Util/File/FileUtils.php
Expand Up @@ -564,7 +564,7 @@ public static function listDirectoryContents($sourceDir, &$fileList, $fileCount=
}

/**
* Recursively deletes the contents of the directory indicated.
* Recursively deletes the contents of the directory indicated (the directory itself is not deleted).
*
* @param string $sourceDir The path to the source directory.
* @param array $excludeFiles An array of file names to exclude from the deletion.
Expand All @@ -573,7 +573,8 @@ public static function listDirectoryContents($sourceDir, &$fileList, $fileCount=
*/
public static function deleteDirectoryContents($sourceDir, $excludeFiles = array())
{
try {
try
{
$dir = new DirectoryIterator($sourceDir);

foreach ($dir as $file) {
Expand Down
19 changes: 19 additions & 0 deletions test/Alpha/Test/Util/File/FileUtilsTest.php
Expand Up @@ -72,6 +72,25 @@ public function testListDirectoryContents()
$this->assertTrue(FileUtils::listDirectoryContents('.', $fileList, 0, array()) > 0, 'Testing the listDirectoryContents() method');
$this->assertTrue(strpos($fileList,'</em><br>') !== false, 'Testing the listDirectoryContents() method');
}

/**
* Testing the deleteDirectoryContents() method
*
* @since 2.0
*/
public function testDeleteDirectoryContents()
{
if (!file_exists('/tmp/alphatestdir')) {
mkdir('/tmp/alphatestdir');
}
mkdir('/tmp/alphatestdir/subdir');

$this->assertTrue(file_exists('/tmp/alphatestdir/subdir'), 'Testing the deleteDirectoryContents() method');

FileUtils::deleteDirectoryContents('/tmp/alphatestdir');

$this->assertFalse(file_exists('/tmp/alphatestdir/subdir'), 'Testing the deleteDirectoryContents() method');
}
}

?>

0 comments on commit f2eb6b5

Please sign in to comment.