summaryrefslogtreecommitdiffstats
path: root/apps/comments
diff options
context:
space:
mode:
Diffstat (limited to 'apps/comments')
-rw-r--r--apps/comments/lib/Collaboration/CommentersSorter.php17
-rw-r--r--apps/comments/tests/Unit/Collaboration/CommentersSorterTest.php2
2 files changed, 15 insertions, 4 deletions
diff --git a/apps/comments/lib/Collaboration/CommentersSorter.php b/apps/comments/lib/Collaboration/CommentersSorter.php
index e89a66f148d..8a24592c30b 100644
--- a/apps/comments/lib/Collaboration/CommentersSorter.php
+++ b/apps/comments/lib/Collaboration/CommentersSorter.php
@@ -58,12 +58,23 @@ class CommentersSorter implements ISorter {
continue;
}
- usort($byType, function ($a, $b) use ($commenters, $type) {
- $r = $this->compare($a, $b, $commenters[$type]);
+ // at least on PHP 5.6 usort turned out to be not stable. So we add
+ // the current index to the value and compare it on a draw
+ $i = 0;
+ $workArray = array_map(function($element) use (&$i) {
+ return [$i++, $element];
+ }, $byType);
+
+ usort($workArray, function ($a, $b) use ($commenters, $type) {
+ $r = $this->compare($a[1], $b[1], $commenters[$type]);
+ if($r === 0) {
+ $r = $a[0] - $b[0];
+ }
return $r;
});
- $s = '';
+ // and remove the index values again
+ $byType = array_column($workArray, 1);
}
}
diff --git a/apps/comments/tests/Unit/Collaboration/CommentersSorterTest.php b/apps/comments/tests/Unit/Collaboration/CommentersSorterTest.php
index 495dee1f416..95a74f118c0 100644
--- a/apps/comments/tests/Unit/Collaboration/CommentersSorterTest.php
+++ b/apps/comments/tests/Unit/Collaboration/CommentersSorterTest.php
@@ -59,7 +59,7 @@ class CommentersSorterTest extends TestCase {
$workArray = $data['input'];
$this->sorter->sort($workArray, ['itemType' => 'files', 'itemId' => '24']);
- $this->assertSame($data['expected'], $workArray);
+ $this->assertEquals($data['expected'], $workArray);
}
public function sortDataProvider() {