Skip to content

Commit c43c5ab

Browse files
committed
Merge pull request #102
2 parents fef42a7 + 16e28a9 commit c43c5ab

File tree

2 files changed

+18
-13
lines changed

2 files changed

+18
-13
lines changed

src/bson.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -717,6 +717,11 @@ void object_to_bson(zval *object, php_phongo_bson_flags_t flags, const char *key
717717
return;
718718
}
719719
}
720+
721+
/* Even if we don't know how to encode the object, ensure that we at least
722+
* create an empty BSON document. */
723+
bson_append_document_begin(bson, key, key_len, &child);
724+
bson_append_document_end(bson, &child);
720725
}
721726
void phongo_bson_append(bson_t *bson, php_phongo_bson_flags_t flags, const char *key, long key_len, int entry_type, zval *entry TSRMLS_DC)
722727
{

tests/bson/bson-utcdatetime-001.phpt

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,21 +12,21 @@ $manager = new MongoDB\Driver\Manager(STANDALONE);
1212

1313
$classname = BSON_NAMESPACE . "\\UTCDateTime";
1414
$utcdatetime = new $classname("1416445411987");
15-
$result = $manager->executeInsert(NS, array('_id' => 1, 'x' => $utcdatetime));
16-
$query = new MongoDB\Driver\Query(array('_id' => 1));
17-
$cursor = $manager->executeQuery(NS, $query);
18-
$array = iterator_to_array($cursor);
1915

16+
$manager->executeInsert(NS, array('_id' => 1, 'x' => $utcdatetime));
2017

21-
$date = $utcdatetime->toDateTime();
22-
var_dump($date->format(DATE_RSS));
18+
$query = new MongoDB\Driver\Query(array('_id' => 1));
19+
$cursor = $manager->executeQuery(NS, $query);
20+
$results = iterator_to_array($cursor);
2321

24-
echo $utcdatetime, "\n";
22+
$datetime = $utcdatetime->toDateTime();
23+
var_dump($datetime->format(DATE_RSS));
24+
var_dump((string) $utcdatetime);
2525

2626
$tests = array(
2727
array($utcdatetime),
28-
array($array[0]->x),
29-
array($date),
28+
array($results[0]->x),
29+
array($datetime),
3030
);
3131

3232
foreach($tests as $n => $test) {
@@ -42,7 +42,7 @@ foreach($tests as $n => $test) {
4242
<?php exit(0); ?>
4343
--EXPECTF--
4444
string(31) "Thu, 20 Nov 2014 01:03:31 +0000"
45-
1416445411987
45+
string(13) "1416445411987"
4646
Test#0 { "0" : { "$date" : 1416445411987 } }
4747
string(37) "{ "0" : { "$date" : 1416445411987 } }"
4848
string(37) "{ "0" : { "$date" : 1416445411987 } }"
@@ -51,8 +51,8 @@ Test#1 { "0" : { "$date" : 1416445411987 } }
5151
string(37) "{ "0" : { "$date" : 1416445411987 } }"
5252
string(37) "{ "0" : { "$date" : 1416445411987 } }"
5353
bool(true)
54-
Test#2 { }
55-
string(3) "{ }"
56-
string(3) "{ }"
54+
Test#2 { "0" : { } }
55+
string(14) "{ "0" : { } }"
56+
string(14) "{ "0" : { } }"
5757
bool(false)
5858
===DONE===

0 commit comments

Comments
 (0)