|
| 1 | +--TEST-- |
| 2 | +BSON\fromPHP(): Encoding non-Serializable Type objects as a root element |
| 3 | +--INI-- |
| 4 | +date.timezone=America/Los_Angeles |
| 5 | +--SKIPIF-- |
| 6 | +<?php require __DIR__ . "/../utils/basic-skipif.inc"?> |
| 7 | +--FILE-- |
| 8 | +<?php |
| 9 | +use MongoDB\BSON as BSON; |
| 10 | + |
| 11 | +require_once __DIR__ . "/../utils/basic.inc"; |
| 12 | + |
| 13 | +class UnknownType implements BSON\Type {} |
| 14 | + |
| 15 | +$tests = array( |
| 16 | + new UnknownType, |
| 17 | + new BSON\Binary('foobar', BSON\Binary::TYPE_GENERIC), |
| 18 | + new BSON\Javascript('function foo(bar) {var baz = bar; var bar = foo; return bar; }'), |
| 19 | + new BSON\MinKey, |
| 20 | + new BSON\MaxKey, |
| 21 | + new BSON\ObjectId, |
| 22 | + new BSON\Regex('regexp', 'i'), |
| 23 | + new BSON\Timestamp(1234, 5678), |
| 24 | + new BSON\UTCDateTime('1416445411987'), |
| 25 | +); |
| 26 | + |
| 27 | +foreach ($tests as $document) { |
| 28 | + echo throws(function() use ($document) { |
| 29 | + fromPHP($document); |
| 30 | + }, 'MongoDB\Driver\Exception\UnexpectedValueException'), "\n";} |
| 31 | + |
| 32 | +?> |
| 33 | +===DONE=== |
| 34 | +<?php exit(0); ?> |
| 35 | +--EXPECTF-- |
| 36 | +OK: Got MongoDB\Driver\Exception\UnexpectedValueException |
| 37 | +UnknownType cannot be serialized as a root element |
| 38 | +OK: Got MongoDB\Driver\Exception\UnexpectedValueException |
| 39 | +%S\BSON\Binary cannot be serialized as a root element |
| 40 | +OK: Got MongoDB\Driver\Exception\UnexpectedValueException |
| 41 | +%S\BSON\Javascript cannot be serialized as a root element |
| 42 | +OK: Got MongoDB\Driver\Exception\UnexpectedValueException |
| 43 | +%S\BSON\MinKey cannot be serialized as a root element |
| 44 | +OK: Got MongoDB\Driver\Exception\UnexpectedValueException |
| 45 | +%S\BSON\MaxKey cannot be serialized as a root element |
| 46 | +OK: Got MongoDB\Driver\Exception\UnexpectedValueException |
| 47 | +%S\BSON\ObjectID cannot be serialized as a root element |
| 48 | +OK: Got MongoDB\Driver\Exception\UnexpectedValueException |
| 49 | +%S\BSON\Regex cannot be serialized as a root element |
| 50 | +OK: Got MongoDB\Driver\Exception\UnexpectedValueException |
| 51 | +%S\BSON\Timestamp cannot be serialized as a root element |
| 52 | +OK: Got MongoDB\Driver\Exception\UnexpectedValueException |
| 53 | +%S\BSON\UTCDateTime cannot be serialized as a root element |
| 54 | +===DONE=== |
0 commit comments