Commit f19a97e3 by Klimov Paul

Fix `yii\helpers\FileHelper::copyDirectory()` pattern not working

parent 243f0134
...@@ -25,6 +25,7 @@ Yii Framework 2 Change Log ...@@ -25,6 +25,7 @@ Yii Framework 2 Change Log
- Bug #3311: Fixed the bug that `yii\di\Container::has()` did not return correct value (mgrechanik, qiangxue) - Bug #3311: Fixed the bug that `yii\di\Container::has()` did not return correct value (mgrechanik, qiangxue)
- Bug #3327: Fixed "Unable to find debug data" when logging objects with circular references (jarekkozak, samdark) - Bug #3327: Fixed "Unable to find debug data" when logging objects with circular references (jarekkozak, samdark)
- Bug #3368: Fix for comparing numeric attributes in JavaScript (technixp) - Bug #3368: Fix for comparing numeric attributes in JavaScript (technixp)
- Bug #3393: Fix `yii\helpers\FileHelper::copyDirectory()` pattern not working (klimov-paul)
- Bug #3431: Allow using extended ErrorHandler class from the app namespace (cebe) - Bug #3431: Allow using extended ErrorHandler class from the app namespace (cebe)
- Bug #3436: Fixed the issue that `ServiceLocator` still returns the old component after calling `set()` with a new definition (qiangxue) - Bug #3436: Fixed the issue that `ServiceLocator` still returns the old component after calling `set()` with a new definition (qiangxue)
- Bug #3458: Fixed the bug that the image rendered by `CaptchaAction` was using a wrong content type (MDMunir, qiangxue) - Bug #3458: Fixed the bug that the image rendered by `CaptchaAction` was using a wrong content type (MDMunir, qiangxue)
......
...@@ -209,6 +209,9 @@ class BaseFileHelper ...@@ -209,6 +209,9 @@ class BaseFileHelper
if ($handle === false) { if ($handle === false) {
throw new InvalidParamException('Unable to open directory: ' . $src); throw new InvalidParamException('Unable to open directory: ' . $src);
} }
if (!isset($options['basePath'])) {
$options['basePath'] = realpath($src);
}
while (($file = readdir($handle)) !== false) { while (($file = readdir($handle)) !== false) {
if ($file === '.' || $file === '..') { if ($file === '.' || $file === '..') {
continue; continue;
......
...@@ -407,4 +407,42 @@ class FileHelperTest extends TestCase ...@@ -407,4 +407,42 @@ class FileHelperTest extends TestCase
FileHelper::localize($viewFile, $currentLanguage, $sourceLanguage) FileHelper::localize($viewFile, $currentLanguage, $sourceLanguage)
); );
} }
/**
* @see https://github.com/yiisoft/yii2/issues/3393
*
* @depends testCopyDirectory
* @depends testFindFiles
*/
public function testCopyDirectoryExclude()
{
$srcDirName = 'test_src_dir';
$textFiles = [
'file1.txt' => 'text file 1 content',
'file2.txt' => 'text file 2 content',
];
$dataFiles = [
'file1.dat' => 'data file 1 content',
'file2.dat' => 'data file 2 content',
];
$this->createFileStructure([
$srcDirName => array_merge($textFiles, $dataFiles)
]);
$basePath = $this->testFilePath;
$srcDirName = $basePath . DIRECTORY_SEPARATOR . $srcDirName;
$dstDirName = $basePath . DIRECTORY_SEPARATOR . 'test_dst_dir';
FileHelper::copyDirectory($srcDirName, $dstDirName, ['only' => ['*.dat']]);
$this->assertFileExists($dstDirName, 'Destination directory does not exist!');
$copiedFiles = FileHelper::findFiles($dstDirName);
$this->assertCount(2, $copiedFiles, 'wrong files count copied');
foreach ($dataFiles as $name => $content) {
$fileName = $dstDirName . DIRECTORY_SEPARATOR . $name;
$this->assertFileExists($fileName);
$this->assertEquals($content, file_get_contents($fileName), 'Incorrect file content!');
}
}
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment