MDL-71036 phpunit: assertContains() now performs strict comparison
commit3dd26fe33441d08c7fd3c5fd58b4d07b21d47463
authorEloy Lafuente (stronk7) <stronk7@moodle.org>
Thu, 25 Feb 2021 11:25:33 +0000 (25 12:25 +0100)
committerEloy Lafuente (stronk7) <stronk7@moodle.org>
Thu, 11 Mar 2021 22:07:31 +0000 (11 23:07 +0100)
tree0ec4fb401f869d97650e1645cbc75717f7324d5d
parent8940f6748607d53e076bf8407f075922038a8a30
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
27 files changed:
admin/tool/dataprivacy/tests/api_test.php
admin/tool/dataprivacy/tests/expired_contexts_test.php
analytics/tests/prediction_test.php
blog/tests/privacy_test.php
calendar/tests/rrule_manager_test.php
cohort/tests/privacy_test.php
competency/tests/api_test.php
contentbank/tests/privacy_test.php
course/tests/courselib_test.php
enrol/flatfile/tests/privacy_provider_test.php
enrol/paypal/tests/privacy_provider_test.php
files/tests/privacy_test.php
grade/grading/tests/privacy_test.php
group/tests/privacy_provider_test.php
lib/tests/grouplib_test.php
message/tests/api_test.php
message/tests/externallib_test.php
message/tests/privacy_provider_test.php
mod/assign/submission/comments/tests/privacy_test.php
mod/assign/tests/locallib_test.php
mod/data/tests/search_test.php
mod/h5pactivity/tests/privacy_test.php
mod/quiz/accessrule/seb/tests/quiz_settings_test.php
mod/quiz/accessrule/seb/tests/rule_test.php
mod/scorm/tests/privacy_test.php
privacy/tests/contextlist_test.php
question/type/random/tests/questiontype_test.php