Commit ff8e78c6 by Qiang Xue

Merge branch '2048-improve-messages-config-exceptions' of…

Merge branch '2048-improve-messages-config-exceptions' of github.com:nineinchnick/yii2 into nineinchnick-2048-improve-messages-config-exceptions Conflicts: framework/messages/config.php
parents 150d7136 26564fb9
......@@ -22,17 +22,14 @@ return [
// boolean, whether to remove messages that no longer appear in the source code.
// Defaults to false, which means each of these messages will be enclosed with a pair of '@@' marks.
'removeUnused' => false,
// array, list of patterns that specify which files/directories should be processed.
// array, list of patterns that specify which files/directories should NOT be processed.
// If empty or not set, all files/directories will be processed.
// A path matches a pattern if it contains the pattern string at its end. For example,
// '/a/b' will match all files and directories ending with '/a/b';
// and the '.svn' will match all files and directories whose name ends with '.svn'.
// the '*.svn' will match all files and directories whose name ends with '.svn'.
// and the '.svn' will match all files and directories named exactly '.svn'.
// Note, the '/' characters in a pattern matches both '/' and '\'.
// If a file/directory matches both a pattern in "only" and "except", it will NOT be processed.
'only' => ['.php'],
// array, list of patterns that specify which files/directories should NOT be processed.
// If empty or not set, all files/directories will be processed.
// Please refer to "only" for details about the patterns.
// See helpers/FileHelper::findFiles() description for more details on pattern matching rules.
'except' => [
'.svn',
'.git',
......@@ -42,8 +39,13 @@ return [
'.hgkeep',
'/messages',
],
// Generated file format. Can be either "php", "po" or "db".
// array, list of patterns that specify which files (not directories) should be processed.
// If empty or not set, all files will be processed.
// Please refer to "except" for details about the patterns.
// If a file/directory matches both a pattern in "only" and "except", it will NOT be processed.
'only' => ['*.php'],
// Generated file format. Can be "php", "db" or "po".
'format' => 'php',
// Connection component ID for "db".
//'connectionID' => 'db',
// Connection component ID for "db" format.
//'db' => 'db',
];
......@@ -22,17 +22,19 @@ return [
// boolean, whether to remove messages that no longer appear in the source code.
// Defaults to false, which means each of these messages will be enclosed with a pair of '@@' marks.
'removeUnused' => false,
// array, list of patterns that specify which files/directories should be processed.
// array, list of patterns that specify which files/directories should NOT be processed.
// If empty or not set, all files/directories will be processed.
// A path matches a pattern if it contains the pattern string at its end. For example,
// '/a/b' will match all files and directories ending with '/a/b';
// and the '.svn' will match all files and directories whose name ends with '.svn'.
// the '*.svn' will match all files and directories whose name ends with '.svn'.
// and the '.svn' will match all files and directories named exactly '.svn'.
// Note, the '/' characters in a pattern matches both '/' and '\'.
// If a file/directory matches both a pattern in "only" and "except", it will NOT be processed.
// See helpers/FileHelper::findFiles() description for more details on pattern matching rules.
'only' => ['.php'],
// array, list of patterns that specify which files/directories should NOT be processed.
// If empty or not set, all files/directories will be processed.
// Please refer to "only" for details about the patterns.
// array, list of patterns that specify which files (not directories) should be processed.
// If empty or not set, all files will be processed.
// Please refer to "except" for details about the patterns.
// If a file/directory matches both a pattern in "only" and "except", it will NOT be processed.
'except' => [
'.svn',
'.git',
......
......@@ -253,23 +253,58 @@ class FileHelperTest extends TestCase
*/
public function testFindFilesExclude()
{
$dirName = 'test_dir';
$fileName = 'test_file.txt';
$excludeFileName = 'exclude_file.txt';
$this->createFileStructure([
$dirName => [
$fileName => 'file content',
$excludeFileName => 'exclude file content',
],
]);
$basePath = $this->testFilePath;
$dirName = $basePath . DIRECTORY_SEPARATOR . $dirName;
$basePath = $this->testFilePath . DIRECTORY_SEPARATOR;
$dirs = array('', 'one', 'one'.DIRECTORY_SEPARATOR.'two', 'three');
$files = array_fill_keys(array_map(function($n){return "a.$n";}, range(1,8)), 'file contents');
$tree = $files;
$root = $files;
$flat = array();
foreach($dirs as $dir) {
foreach($files as $fileName=>$contents) {
$flat[] = rtrim($basePath.$dir,DIRECTORY_SEPARATOR).DIRECTORY_SEPARATOR.$fileName;
}
if ($dir === '') continue;
$parts = explode(DIRECTORY_SEPARATOR, $dir);
$last = array_pop($parts);
$parent = array_pop($parts);
$tree[$last] = $files;
if ($parent !== null) {
$tree[$parent][$last] = &$tree[$last];
} else {
$root[$last] = &$tree[$last];
}
}
$this->createFileStructure($root);
$options = [
'except' => [$excludeFileName],
];
$foundFiles = FileHelper::findFiles($dirName, $options);
$this->assertEquals([$dirName . DIRECTORY_SEPARATOR . $fileName], $foundFiles);
// range
$foundFiles = FileHelper::findFiles($basePath, ['except' => ['a.[2-8]']]);
sort($foundFiles);
$expect = array_values(array_filter($flat, function($p){return substr($p, -3)==='a.1';}));
$this->assertEquals($expect, $foundFiles);
// suffix
$foundFiles = FileHelper::findFiles($basePath, ['except' => ['*.1']]);
sort($foundFiles);
$expect = array_values(array_filter($flat, function($p){return substr($p, -3)!=='a.1';}));
$this->assertEquals($expect, $foundFiles);
// dir
$foundFiles = FileHelper::findFiles($basePath, ['except' => ['/one']]);
sort($foundFiles);
$expect = array_values(array_filter($flat, function($p){return strpos($p, DIRECTORY_SEPARATOR.'one')===false;}));
$this->assertEquals($expect, $foundFiles);
// dir contents
$foundFiles = FileHelper::findFiles($basePath, ['except' => ['?*/a.1']]);
sort($foundFiles);
$expect = array_values(array_filter($flat, function($p){
return substr($p, -11, 10)==='one'.DIRECTORY_SEPARATOR.'two'.DIRECTORY_SEPARATOR.'a.' || (
substr($p, -8)!==DIRECTORY_SEPARATOR.'one'.DIRECTORY_SEPARATOR.'a.1' &&
substr($p, -10)!==DIRECTORY_SEPARATOR.'three'.DIRECTORY_SEPARATOR.'a.1'
);
}));
$this->assertEquals($expect, $foundFiles);
}
public function testCreateDirectory()
......
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