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:
Eloy Lafuente (stronk7) 2021-02-25 12:25:33 +01:00
parent 8940f67486
commit 3dd26fe334
27 changed files with 139 additions and 143 deletions

View file

@ -719,8 +719,8 @@ class core_group_privacy_provider_testcase extends provider_testcase {
$this->assertCount(3, $contextlist);
// One of the user context is the one related to self-conversation. Let's test group contexts.
$this->assertContains($coursecontext1->id, $contextids);
$this->assertContains($coursecontext2->id, $contextids);
$this->assertContainsEquals($coursecontext1->id, $contextids);
$this->assertContainsEquals($coursecontext2->id, $contextids);
}
/**