Skip to content

Commit 212937d

Browse files
committed
PHPLIB-510: Improve handling of NULL and Int64 values in DocumentsMatchConstraint
1 parent 2549bef commit 212937d

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

tests/SpecTests/DocumentsMatchConstraint.php

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
use Symfony\Bridge\PhpUnit\ConstraintTrait;
3434
use function array_values;
3535
use function get_class;
36+
use function gettype;
3637
use function in_array;
3738
use function is_array;
3839
use function is_object;
@@ -313,19 +314,22 @@ private function assertEquals(ArrayObject $expected, ArrayObject $actual, $ignor
313314
continue;
314315
}
315316

317+
$expectedType = is_object($expectedValue) ? get_class($expectedValue) : gettype($expectedValue);
318+
$actualType = is_object($expectedValue) ? get_class($actualValue) : gettype($actualValue);
319+
316320
// Workaround for ObjectComparator printing the whole actual object
317-
if (get_class($expectedValue) !== get_class($actualValue)) {
321+
if ($expectedType !== $actualType) {
318322
throw new ComparisonFailure(
319323
$expectedValue,
320324
$actualValue,
321325
'',
322326
'',
323327
false,
324328
sprintf(
325-
'Field path "%s": %s is not instance of expected class "%s".',
329+
'Field path "%s": %s is not instance of expected type "%s".',
326330
$keyPrefix . $key,
327331
$this->exporter()->shortenedExport($actualValue),
328-
get_class($expectedValue)
332+
$expectedType
329333
)
330334
);
331335
}
@@ -441,6 +445,12 @@ private function prepareBSON($bson, $isRoot, $sortKeys = false)
441445
$bson[$key] = $this->prepareBSON($value, false, $sortKeys);
442446
continue;
443447
}
448+
449+
/* Convert Int64 objects to integers on 64-bit platforms for
450+
* compatibility reasons. */
451+
if ($value instanceof Int64 && PHP_INT_SIZE != 4) {
452+
$bson[$key] = (int) ((string) $value);
453+
}
444454
}
445455

446456
return $bson;

0 commit comments

Comments
 (0)