|
|
|
@ -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 = [ |
|
|
|
|