Uploaded image for project: 'PHP Driver: Library'
  1. PHP Driver: Library
  2. PHPLIB-1577

Matches constraint should never consider strings equal to numeric types

    • Type: Icon: Bug Bug
    • Resolution: Unresolved
    • Priority: Icon: Minor - P4 Minor - P4
    • None
    • Affects Version/s: None
    • Component/s: Unified Test Runner
    • PHP Drivers
    • Not Needed

      Matches::assertEquals() relies on PHPUnit's comparators for comparing values within documents. The default comparators defer to PHP's comparison logic, which is too liberal for the flexible numeric comparisons called for by the unified test format. When comparing documents, strings should never be considered equivalent to integers or doubles.

      Since SebastianBergmann\Comparator\Factory::getComparatorFor() prefers custom comparators over the PHPUnit defaults, we may be able to work around this by creating another custom comparator (as we did with Int64Comparator) to handle numeric comparisons and reject numeric strings outright. This might have added side effects on the rest of our test suite, but it's unlikely that we'd rely on that behavior – especially since we tend to do strict comparisons (e.g. assertSame()) whenever possible.

      Separately, we may want to reconsider whether Int64Comparator should accept string values, as it also defers to is_numeric() and the internal Int64 comparison handler, which does allow strings.

            Assignee:
            jmikola@mongodb.com Jeremy Mikola
            Reporter:
            jmikola@mongodb.com Jeremy Mikola
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated: