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
e2f7b99f
Commit
e2f7b99f
authored
Jun 10, 2013
by
Klimov Paul
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Unit test for "yii\helpers\base\FileHelper" has been created.
parent
3fc19008
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
72 additions
and
0 deletions
+72
-0
FileHelperTest.php
tests/unit/framework/helpers/FileHelperTest.php
+72
-0
No files found.
tests/unit/framework/helpers/FileHelperTest.php
0 → 100644
View file @
e2f7b99f
<?php
use
yii\helpers\base\FileHelper
;
use
yii\test\TestCase
;
/**
* Unit test for [[yii\helpers\base\FileHelper]]
* @see FileHelper
*/
class
FileHelperTest
extends
TestCase
{
private
$testFilePath
=
''
;
public
function
setUp
()
{
$this
->
testFilePath
=
Yii
::
getAlias
(
'@yiiunit/runtime'
)
.
DIRECTORY_SEPARATOR
.
get_class
(
$this
);
$this
->
createDir
(
$this
->
testFilePath
);
}
public
function
tearDown
()
{
$this
->
removeDir
(
$this
->
testFilePath
);
}
/**
* Creates directory.
* @param string $dirName directory full name.
*/
protected
function
createDir
(
$dirName
)
{
if
(
!
file_exists
(
$dirName
))
{
mkdir
(
$dirName
,
0777
,
true
);
}
}
/**
* Removes directory.
* @param string $dirName directory full name.
*/
protected
function
removeDir
(
$dirName
)
{
if
(
!
empty
(
$dirName
)
&&
file_exists
(
$dirName
))
{
exec
(
"rm -rf
{
$dirName
}
"
);
}
}
// Tests :
public
function
testCopyDirectory
()
{
$basePath
=
$this
->
testFilePath
;
$srcDirName
=
$basePath
.
DIRECTORY_SEPARATOR
.
'test_src_dir'
;
mkdir
(
$srcDirName
,
0777
,
true
);
$files
=
array
(
'file1.txt'
=>
'file 1 content'
,
'file2.txt'
=>
'file 2 content'
,
);
foreach
(
$files
as
$name
=>
$content
)
{
file_put_contents
(
$srcDirName
.
DIRECTORY_SEPARATOR
.
$name
,
$content
);
}
$dstDirName
=
$basePath
.
DIRECTORY_SEPARATOR
.
'test_dst_dir'
;
FileHelper
::
copyDirectory
(
$srcDirName
,
$dstDirName
);
$this
->
assertTrue
(
file_exists
(
$dstDirName
),
'Destination directory does not exist!'
);
foreach
(
$files
as
$name
=>
$content
)
{
$fileName
=
$dstDirName
.
DIRECTORY_SEPARATOR
.
$name
;
$this
->
assertTrue
(
file_exists
(
$fileName
),
'Directory file is missing!'
);
$this
->
assertEquals
(
$content
,
file_get_contents
(
$fileName
),
'Incorrect file content!'
);
}
}
}
\ 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