From c4857176ac30b51ffc14880562c63c048932cfe0 Mon Sep 17 00:00:00 2001 From: Carsten Brandt Date: Tue, 20 Dec 2016 14:14:01 +0100 Subject: [PATCH] added test for ArrayHelper::multisort() with closure key related to #13248 --- tests/framework/helpers/ArrayHelperTest.php | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/tests/framework/helpers/ArrayHelperTest.php b/tests/framework/helpers/ArrayHelperTest.php index ac02760..224ef06 100644 --- a/tests/framework/helpers/ArrayHelperTest.php +++ b/tests/framework/helpers/ArrayHelperTest.php @@ -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 = [