Skip to content

Commit

Permalink
MDL-67673 phpunit: Remove deprecated assertEquals() params
Browse files Browse the repository at this point in the history
The optional parameters of assertEquals() and assertNotEquals()
are deprecated in PHPUnit 8 (to be removed in PHPUnit 9):

- delta => use assertEqualsWithDelta()
- canonicalize => use assertEqualsCanonicalizing()
- ignoreCase => use assertEqualsIgnoringCase
- maxDepth => removed without replacement.

More info @ sebastianbergmann/phpunit#3341

Initial search done with:

ag 'assert(Not)?Equals\(.*,.*,' --php

Then, running tests and fixing remaining cases.
  • Loading branch information
stronk7 committed Oct 5, 2020
1 parent 301a8cb commit 46cfeab
Show file tree
Hide file tree
Showing 70 changed files with 220 additions and 263 deletions.
14 changes: 7 additions & 7 deletions admin/roles/tests/privacy_test.php
Expand Up @@ -536,7 +536,7 @@ public function test_get_users_in_context() {
$user1->id,
$admin->id
];
$this->assertEquals($expected, $userlist2->get_userids(), '', 0.0, 10, true);
$this->assertEqualsCanonicalizing($expected, $userlist2->get_userids());

// The user list for coursecontext1 should user1, user2 and admin (role creator).
$userlist3 = new \core_privacy\local\request\userlist($coursecontext1, $component);
Expand All @@ -547,7 +547,7 @@ public function test_get_users_in_context() {
$user2->id,
$admin->id
];
$this->assertEquals($expected, $userlist3->get_userids(), '', 0.0, 10, true);
$this->assertEqualsCanonicalizing($expected, $userlist3->get_userids());

// The user list for coursecatcontext should user2 and admin (role creator).
$userlist4 = new \core_privacy\local\request\userlist($coursecatcontext, $component);
Expand All @@ -557,7 +557,7 @@ public function test_get_users_in_context() {
$user2->id,
$admin->id
];
$this->assertEquals($expected, $userlist4->get_userids(), '', 0.0, 10, true);
$this->assertEqualsCanonicalizing($expected, $userlist4->get_userids());

// The user list for systemcontext should user1 and admin (role creator).
$userlist6 = new \core_privacy\local\request\userlist($systemcontext, $component);
Expand All @@ -567,7 +567,7 @@ public function test_get_users_in_context() {
$user1->id,
$admin->id
];
$this->assertEquals($expected, $userlist6->get_userids(), '', 0.0, 10, true);
$this->assertEqualsCanonicalizing($expected, $userlist6->get_userids());

// The user list for cmcontext should user1, user2 and admin (role creator).
$userlist7 = new \core_privacy\local\request\userlist($cmcontext, $component);
Expand All @@ -578,7 +578,7 @@ public function test_get_users_in_context() {
$user2->id,
$admin->id
];
$this->assertEquals($expected, $userlist7->get_userids(), '', 0.0, 10, true);
$this->assertEqualsCanonicalizing($expected, $userlist7->get_userids());

// The user list for blockcontext should user1 and admin (role creator).
$userlist8 = new \core_privacy\local\request\userlist($blockcontext, $component);
Expand All @@ -588,7 +588,7 @@ public function test_get_users_in_context() {
$user1->id,
$admin->id
];
$this->assertEquals($expected, $userlist8->get_userids(), '', 0.0, 10, true);
$this->assertEqualsCanonicalizing($expected, $userlist8->get_userids());
}

