1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
|
--TEST--
MongoDB\BSON\Int64 wraps 64-bit integers on 32-bit platforms
--SKIPIF--
<?php if (4 !== PHP_INT_SIZE) { die('skip Only for 32-bit platform'); } ?>
--FILE--
<?php
require_once __DIR__ . '/../utils/tools.php';
$tests = [
MongoDB\BSON\toPHP(MongoDB\BSON\fromJSON('{"max64": {"$numberLong": "9223372036854775807"}}')),
MongoDB\BSON\toPHP(MongoDB\BSON\fromJSON('{"min64": {"$numberLong": "-9223372036854775808"}}')),
MongoDB\BSON\toPHP(MongoDB\BSON\fromJSON('{"max32+1": {"$numberLong": "2147483648"}}')),
MongoDB\BSON\toPHP(MongoDB\BSON\fromJSON('{"min32-1": {"$numberLong": "-2147483649"}}')),
// Numbers within the range of 32-bit integers will not be wrapped
MongoDB\BSON\toPHP(MongoDB\BSON\fromJSON('{"max32": {"$numberLong": "2147483647"}}')),
MongoDB\BSON\toPHP(MongoDB\BSON\fromJSON('{"min32": {"$numberLong": "-2147483648"}}')),
MongoDB\BSON\toPHP(MongoDB\BSON\fromJSON('{"zero": {"$numberLong": "0"}}')),
];
foreach ($tests as $test) {
var_dump($test);
}
?>
===DONE===
<?php exit(0); ?>
--EXPECTF--
object(stdClass)#%d (%d) {
["max64"]=>
object(MongoDB\BSON\Int64)#%d (%d) {
["integer"]=>
string(19) "9223372036854775807"
}
}
object(stdClass)#%d (%d) {
["min64"]=>
object(MongoDB\BSON\Int64)#%d (%d) {
["integer"]=>
string(20) "-9223372036854775808"
}
}
object(stdClass)#%d (%d) {
["max32+1"]=>
object(MongoDB\BSON\Int64)#%d (%d) {
["integer"]=>
string(10) "2147483648"
}
}
object(stdClass)#%d (%d) {
["min32-1"]=>
object(MongoDB\BSON\Int64)#%d (%d) {
["integer"]=>
string(11) "-2147483649"
}
}
object(stdClass)#%d (%d) {
["max32"]=>
int(2147483647)
}
object(stdClass)#%d (%d) {
["min32"]=>
int(-2147483648)
}
object(stdClass)#%d (%d) {
["zero"]=>
int(0)
}
===DONE===
|