Skip to content

Commit 63d205f

Browse files
committed
Merge pull request #734
2 parents 1332775 + 37b8eaf commit 63d205f

19 files changed

+387
-1
lines changed

php_phongo.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,6 @@ zend_bool phongo_writeconcernerror_init(zval *return_value, bson_t *bson TSRMLS_
196196
ALLOC_HASHTABLE(props); \
197197
zend_hash_init((props), (size), NULL, ZVAL_PTR_DTOR, 0); \
198198
} else if ((intern)->properties) { \
199-
zend_hash_clean((intern)->properties); \
200199
(props) = (intern)->properties; \
201200
} else { \
202201
ALLOC_HASHTABLE(props); \
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
--TEST--
2+
MongoDB\BSON\Binary get_properties handler (get_object_vars)
3+
--FILE--
4+
<?php
5+
6+
$binary = new MongoDB\BSON\Binary('foobar', MongoDB\BSON\Binary::TYPE_GENERIC);
7+
8+
var_dump(get_object_vars($binary));
9+
10+
?>
11+
===DONE===
12+
<?php exit(0); ?>
13+
--EXPECT--
14+
array(2) {
15+
["data"]=>
16+
string(6) "foobar"
17+
["type"]=>
18+
int(0)
19+
}
20+
===DONE===
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
--TEST--
2+
MongoDB\BSON\Binary get_properties handler (foreach)
3+
--FILE--
4+
<?php
5+
6+
$binary = new MongoDB\BSON\Binary('foobar', MongoDB\BSON\Binary::TYPE_GENERIC);
7+
8+
foreach ($binary as $key => $value) {
9+
var_dump($key);
10+
var_dump($value);
11+
}
12+
13+
?>
14+
===DONE===
15+
<?php exit(0); ?>
16+
--EXPECT--
17+
string(4) "data"
18+
string(6) "foobar"
19+
string(4) "type"
20+
int(0)
21+
===DONE===
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
--TEST--
2+
MongoDB\BSON\DBPointer get_properties handler (get_object_vars)
3+
--FILE--
4+
<?php
5+
6+
$document = MongoDB\BSON\toPHP(MongoDB\BSON\fromJSON('{"dbptr":{"$dbPointer":{"$ref":"phongo.test","$id":{"$oid":"5a2e78accd485d55b405ac12"}}}}'));
7+
$dbptr = $document->dbptr;
8+
9+
var_dump(get_object_vars($dbptr));
10+
11+
?>
12+
===DONE===
13+
<?php exit(0); ?>
14+
--EXPECT--
15+
array(2) {
16+
["ref"]=>
17+
string(11) "phongo.test"
18+
["id"]=>
19+
string(24) "5a2e78accd485d55b405ac12"
20+
}
21+
===DONE===
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
--TEST--
2+
MongoDB\BSON\DBPointer get_properties handler (foreach)
3+
--FILE--
4+
<?php
5+
6+
$document = MongoDB\BSON\toPHP(MongoDB\BSON\fromJSON('{"dbptr":{"$dbPointer":{"$ref":"phongo.test","$id":{"$oid":"5a2e78accd485d55b405ac12"}}}}'));
7+
$dbptr = $document->dbptr;
8+
9+
foreach ($dbptr as $key => $value) {
10+
var_dump($key);
11+
var_dump($value);
12+
}
13+
14+
?>
15+
===DONE===
16+
<?php exit(0); ?>
17+
--EXPECT--
18+
string(3) "ref"
19+
string(11) "phongo.test"
20+
string(2) "id"
21+
string(24) "5a2e78accd485d55b405ac12"
22+
===DONE===
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
--TEST--
2+
MongoDB\BSON\Decimal128 get_properties handler (get_object_vars)
3+
--SKIPIF--
4+
<?php if (!class_exists('MongoDB\BSON\Decimal128')) { die('skip MongoDB\BSON\Decimal128 is not available'); } ?>
5+
--FILE--
6+
<?php
7+
8+
$decimal = new MongoDB\BSON\Decimal128('1234.5678');
9+
10+
var_dump(get_object_vars($decimal));
11+
12+
?>
13+
===DONE===
14+
<?php exit(0); ?>
15+
--EXPECT--
16+
array(1) {
17+
["dec"]=>
18+
string(9) "1234.5678"
19+
}
20+
===DONE===
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
--TEST--
2+
MongoDB\BSON\Decimal128 get_properties handler (foreach)
3+
--SKIPIF--
4+
<?php if (!class_exists('MongoDB\BSON\Decimal128')) { die('skip MongoDB\BSON\Decimal128 is not available'); } ?>
5+
--FILE--
6+
<?php
7+
8+
$decimal = new MongoDB\BSON\Decimal128('1234.5678');
9+
10+
foreach ($decimal as $key => $value) {
11+
var_dump($key);
12+
var_dump($value);
13+
}
14+
15+
?>
16+
===DONE===
17+
<?php exit(0); ?>
18+
--EXPECT--
19+
string(3) "dec"
20+
string(9) "1234.5678"
21+
===DONE===
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
--TEST--
2+
MongoDB\BSON\Javascript get_properties handler (get_object_vars)
3+
--FILE--
4+
<?php
5+
6+
$tests = [
7+
new MongoDB\BSON\Javascript('function foo(bar) { return bar; }'),
8+
new MongoDB\BSON\Javascript('function foo() { return bar; }', ['bar' => 42]),
9+
];
10+
11+
foreach ($tests as $test) {
12+
var_dump(get_object_vars($test));
13+
}
14+
15+
?>
16+
===DONE===
17+
<?php exit(0); ?>
18+
--EXPECTF--
19+
array(2) {
20+
["code"]=>
21+
string(33) "function foo(bar) { return bar; }"
22+
["scope"]=>
23+
NULL
24+
}
25+
array(2) {
26+
["code"]=>
27+
string(30) "function foo() { return bar; }"
28+
["scope"]=>
29+
object(stdClass)#%d (%d) {
30+
["bar"]=>
31+
int(42)
32+
}
33+
}
34+
===DONE===
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
--TEST--
2+
MongoDB\BSON\Javascript get_properties handler (foreach)
3+
--FILE--
4+
<?php
5+
6+
$tests = [
7+
new MongoDB\BSON\Javascript('function foo(bar) { return bar; }'),
8+
new MongoDB\BSON\Javascript('function foo() { return bar; }', ['bar' => 42]),
9+
];
10+
11+
foreach ($tests as $test) {
12+
foreach ($test as $key => $value) {
13+
var_dump($key);
14+
var_dump($value);
15+
}
16+
}
17+
18+
?>
19+
===DONE===
20+
<?php exit(0); ?>
21+
--EXPECTF--
22+
string(4) "code"
23+
string(33) "function foo(bar) { return bar; }"
24+
string(5) "scope"
25+
NULL
26+
string(4) "code"
27+
string(30) "function foo() { return bar; }"
28+
string(5) "scope"
29+
object(stdClass)#%d (%d) {
30+
["bar"]=>
31+
int(42)
32+
}
33+
===DONE===
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
--TEST--
2+
MongoDB\BSON\ObjectId get_properties handler (get_object_vars)
3+
--FILE--
4+
<?php
5+
6+
$oid = new MongoDB\BSON\ObjectId('53e2a1c40640fd72175d4603');
7+
8+
var_dump(get_object_vars($oid));
9+
10+
?>
11+
===DONE===
12+
<?php exit(0); ?>
13+
--EXPECT--
14+
array(1) {
15+
["oid"]=>
16+
string(24) "53e2a1c40640fd72175d4603"
17+
}
18+
===DONE===

0 commit comments

Comments
 (0)