|
| 1 | +--TEST-- |
| 2 | +BSON\fromJSON(): Decoding extended JSON types |
| 3 | +--SKIPIF-- |
| 4 | +<?php require __DIR__ . "/../utils/basic-skipif.inc"?> |
| 5 | +--FILE-- |
| 6 | +<?php |
| 7 | + |
| 8 | +require_once __DIR__ . "/../utils/basic.inc"; |
| 9 | + |
| 10 | +$tests = [ |
| 11 | + '{ "_id": { "$oid": "56315a7c6118fd1b920270b1" }}', |
| 12 | + '{ "binary": { "$binary": "Zm9v", "$type": "00" }}', |
| 13 | + '{ "date": { "$date": "2015-10-28T00:00:00Z" }}', |
| 14 | + '{ "timestamp": { "$timestamp": { "t": 1446084619, "i": 0 }}}', |
| 15 | + '{ "regex": { "$regex": "pattern", "$options": "i" }}', |
| 16 | + '{ "undef": { "$undefined": true }}', |
| 17 | + '{ "minkey": { "$minKey": 1 }}', |
| 18 | + '{ "maxkey": { "$maxKey": 1 }}', |
| 19 | + '{ "long": { "$numberLong": "1234" }}', |
| 20 | +]; |
| 21 | + |
| 22 | +foreach ($tests as $json) { |
| 23 | + printf("Test %s\n", $json); |
| 24 | + $bson = fromJSON($json); |
| 25 | + hex_dump($bson); |
| 26 | +} |
| 27 | + |
| 28 | +?> |
| 29 | +===DONE=== |
| 30 | +<?php exit(0); ?> |
| 31 | +--EXPECT-- |
| 32 | +Test { "_id": { "$oid": "56315a7c6118fd1b920270b1" }} |
| 33 | + 0 : 16 00 00 00 07 5f 69 64 00 56 31 5a 7c 61 18 fd [....._id.V1Z|a..] |
| 34 | + 10 : 1b 92 02 70 b1 00 [...p..] |
| 35 | +Test { "binary": { "$binary": "Zm9v", "$type": "00" }} |
| 36 | + 0 : 15 00 00 00 05 62 69 6e 61 72 79 00 03 00 00 00 [.....binary.....] |
| 37 | + 10 : 00 66 6f 6f 00 [.foo.] |
| 38 | +Test { "date": { "$date": "2015-10-28T00:00:00Z" }} |
| 39 | + 0 : 13 00 00 00 09 64 61 74 65 00 00 80 be ab 50 01 [.....date.....P.] |
| 40 | + 10 : 00 00 00 [...] |
| 41 | +Test { "timestamp": { "$timestamp": { "t": 1446084619, "i": 0 }}} |
| 42 | + 0 : 18 00 00 00 11 74 69 6d 65 73 74 61 6d 70 00 00 [.....timestamp..] |
| 43 | + 10 : 00 00 00 0b 80 31 56 00 [.....1V.] |
| 44 | +Test { "regex": { "$regex": "pattern", "$options": "i" }} |
| 45 | + 0 : 16 00 00 00 0b 72 65 67 65 78 00 70 61 74 74 65 [.....regex.patte] |
| 46 | + 10 : 72 6e 00 69 00 00 [rn.i..] |
| 47 | +Test { "undef": { "$undefined": true }} |
| 48 | + 0 : 0c 00 00 00 06 75 6e 64 65 66 00 00 [.....undef..] |
| 49 | +Test { "minkey": { "$minKey": 1 }} |
| 50 | + 0 : 0d 00 00 00 ff 6d 69 6e 6b 65 79 00 00 [.....minkey..] |
| 51 | +Test { "maxkey": { "$maxKey": 1 }} |
| 52 | + 0 : 0d 00 00 00 7f 6d 61 78 6b 65 79 00 00 [.....maxkey..] |
| 53 | +Test { "long": { "$numberLong": "1234" }} |
| 54 | + 0 : 13 00 00 00 12 6c 6f 6e 67 00 d2 04 00 00 00 00 [.....long.......] |
| 55 | + 10 : 00 00 00 [...] |
| 56 | +===DONE=== |
0 commit comments