/**
Expand Down Expand Up @@ -744,4 +744,4 @@ protected static function get_roles_name() {
}
return $rolesnames;
}
}
}
2 changes: 1 addition & 1 deletion admin/tool/cohortroles/tests/privacy_test.php
Expand Up @@ -87,7 +87,7 @@ public function test_get_contexts_for_userid() {
CONTEXT_COURSECAT
];
// Test the User's contexts equal the system and course category context.
$this->assertEquals($expected, $contextlevels, '', 0, 10, true);
$this->assertEqualsCanonicalizing($expected, $contextlevels);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion admin/tool/dataprivacy/tests/manager_observer_test.php
Expand Up @@ -63,7 +63,7 @@ public function test_handle_component_failure() {
return $message->useridto;
}, $messages);

$this->assertEquals(array_keys($dpos), $messageusers, '', 0.0, 0, true);
$this->assertEqualsCanonicalizing(array_keys($dpos), $messageusers);
}

/**
Expand Down
10 changes: 3 additions & 7 deletions admin/tool/policy/tests/privacy_provider_test.php
Expand Up @@ -274,13 +274,9 @@ public function test_export_agreements_for_other() {
// Request export for the manager.
$contextlist = provider::get_contexts_for_userid($this->manager->id);
$this->assertCount(3, $contextlist);
$this->assertEquals(
$this->assertEqualsCanonicalizing(
[$managercontext->id, $usercontext->id, $systemcontext->id],
$contextlist->get_contextids(),
'',
0.0,
1,
true
$contextlist->get_contextids()
);

$approvedcontextlist = new approved_contextlist($this->user, 'tool_policy', [$usercontext->id]);
Expand Down Expand Up @@ -332,7 +328,7 @@ public function test_export_created_policies() {
// Agree to the policies for oneself.
$contextlist = provider::get_contexts_for_userid($this->manager->id);
$this->assertCount(2, $contextlist);
$this->assertEquals([$managercontext->id, $systemcontext->id], $contextlist->get_contextids(), '', 0.0, 1, true);
$this->assertEqualsCanonicalizing([$managercontext->id, $systemcontext->id], $contextlist->get_contextids());

$approvedcontextlist = new approved_contextlist($this->manager, 'tool_policy', $contextlist->get_contextids());
provider::export_user_data($approvedcontextlist);
Expand Down
2 changes: 1 addition & 1 deletion admin/tool/uploadcourse/tests/course_test.php
Expand Up @@ -1228,7 +1228,7 @@ public function test_custom_fields_data() {

// Confirm presence of course custom fields.
$data = \core_course\customfield\course_handler::create()->export_instance_data_object($course->id);
$this->assertEquals('Wednesday, 1 April 2020, 4:00 PM', $data->mydatefield, '', 0.0, 10, false, true);
$this->assertEqualsIgnoringCase('Wednesday, 1 April 2020, 4:00 PM', $data->mydatefield);
$this->assertEquals($dataupload['customfield_mytextfield'], $data->mytextfield);
$this->assertStringContainsString($dataupload['customfield_mytextareafield'], $data->mytextareafield);
}
Expand Down
5 changes: 1 addition & 4 deletions auth/oauth2/tests/auth_test.php
Expand Up @@ -42,10 +42,7 @@ public function test_get_password_change_info() {
$auth = get_auth_plugin($user->auth);
$info = $auth->get_password_change_info($user);

$this->assertEquals(
['subject', 'message'],
array_keys($info),
'', 0.0, 10, true);
$this->assertEqualsCanonicalizing(['subject', 'message'], array_keys($info));
$this->assertStringContainsString(
'your password cannot be reset because you are using your account on another site to log in',
$info['message']);
Expand Down
2 changes: 1 addition & 1 deletion backup/tests/privacy_provider_test.php
Expand Up @@ -482,7 +482,7 @@ public function test_delete_data_for_users() {
$this->assertCount(2, $userlist1);
$expected = [$user1->id, $user2->id];
$actual = $userlist1->get_userids();
$this->assertEquals($expected, $actual, '', 0.0, 10, true);
$this->assertEqualsCanonicalizing($expected, $actual);

// The list of users for coursecontext2 should not return users.
$userlist2 = new \core_privacy\local\request\userlist($coursecontext2, $component);
Expand Down
2 changes: 1 addition & 1 deletion blocks/comments/tests/privacy_provider_test.php
Expand Up @@ -209,7 +209,7 @@ public function test_get_contexts_for_userid() {
$this->assertCount(2, $contextlist);

$contextids = $contextlist->get_contextids();
$this->assertEquals([$coursecontext1->id, $coursecontext2->id], $contextids, '', 0.0, 10, true);
$this->assertEqualsCanonicalizing([$coursecontext1->id, $coursecontext2->id], $contextids);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion blog/tests/privacy_test.php
Expand Up @@ -690,7 +690,7 @@ public function test_export_data_for_user() {
$commentpath = array_merge($path, [get_string('commentsubcontext', 'core_comment')]);
if ($e->id == $e1->id) {
$tagdata = $writer->get_related_data($path, 'tags');
$this->assertEquals(['Beer', 'Golf'], $tagdata, '', 0, 10, true);
$this->assertEqualsCanonicalizing(['Beer', 'Golf'], $tagdata);

$comments = $writer->get_data($commentpath);
$this->assertCount(2, $comments->comments);
Expand Down
4 changes: 2 additions & 2 deletions cache/tests/fixtures/stores.php
Expand Up @@ -116,10 +116,10 @@ public function run_tests(cache_store $instance) {
// Test find and find with prefix if this class implements the searchable interface.
if ($instance->is_searchable()) {
// Extra settings here ignore the return order of the array.
$this->assertEquals(['test3', 'test1', 'test2', 'other3'], $instance->find_all(), '', 0, 1, true);
$this->assertEqualsCanonicalizing(['test3', 'test1', 'test2', 'other3'], $instance->find_all());

// Extra settings here ignore the return order of the array.
$this->assertEquals(['test2', 'test1', 'test3'], $instance->find_by_prefix('test'), '', 0, 1, true);
$this->assertEqualsCanonicalizing(['test2', 'test1', 'test3'], $instance->find_by_prefix('test'));
$this->assertEquals(['test2'], $instance->find_by_prefix('test2'));
$this->assertEquals(['other3'], $instance->find_by_prefix('other'));
$this->assertEquals([], $instance->find_by_prefix('nothere'));
Expand Down
13 changes: 5 additions & 8 deletions calendar/tests/lib_test.php
Expand Up @@ -827,10 +827,9 @@ public function test_calendar_set_filters_not_logged_in() {
$defaultcourses = calendar_get_default_courses(null, '*', false, $users[0]->id);
list($courseids, $groupids, $userid) = calendar_set_filters($defaultcourses);

$this->assertEquals(
$this->assertEqualsCanonicalizing(
[$courses[0]->id, $courses[1]->id, $courses[2]->id, SITEID],
array_values($courseids),
'', 0.0, 10, true);
array_values($courseids));
$this->assertFalse($groupids);
$this->assertFalse($userid);
}
Expand All @@ -853,10 +852,9 @@ public function test_calendar_set_filters_not_logged_in_with_user() {
$defaultcourses = calendar_get_default_courses(null, '*', false, $users[0]->id);
list($courseids, $groupids, $userid) = calendar_set_filters($defaultcourses, false, $users[0]);

$this->assertEquals(
$this->assertEqualsCanonicalizing(
[$courses[0]->id, $courses[1]->id, $courses[2]->id, SITEID],
array_values($courseids),
'', 0.0, 10, true);
array_values($courseids));
$this->assertEquals(array($coursegroups[$courses[0]->id][0]->id), $groupids);
$this->assertEquals($users[0]->id, $userid);

Expand All @@ -873,8 +871,7 @@ public function test_calendar_set_filters_logged_in_no_user() {
$this->setUser($users[0]);
$defaultcourses = calendar_get_default_courses(null, '*', false, $users[0]->id);
list($courseids, $groupids, $userid) = calendar_set_filters($defaultcourses, false);
$this->assertEquals([$courses[0]->id, $courses[1]->id, $courses[2]->id, SITEID], array_values($courseids), '', 0.0, 10,
true);
$this->assertEqualsCanonicalizing([$courses[0]->id, $courses[1]->id, $courses[2]->id, SITEID], array_values($courseids));
$this->assertEquals(array($coursegroups[$courses[0]->id][0]->id), $groupids);
$this->assertEquals($users[0]->id, $userid);
}
Expand Down
10 changes: 4 additions & 6 deletions calendar/tests/raw_event_retrieval_strategy_test.php
Expand Up @@ -402,10 +402,9 @@ public function test_get_raw_events_for_multiple_users() {
// Get all events.
$events = $retrievalstrategy->get_raw_events([$user1->id, $user2->id]);
$this->assertCount(2, $events);
$this->assertEquals(
$this->assertEqualsCanonicalizing(
['User1 Event', 'User2 Event'],
array_column($events, 'name'),
'', 0.0, 10, true);
array_column($events, 'name'));
}

public function test_get_raw_events_for_groups_with_no_members() {
Expand Down Expand Up @@ -442,9 +441,8 @@ public function test_get_raw_events_for_groups_with_no_members() {
// Get group eventsl.
$events = $retrievalstrategy->get_raw_events(null, [$group1->id, $group2->id]);
$this->assertCount(2, $events);
$this->assertEquals(
$this->assertEqualsCanonicalizing(
['Group 1 Event', 'Group 2 Event'],
array_column($events, 'name'),
'', 0.0, 10, true);
array_column($events, 'name'));
}
}
2 changes: 1 addition & 1 deletion course/tests/externallib_test.php
Expand Up @@ -240,7 +240,7 @@ public function test_get_categories() {
$returnedids[] = $category['id'];
}
// Sort the arrays upon comparision.
$this->assertEquals(array_keys($generatedcats), $returnedids, '', 0.0, 10, true);
$this->assertEqualsCanonicalizing(array_keys($generatedcats), $returnedids);

// Check different params.
$categories = core_course_external::get_categories(array(
Expand Down
4 changes: 2 additions & 2 deletions customfield/tests/privacy_test.php
Expand Up @@ -116,9 +116,9 @@ public function test_get_customfields_data_contexts() {
list($sql, $params) = $DB->get_in_or_equal([$courses[1]->id, $courses[2]->id], SQL_PARAMS_NAMED);
$r = provider::get_customfields_data_contexts('core_course', 'course', '=0',
$sql, $params);
$this->assertEquals([context_course::instance($courses[1]->id)->id,
$this->assertEqualsCanonicalizing([context_course::instance($courses[1]->id)->id,
context_course::instance($courses[2]->id)->id],
$r->get_contextids(), '', 0, 10, true);
$r->get_contextids());
}

/**
Expand Down
12 changes: 4 additions & 8 deletions enrol/flatfile/tests/privacy_provider_test.php
Expand Up @@ -218,11 +218,9 @@ public function test_get_users_in_context() {
// We expect to see 3 entries for course1, and that's user1, user3 and user4.
$userlist = new \core_privacy\local\request\userlist($this->coursecontext1, 'enrol_flatfile');
provider::get_users_in_context($userlist);
$this->assertEquals(
$this->assertEqualsCanonicalizing(
[$this->user1->id, $this->user3->id, $this->user4->id],
$userlist->get_userids(),
'', 0.0, 10, true
);
$userlist->get_userids());

// And 1 for course2 which is for user2.
$userlist = new \core_privacy\local\request\userlist($this->coursecontext2, 'enrol_flatfile');
Expand All @@ -247,11 +245,9 @@ public function test_delete_data_for_users() {
// Verify we have 3 future enrolment for user 1, user 3 and user 4.
$userlist = new \core_privacy\local\request\userlist($this->coursecontext1, 'enrol_flatfile');
provider::get_users_in_context($userlist);
$this->assertEquals(
$this->assertEqualsCanonicalizing(
[$this->user1->id, $this->user3->id, $this->user4->id],
$userlist->get_userids(),
'', 0.0, 10, true
);
$userlist->get_userids());

$approveduserlist = new \core_privacy\local\request\approved_userlist($this->coursecontext1, 'enrol_flatfile',
[$this->user1->id, $this->user3->id]);
Expand Down
7 changes: 3 additions & 4 deletions enrol/lti/tests/privacy_provider_test.php
Expand Up @@ -92,7 +92,7 @@ public function test_get_contexts_for_userid() {
$expectedids = [$coursectx->id, $activityctx->id];

$actualids = $contextlist->get_contextids();
$this->assertEquals($expectedids, $actualids, '', 0.0, 10, true);
$this->assertEqualsCanonicalizing($expectedids, $actualids);
}

/**
Expand Down Expand Up @@ -211,10 +211,9 @@ public function test_get_users_in_context_course() {
$userlist = new \core_privacy\local\request\userlist($coursecontext, 'enrol_paypal');
provider::get_users_in_context($userlist);

$this->assertEquals(
$this->assertEqualsCanonicalizing(
[$this->user->id, $this->anotheruser->id],
$userlist->get_userids(),
'', 0.0, 10, true);
$userlist->get_userids());
}

/**
Expand Down
5 changes: 2 additions & 3 deletions enrol/meta/tests/privacy_test.php
Expand Up @@ -294,9 +294,8 @@ public function test_get_users_in_context() {
$userlist = new \core_privacy\local\request\userlist($context, 'enrol_meta');
\enrol_meta\privacy\provider::get_users_in_context($userlist);

$this->assertEquals(
$this->assertEqualsCanonicalizing(
[$user1->id, $user2->id],
$userlist->get_userids(),
'', 0.0, 10, true);
$userlist->get_userids());
}
}

0 comments on commit 46cfeab

Please sign in to comment.