Skip to content

Commit 56e5567

Browse files
committed
PHPC-274: Regression test for root BSON\Serializable encoding
1 parent 047bea5 commit 56e5567

File tree

1 file changed

+53
-0
lines changed

1 file changed

+53
-0
lines changed

tests/bson/bug0274.phpt

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
--TEST--
2+
Test for PHPC-274: zval_to_bson() should process BSON\Serializable instances
3+
--SKIPIF--
4+
<?php require __DIR__ . "/../utils/basic-skipif.inc"?>
5+
--FILE--
6+
<?php
7+
require_once __DIR__ . "/../utils/basic.inc";
8+
9+
class AssociativeArray implements BSON\Serializable
10+
{
11+
public function bsonSerialize()
12+
{
13+
return array("random" => "class", "data");
14+
}
15+
}
16+
17+
class NumericArray implements BSON\Serializable
18+
{
19+
public function bsonSerialize()
20+
{
21+
return array(1, 2, 3);
22+
}
23+
}
24+
25+
echo "Testing top-level AssociativeArray:\n";
26+
$bson = BSON\fromArray(new AssociativeArray);
27+
echo BSON\toJSON($bson), "\n";
28+
echo "Encoded BSON:\n";
29+
hex_dump($bson);
30+
31+
echo "\nTesting top-level NumericArray:\n";
32+
$bson = BSON\fromArray(new NumericArray);
33+
echo BSON\toJSON($bson), "\n";
34+
echo "Encoded BSON:\n";
35+
hex_dump($bson);
36+
37+
?>
38+
===DONE===
39+
<?php exit(0); ?>
40+
--EXPECT--
41+
Testing top-level AssociativeArray:
42+
{ "random" : "class", "0" : "data" }
43+
Encoded BSON:
44+
0 : 23 00 00 00 02 72 61 6e 64 6f 6d 00 06 00 00 00 [#....random.....]
45+
10 : 63 6c 61 73 73 00 02 30 00 05 00 00 00 64 61 74 [class..0.....dat]
46+
20 : 61 00 00 [a..]
47+
48+
Testing top-level NumericArray:
49+
{ "0" : 1, "1" : 2, "2" : 3 }
50+
Encoded BSON:
51+
0 : 1a 00 00 00 10 30 00 01 00 00 00 10 31 00 02 00 [.....0......1...]
52+
10 : 00 00 10 32 00 03 00 00 00 00 [...2......]
53+
===DONE===

0 commit comments

Comments
 (0)