mirror of
https://github.com/yiisoft/yii2.git
synced 2025-08-15 06:40:59 +08:00
added test for ArrayHelper::multisort() with closure key
related to #13248
This commit is contained in:
@ -298,6 +298,32 @@ class ArrayHelperTest extends TestCase
|
||||
$this->assertEquals(['name' => 'b', 'age' => 3], $array[2]);
|
||||
}
|
||||
|
||||
public function testMultisortClosure()
|
||||
{
|
||||
$changelog = [
|
||||
'- Enh #123: test1',
|
||||
'- Bug #125: test2',
|
||||
'- Bug #123: test2',
|
||||
'- Enh: test3',
|
||||
'- Bug: test4',
|
||||
];
|
||||
$i = 0;
|
||||
ArrayHelper::multisort($changelog, function($line) use (&$i) {
|
||||
if (preg_match('/^- (Enh|Bug)( #\d+)?: .+$/', $line, $m)) {
|
||||
$o = ['Bug' => 'C', 'Enh' => 'D'];
|
||||
return $o[$m[1]] . ' ' . (!empty($m[2]) ? $m[2] : 'AAAA' . $i++);
|
||||
}
|
||||
return 'B' . $i++;
|
||||
}, SORT_ASC, SORT_NATURAL);
|
||||
$this->assertEquals([
|
||||
'- Bug #123: test2',
|
||||
'- Bug #125: test2',
|
||||
'- Bug: test4',
|
||||
'- Enh #123: test1',
|
||||
'- Enh: test3',
|
||||
], $changelog);
|
||||
}
|
||||
|
||||
public function testMerge()
|
||||
{
|
||||
$a = [
|
||||
|
Reference in New Issue
Block a user