Skip to content
  • Eloy Lafuente's avatar
    MDL-71036 phpunit: assertContains() now performs strict comparison · 8a14a7bd
    Eloy Lafuente authored
    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
    8a14a7bd