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

Create Comparator for Int64 objects and numeric primitives

    • Type: Icon: Task Task
    • Resolution: Fixed
    • Priority: Icon: Minor - P4 Minor - P4
    • 1.16.0
    • Affects Version/s: None
    • Component/s: Tests
    • Labels:
      None

      As mentioned in PHPLIB-1147, PHPLIB currently "prepares" Int64 objects as integer primitives so they can be easily compared in PHPUnit equality assertions. See:

      This code could likely be removed if we created and registered a custom Comparator that supported comparisons between Int64 objects and other numeric types.

      Consider the following snippet:

      $int64 = new MongoDB\BSON\Int64(1);
      
      var_dump(1 == $int64); // true
      var_dump(2 == $int64); // false
      
      var_dump(1.0 == $int64); // true
      var_dump(1.1 == $int64); // false
      

      Note that the Comparator factory in PHPUnit is a singleton by default. Before registering a custom Comparator for the benefit of these two BSON matching constraints we should make sure that this won't adversely affect other parts of the test suite, which might need to differentiate between Int64 objects and primitives (unlikely, but worth checking). If it is possible to only utilize this comparator in the two constraints above, that would also be reasonable.

            Assignee:
            andreas.braun@mongodb.com Andreas Braun
            Reporter:
            jmikola@mongodb.com Jeremy Mikola
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: