Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
Y
yii2
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
PSDI Army
yii2
Commits
ef60ec56
Commit
ef60ec56
authored
Jun 10, 2013
by
Klimov Paul
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Method "yii\helpers\base\FileHelper::removeDirectory()" has been added.
parent
e2f7b99f
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
51 additions
and
1 deletion
+51
-1
FileHelper.php
framework/yii/helpers/base/FileHelper.php
+22
-0
FileHelperTest.php
tests/unit/framework/helpers/FileHelperTest.php
+29
-1
No files found.
framework/yii/helpers/base/FileHelper.php
View file @
ef60ec56
...
...
@@ -169,4 +169,26 @@ class FileHelper
}
closedir
(
$handle
);
}
/**
* Removes a directory recursively.
* @param string $directory to be deleted recursively.
*/
public
static
function
removeDirectory
(
$directory
)
{
$items
=
glob
(
$directory
.
DIRECTORY_SEPARATOR
.
'{,.}*'
,
GLOB_MARK
|
GLOB_BRACE
);
foreach
(
$items
as
$item
)
{
if
(
basename
(
$item
)
==
'.'
||
basename
(
$item
)
==
'..'
)
{
continue
;
}
if
(
substr
(
$item
,
-
1
)
==
DIRECTORY_SEPARATOR
)
{
self
::
removeDirectory
(
$item
);
}
else
{
unlink
(
$item
);
}
}
if
(
is_dir
(
$directory
))
{
rmdir
(
$directory
);
}
}
}
tests/unit/framework/helpers/FileHelperTest.php
View file @
ef60ec56
...
...
@@ -9,6 +9,9 @@ use yii\test\TestCase;
*/
class
FileHelperTest
extends
TestCase
{
/**
* @var string test files path.
*/
private
$testFilePath
=
''
;
public
function
setUp
()
...
...
@@ -46,7 +49,8 @@ class FileHelperTest extends TestCase
// Tests :
public
function
testCopyDirectory
()
{
public
function
testCopyDirectory
()
{
$basePath
=
$this
->
testFilePath
;
$srcDirName
=
$basePath
.
DIRECTORY_SEPARATOR
.
'test_src_dir'
;
mkdir
(
$srcDirName
,
0777
,
true
);
...
...
@@ -68,4 +72,27 @@ class FileHelperTest extends TestCase
$this
->
assertEquals
(
$content
,
file_get_contents
(
$fileName
),
'Incorrect file content!'
);
}
}
public
function
testRemoveDirectory
()
{
$basePath
=
$this
->
testFilePath
;
$dirName
=
$basePath
.
DIRECTORY_SEPARATOR
.
'test_dir_for_remove'
;
mkdir
(
$dirName
,
0777
,
true
);
$files
=
array
(
'file1.txt'
=>
'file 1 content'
,
'file2.txt'
=>
'file 2 content'
,
);
foreach
(
$files
as
$name
=>
$content
)
{
file_put_contents
(
$dirName
.
DIRECTORY_SEPARATOR
.
$name
,
$content
);
}
$subDirName
=
$dirName
.
DIRECTORY_SEPARATOR
.
'test_sub_dir'
;
mkdir
(
$subDirName
,
0777
,
true
);
foreach
(
$files
as
$name
=>
$content
)
{
file_put_contents
(
$subDirName
.
DIRECTORY_SEPARATOR
.
$name
,
$content
);
}
FileHelper
::
removeDirectory
(
$dirName
);
$this
->
assertFalse
(
file_exists
(
$dirName
),
'Unable to remove directory!'
);
}
}
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment