Skip to content

Commit 9dff9d3

Browse files
committed
Add another test
1 parent f83cb3f commit 9dff9d3

File tree

1 file changed

+62
-0
lines changed

1 file changed

+62
-0
lines changed

tests/bson/bug2505_2.phpt

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
--TEST--
2+
PHPC-2505: Setting and unsetting a property may interfere with using foreach to iterate objects
3+
--FILE--
4+
<?php
5+
require_once __DIR__ . "/../utils/basic.inc";
6+
7+
$tests = [
8+
[ 'binary' => new MongoDB\BSON\Binary('foo', MongoDB\BSON\Binary::TYPE_GENERIC) ],
9+
[ 'dbpointer' => createDBPointer() ],
10+
[ 'decimal128' => new MongoDB\BSON\Decimal128('1234.5678') ],
11+
[ 'int64' => new MongoDB\BSON\Int64('9223372036854775807') ],
12+
// JavaScript w/ scope may not be necessary (same code path as w/o scope), but we'll test it anyway
13+
[ 'javascript' => new MongoDB\BSON\Javascript('function() { return 1; }') ],
14+
[ 'javascript_ws' => new MongoDB\BSON\Javascript('function() { return a; }', ['a' => 1]) ],
15+
// MaxKey and MinKey don't have get_properties or get_gc handlers, but we'll test them anyway
16+
[ 'maxkey' => new MongoDB\BSON\MaxKey ],
17+
[ 'minkey' => new MongoDB\BSON\MinKey ],
18+
[ 'objectid' => new MongoDB\BSON\ObjectId ],
19+
[ 'regex' => new MongoDB\BSON\Regex('pattern', 'i') ],
20+
[ 'symbol' => createSymbol() ],
21+
[ 'timestamp' => new MongoDB\BSON\Timestamp(1234, 5678) ],
22+
[ 'utcdatetime' => new MongoDB\BSON\UTCDateTime ],
23+
];
24+
25+
ob_start();
26+
foreach ($tests as $test) {
27+
echo key($test), "\n";
28+
$test = reset($test);
29+
30+
foreach ($test as $k => $v) {
31+
var_dump($k, $v);
32+
}
33+
}
34+
$buf1 = ob_get_clean();
35+
36+
foreach ($tests as $test) {
37+
$test = reset($test);
38+
$test->a = 'test';
39+
unset($test->a);
40+
}
41+
42+
ob_start();
43+
foreach ($tests as $test) {
44+
echo key($test), "\n";
45+
$test = reset($test);
46+
47+
foreach ($test as $k => $v) {
48+
var_dump($k, $v);
49+
}
50+
}
51+
$buf2 = ob_get_clean();
52+
53+
if ($buf1 === $buf2) {
54+
echo "OK!\n";
55+
exit(0);
56+
} else {
57+
echo("buf1 != buf2: $buf1\n!=\n$buf2\n");
58+
}
59+
60+
?>
61+
--EXPECT--
62+
OK!

0 commit comments

Comments
 (0)