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
539864f4
Commit
539864f4
authored
Jun 10, 2013
by
Klimov Paul
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
"FileHelperTest" has been refactored.
parent
dfda6663
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
57 additions
and
38 deletions
+57
-38
FileHelperTest.php
tests/unit/framework/helpers/FileHelperTest.php
+57
-38
No files found.
tests/unit/framework/helpers/FileHelperTest.php
View file @
539864f4
...
@@ -47,20 +47,42 @@ class FileHelperTest extends TestCase
...
@@ -47,20 +47,42 @@ class FileHelperTest extends TestCase
}
}
}
}
/**
* Creates test files structure,
* @param array $items file system objects to be created in format: objectName => objectContent
* Arrays specifies directories, other values - files.
* @param string $basePath structure base file path.
*/
protected
function
createFileStructure
(
array
$items
,
$basePath
=
''
)
{
if
(
empty
(
$basePath
))
{
$basePath
=
$this
->
testFilePath
;
}
foreach
(
$items
as
$name
=>
$content
)
{
$itemName
=
$basePath
.
DIRECTORY_SEPARATOR
.
$name
;
if
(
is_array
(
$content
))
{
mkdir
(
$itemName
,
0777
,
true
);
$this
->
createFileStructure
(
$content
,
$itemName
);
}
else
{
file_put_contents
(
$itemName
,
$content
);
}
}
}
// Tests :
// Tests :
public
function
testCopyDirectory
()
public
function
testCopyDirectory
()
{
{
$basePath
=
$this
->
testFilePath
;
$srcDirName
=
'test_src_dir'
;
$srcDirName
=
$basePath
.
DIRECTORY_SEPARATOR
.
'test_src_dir'
;
mkdir
(
$srcDirName
,
0777
,
true
);
$files
=
array
(
$files
=
array
(
'file1.txt'
=>
'file 1 content'
,
'file1.txt'
=>
'file 1 content'
,
'file2.txt'
=>
'file 2 content'
,
'file2.txt'
=>
'file 2 content'
,
);
);
foreach
(
$files
as
$name
=>
$content
)
{
$this
->
createFileStructure
(
array
(
file_put_contents
(
$srcDirName
.
DIRECTORY_SEPARATOR
.
$name
,
$content
);
$srcDirName
=>
$files
}
));
$basePath
=
$this
->
testFilePath
;
$srcDirName
=
$basePath
.
DIRECTORY_SEPARATOR
.
$srcDirName
;
$dstDirName
=
$basePath
.
DIRECTORY_SEPARATOR
.
'test_dst_dir'
;
$dstDirName
=
$basePath
.
DIRECTORY_SEPARATOR
.
'test_dst_dir'
;
FileHelper
::
copyDirectory
(
$srcDirName
,
$dstDirName
);
FileHelper
::
copyDirectory
(
$srcDirName
,
$dstDirName
);
...
@@ -75,21 +97,20 @@ class FileHelperTest extends TestCase
...
@@ -75,21 +97,20 @@ class FileHelperTest extends TestCase
public
function
testRemoveDirectory
()
public
function
testRemoveDirectory
()
{
{
$basePath
=
$this
->
testFilePath
;
$dirName
=
'test_dir_for_remove'
;
$dirName
=
$basePath
.
DIRECTORY_SEPARATOR
.
'test_dir_for_remove'
;
$this
->
createFileStructure
(
array
(
mkdir
(
$dirName
,
0777
,
true
);
$dirName
=>
array
(
$files
=
array
(
'file1.txt'
=>
'file 1 content'
,
'file1.txt'
=>
'file 1 content'
,
'file2.txt'
=>
'file 2 content'
,
'file2.txt'
=>
'file 2 content'
,
);
'test_sub_dir'
=>
array
(
foreach
(
$files
as
$name
=>
$content
)
{
'sub_dir_file_1.txt'
=>
'sub dir file 1 content'
,
file_put_contents
(
$dirName
.
DIRECTORY_SEPARATOR
.
$name
,
$content
);
'sub_dir_file_2.txt'
=>
'sub dir file 2 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
)
;
$basePath
=
$this
->
testFilePath
;
}
$dirName
=
$basePath
.
DIRECTORY_SEPARATOR
.
$dirName
;
FileHelper
::
removeDirectory
(
$dirName
);
FileHelper
::
removeDirectory
(
$dirName
);
...
@@ -98,27 +119,25 @@ class FileHelperTest extends TestCase
...
@@ -98,27 +119,25 @@ class FileHelperTest extends TestCase
public
function
testFindFiles
()
public
function
testFindFiles
()
{
{
$dirName
=
'test_dir'
;
$this
->
createFileStructure
(
array
(
$dirName
=>
array
(
'file_1.txt'
=>
'file 1 content'
,
'file_2.txt'
=>
'file 2 content'
,
'test_sub_dir'
=>
array
(
'file_1_1.txt'
=>
'sub dir file 1 content'
,
'file_1_2.txt'
=>
'sub dir file 2 content'
,
),
),
));
$basePath
=
$this
->
testFilePath
;
$basePath
=
$this
->
testFilePath
;
$expectedFiles
=
array
();
$dirName
=
$basePath
.
DIRECTORY_SEPARATOR
.
$dirName
;
$expectedFiles
=
array
(
$dirName
=
$basePath
.
DIRECTORY_SEPARATOR
.
'test_dir_for_remove'
;
$dirName
.
DIRECTORY_SEPARATOR
.
'file_1.txt'
,
mkdir
(
$dirName
,
0777
,
true
);
$dirName
.
DIRECTORY_SEPARATOR
.
'file_2.txt'
,
$files
=
array
(
$dirName
.
DIRECTORY_SEPARATOR
.
'test_sub_dir'
.
DIRECTORY_SEPARATOR
.
'file_1_1.txt'
,
'file1.txt'
=>
'file 1 content'
,
$dirName
.
DIRECTORY_SEPARATOR
.
'test_sub_dir'
.
DIRECTORY_SEPARATOR
.
'file_1_2.txt'
,
'file2.txt'
=>
'file 2 content'
,
);
);
foreach
(
$files
as
$name
=>
$content
)
{
$fileName
=
$dirName
.
DIRECTORY_SEPARATOR
.
$name
;
file_put_contents
(
$fileName
,
$content
);
$expectedFiles
[]
=
$fileName
;
}
$subDirName
=
$dirName
.
DIRECTORY_SEPARATOR
.
'test_sub_dir'
;
mkdir
(
$subDirName
,
0777
,
true
);
foreach
(
$files
as
$name
=>
$content
)
{
$fileName
=
$subDirName
.
DIRECTORY_SEPARATOR
.
$name
;
file_put_contents
(
$fileName
,
$content
);
$expectedFiles
[]
=
$fileName
;
}
$foundFiles
=
FileHelper
::
findFiles
(
$dirName
);
$foundFiles
=
FileHelper
::
findFiles
(
$dirName
);
sort
(
$expectedFiles
);
sort
(
$expectedFiles
);
...
...
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