As mentioned in PHPLIB-1147, PHPLIB currently "prepares" Int64 objects as integer primitives so they can be easily compared in PHPUnit equality assertions. See:
- MongoDB\Tests\SpecTests\DocumentsMatchConstraint::prepareBSON() and
- MongoDB\Tests\UnifiedSpecTests\Constraint\Matches::prepare()
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.
- is related to
-
PHPC-2213 Support casting of Int64 objects to scalar integers
- Closed
-
PHPLIB-1147 Utilize Int64 constructor and integer casts in test suite
- Closed
- related to
-
PHPLIB-1165 Provide Int64Comparator as a library
- Backlog