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
|
--TEST--
MongoDB\BSON\Javascript::__set_state()
--FILE--
<?php
$tests = [
['function foo(bar) { return bar; }', null],
['function foo(bar) { return bar; }', []],
['function foo() { return foo; }', ['foo' => 42]],
['function foo() { return id; }', ['id' => new MongoDB\BSON\ObjectId('53e2a1c40640fd72175d4603')]],
];
foreach ($tests as $test) {
list($code, $scope) = $test;
var_export(MongoDB\BSON\Javascript::__set_state([
'code' => $code,
'scope' => $scope,
]));
echo "\n\n";
}
// Test with missing scope field
var_export(MongoDB\BSON\Javascript::__set_state([
'code' => 'function foo(bar) { return bar; }',
]));
echo "\n\n";
?>
===DONE===
<?php exit(0); ?>
--EXPECTF--
%r\\?%rMongoDB\BSON\Javascript::__set_state(array(
%w'code' => 'function foo(bar) { return bar; }',
%w'scope' => NULL,
))
%r\\?%rMongoDB\BSON\Javascript::__set_state(array(
%w'code' => 'function foo(bar) { return bar; }',
%w'scope' =>
%Sarray(
%S),
))
%r\\?%rMongoDB\BSON\Javascript::__set_state(array(
%w'code' => 'function foo() { return foo; }',
%w'scope' =>
%Sarray(
%w'foo' => 42,
%S),
))
%r\\?%rMongoDB\BSON\Javascript::__set_state(array(
%w'code' => 'function foo() { return id; }',
%w'scope' =>
%Sarray(
%w'id' =>
%r\\?%rMongoDB\BSON\ObjectId::__set_state(array(
%w'oid' => '53e2a1c40640fd72175d4603',
)),
%S),
))
%r\\?%rMongoDB\BSON\Javascript::__set_state(array(
%w'code' => 'function foo(bar) { return bar; }',
%w'scope' => NULL,
))
===DONE===
|