Skip to content

Commit

Permalink
MDL-62393 message: Fix random unit test fails
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewnicols committed May 12, 2018
1 parent ab65b87 commit 823e08b
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions message/tests/privacy_provider_test.php
Expand Up @@ -210,6 +210,7 @@ public function test_export_for_context_with_contacts() {
$writer = writer::with_context(\context_system::instance());

$contacts = (array) $writer->get_data([get_string('contacts', 'core_message')]);
usort($contacts, ['static', 'sort_contacts']);

$this->assertCount(3, $contacts);

Expand Down Expand Up @@ -274,6 +275,7 @@ public function test_export_for_context_with_messages() {
$dbm2 = $DB->get_record('messages', ['id' => $m2]);
$dbm3 = $DB->get_record('messages', ['id' => $m3]);

usort($messages, ['static', 'sort_messages']);
$m1 = array_shift($messages);
$m2 = array_shift($messages);
$m3 = array_shift($messages);
Expand Down Expand Up @@ -303,6 +305,7 @@ public function test_export_for_context_with_messages() {
$dbm5 = $DB->get_record('messages', ['id' => $m5]);
$dbm6 = $DB->get_record('messages', ['id' => $m6]);

usort($messages, ['static', 'sort_messages']);
$m4 = array_shift($messages);
$m5 = array_shift($messages);
$m6 = array_shift($messages);
Expand Down Expand Up @@ -584,4 +587,26 @@ private function create_notification(int $useridfrom, int $useridto, int $timecr

return $DB->insert_record('notifications', $record);
}

/**
* Comparison function for sorting messages.
*
* @param \stdClass $a
* @param \stdClass $b
* @return bool
*/
protected static function sort_messages($a, $b) {
return $a->message > $b->message;
}

/**
* Comparison function for sorting contacts.
*
* @param \stdClass $a
* @param \stdClass $b
* @return bool
*/
protected static function sort_contacts($a, $b) {
return $a->contact > $b->contact;
}
}

0 comments on commit 823e08b

Please sign in to comment.