mirror of
https://github.com/moodle/moodle.git
synced 2025-08-06 17:36:38 +02:00
MDL-71036 phpunit: assertContains() now performs strict comparison
The methods assertContains() and assertNotContains() now perform strict (type and value) comparison, pretty much like assertSame() does. A couple of new assertContainsEquals() and assertNotContainsEquals() methods have been created to provide old (non-strict) behavior, pretty much like assertEquals() do. Apart from replacing the calls needing a relaxed comparison to those new methods, there are also a couple of alternative, about how to fix this, depending of every case: - If the test is making any array_values() conversion, then it's better to remove that conversion and use assertArrayHasKey(), that is not strict. - Sometimes if may be also possible to, simply, cast the expectation to the exact type coming in the array. I've not applied this technique to any of the cases in core. Link: https://github.com/sebastianbergmann/phpunit/issues/3426
This commit is contained in:
parent
8940f67486
commit
3dd26fe334
27 changed files with 139 additions and 143 deletions
|
@ -237,9 +237,9 @@ class tool_dataprivacy_api_testcase extends advanced_testcase {
|
|||
// There should only be one PO role.
|
||||
$this->assertCount(1, $roleids);
|
||||
// Confirm it contains the manager role.
|
||||
$this->assertContains($managerroleid, $roleids);
|
||||
$this->assertContainsEquals($managerroleid, $roleids);
|
||||
// And it does not contain the editing teacher role.
|
||||
$this->assertNotContains($editingteacherroleid, $roleids);
|
||||
$this->assertNotContainsEquals($editingteacherroleid, $roleids);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -838,7 +838,7 @@ class tool_dataprivacy_api_testcase extends advanced_testcase {
|
|||
$this->assertCount($filteredcount, $filteredrequests);
|
||||
// Confirm the filtered requests match the status filter(s).
|
||||
foreach ($filteredrequests as $request) {
|
||||
$this->assertContains($request->get('status'), $statuses);
|
||||
$this->assertContainsEquals($request->get('status'), $statuses);
|
||||
}
|
||||
|
||||
if ($numstatus > 1) {
|
||||
|
|
|
@ -950,8 +950,8 @@ class tool_dataprivacy_expired_contexts_testcase extends advanced_testcase {
|
|||
$forumlist = $userlist->get_userlist_for_component('mod_forum');
|
||||
$userids = $forumlist->get_userids();
|
||||
$this->assertCount(1, $userids);
|
||||
$this->assertContains($student->id, $userids);
|
||||
$this->assertNotContains($teacher->id, $userids);
|
||||
$this->assertContainsEquals($student->id, $userids);
|
||||
$this->assertNotContainsEquals($teacher->id, $userids);
|
||||
return true;
|
||||
}));
|
||||
|
||||
|
@ -1038,8 +1038,8 @@ class tool_dataprivacy_expired_contexts_testcase extends advanced_testcase {
|
|||
$forumlist = $userlist->get_userlist_for_component('mod_forum');
|
||||
$userids = $forumlist->get_userids();
|
||||
$this->assertCount(1, $userids);
|
||||
$this->assertContains($student->id, $userids);
|
||||
$this->assertNotContains($teacher->id, $userids);
|
||||
$this->assertContainsEquals($student->id, $userids);
|
||||
$this->assertNotContainsEquals($teacher->id, $userids);
|
||||
return true;
|
||||
}));
|
||||
|
||||
|
@ -1127,8 +1127,8 @@ class tool_dataprivacy_expired_contexts_testcase extends advanced_testcase {
|
|||
$forumlist = $userlist->get_userlist_for_component('mod_forum');
|
||||
$userids = $forumlist->get_userids();
|
||||
$this->assertCount(1, $userids);
|
||||
$this->assertContains($student->id, $userids);
|
||||
$this->assertNotContains($teacher->id, $userids);
|
||||
$this->assertContainsEquals($student->id, $userids);
|
||||
$this->assertNotContainsEquals($teacher->id, $userids);
|
||||
return true;
|
||||
}));
|
||||
|
||||
|
@ -1223,8 +1223,8 @@ class tool_dataprivacy_expired_contexts_testcase extends advanced_testcase {
|
|||
$forumlist = $userlist->get_userlist_for_component('mod_forum');
|
||||
$userids = $forumlist->get_userids();
|
||||
$this->assertCount(2, $userids);
|
||||
$this->assertContains($student->id, $userids);
|
||||
$this->assertContains($teacher->id, $userids);
|
||||
$this->assertContainsEquals($student->id, $userids);
|
||||
$this->assertContainsEquals($teacher->id, $userids);
|
||||
return true;
|
||||
}));
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue