Skip to content

Commit 24f68ee

Browse files
committed
Merged pull request #665
2 parents 3314b93 + 20bbaf3 commit 24f68ee

File tree

3 files changed

+55
-60
lines changed

3 files changed

+55
-60
lines changed

src/bson.c

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ static bool php_phongo_bson_visit_array(const bson_iter_t *iter ARG_UNUSED, cons
4747

4848
static void php_phongo_bson_visit_corrupt(const bson_iter_t *iter ARG_UNUSED, void *data ARG_UNUSED) /* {{{ */
4949
{
50-
mongoc_log(MONGOC_LOG_LEVEL_TRACE, MONGOC_LOG_DOMAIN, "Corrupt BSON data detected!");
50+
mongoc_log(MONGOC_LOG_LEVEL_WARNING, MONGOC_LOG_DOMAIN, "Corrupt BSON data detected!");
5151
} /* }}} */
5252

5353
static void php_phongo_bson_visit_unsupported_type(const bson_iter_t *iter ARG_UNUSED, const char *key, uint32_t v_type_code, void *data ARG_UNUSED) /* {{{ */
@@ -131,8 +131,7 @@ static bool php_phongo_bson_visit_binary(const bson_iter_t *iter ARG_UNUSED, con
131131

132132
static bool php_phongo_bson_visit_undefined(const bson_iter_t *iter, const char *key, void *data) /* {{{ */
133133
{
134-
TSRMLS_FETCH();
135-
phongo_throw_exception(PHONGO_ERROR_UNEXPECTED_VALUE TSRMLS_CC, "Detected unsupported BSON type 0x06 (undefined) for fieldname \"%s\"", key);
134+
mongoc_log(MONGOC_LOG_LEVEL_WARNING, MONGOC_LOG_DOMAIN, "Detected unsupported BSON type 0x06 (undefined) for fieldname \"%s\"", key);
136135

137136
return false;
138137
} /* }}} */
@@ -285,8 +284,7 @@ static bool php_phongo_bson_visit_regex(const bson_iter_t *iter ARG_UNUSED, cons
285284

286285
static bool php_phongo_bson_visit_symbol(const bson_iter_t *iter, const char *key, size_t symbol_len, const char *symbol, void *data) /* {{{ */
287286
{
288-
TSRMLS_FETCH();
289-
phongo_throw_exception(PHONGO_ERROR_UNEXPECTED_VALUE TSRMLS_CC, "Detected unsupported BSON type 0x0E (symbol) for fieldname \"%s\"", key);
287+
mongoc_log(MONGOC_LOG_LEVEL_WARNING, MONGOC_LOG_DOMAIN, "Detected unsupported BSON type 0x0E (symbol) for fieldname \"%s\"", key);
290288

291289
return false;
292290
} /* }}} */
@@ -323,8 +321,7 @@ static bool php_phongo_bson_visit_code(const bson_iter_t *iter ARG_UNUSED, const
323321

324322
static bool php_phongo_bson_visit_dbpointer(const bson_iter_t *iter, const char *key, size_t collection_len, const char *collection, const bson_oid_t *oid, void *data) /* {{{ */
325323
{
326-
TSRMLS_FETCH();
327-
phongo_throw_exception(PHONGO_ERROR_UNEXPECTED_VALUE TSRMLS_CC, "Detected unsupported BSON type 0x0C (DBPointer) for fieldname \"%s\"", key);
324+
mongoc_log(MONGOC_LOG_LEVEL_WARNING, MONGOC_LOG_DOMAIN, "Detected unsupported BSON type 0x0C (DBPointer) for fieldname \"%s\"", key);
328325

329326
return false;
330327
} /* }}} */

tests/bson/bson-toPHP_error-005.phpt

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,30 @@
11
--TEST--
2-
MongoDB\BSON\toPHP(): BSON decoding exceptions for unsupported BSON types
2+
MongoDB\BSON\toPHP(): BSON decoding ignores unsupported BSON types
33
--FILE--
44
<?php
5-
6-
require_once __DIR__ . '/../utils/tools.php';
7-
85
$tests = [
96
pack('VCa*xx', 10, 0x06, 'foo'), // undefined
107
pack('VCa*xVa*xx12x', 37, 0x0C, 'foo', 11, 'collection'), // DBPointer
118
pack('VCa*xVa*xx', 18, 0x0E, 'foo', 4, 'bar'), // symbol
129
];
1310

11+
ini_set('mongodb.debug', 'stdout');
1412
foreach ($tests as $bson) {
15-
echo throws(function() use ($bson) {
16-
var_dump(toPHP($bson));
17-
}, 'MongoDB\Driver\Exception\UnexpectedValueException'), "\n";
13+
var_dump(MongoDB\BSON\toPHP($bson));
1814
}
15+
ini_set('mongodb.debug', 'off');
1916

2017
?>
2118
===DONE===
2219
<?php exit(0); ?>
23-
--EXPECT--
24-
OK: Got MongoDB\Driver\Exception\UnexpectedValueException
25-
Detected unsupported BSON type 0x06 (undefined) for fieldname "foo"
26-
OK: Got MongoDB\Driver\Exception\UnexpectedValueException
27-
Detected unsupported BSON type 0x0C (DBPointer) for fieldname "foo"
28-
OK: Got MongoDB\Driver\Exception\UnexpectedValueException
29-
Detected unsupported BSON type 0x0E (symbol) for fieldname "foo"
20+
--EXPECTF--
21+
[%s] PHONGO-BSON: WARNING > Detected unsupported BSON type 0x06 (undefined) for fieldname "foo"
22+
object(stdClass)#%d (%d) {
23+
}
24+
[%s] PHONGO-BSON: WARNING > Detected unsupported BSON type 0x0C (DBPointer) for fieldname "foo"
25+
object(stdClass)#%d (%d) {
26+
}
27+
[%s] PHONGO-BSON: WARNING > Detected unsupported BSON type 0x0E (symbol) for fieldname "foo"
28+
object(stdClass)#%d (%d) {
29+
}
3030
===DONE===

tests/bson/bson-toPHP_error-006.phpt

Lines changed: 37 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
--TEST--
2-
MongoDB\BSON\toPHP(): BSON decoding throws multiple exceptions
2+
MongoDB\BSON\toPHP(): BSON decoding shows multiple warnings
33
--FILE--
44
<?php
55

6-
require_once __DIR__ . '/../utils/tools.php';
7-
86
$tests = [
97
// two undefined fields in root document
108
pack('VCa*xCa*xx', 13, 0x06, 'u1', 0x06, 'u2'),
@@ -18,45 +16,45 @@ $tests = [
1816
pack('VCa*xVCa*xxCa*xVCa*xxx', 31, 0x03, 'e1', 9, 0x06, 'u1', 0x03, 'e2', 9, 0x06, 'u2'),
1917
];
2018

19+
ini_set('mongodb.debug', 'stdout');
2120
foreach ($tests as $bson) {
22-
try {
23-
var_dump(toPHP($bson));
24-
} catch (MongoDB\Driver\Exception\UnexpectedValueException $e) {
25-
do {
26-
printf("OK: %s\n%s\n", get_class($e), $e->getMessage());
27-
} while ($e = $e->getPrevious());
28-
}
29-
30-
echo "\n";
21+
var_dump(MongoDB\BSON\toPHP($bson));
3122
}
32-
23+
ini_set('mongodb.debug', 'off');
3324
?>
3425
===DONE===
3526
<?php exit(0); ?>
36-
--EXPECT--
37-
OK: MongoDB\Driver\Exception\UnexpectedValueException
38-
Detected unsupported BSON type 0x06 (undefined) for fieldname "u2"
39-
OK: MongoDB\Driver\Exception\UnexpectedValueException
40-
Detected unsupported BSON type 0x06 (undefined) for fieldname "u1"
41-
42-
OK: MongoDB\Driver\Exception\UnexpectedValueException
43-
Detected unsupported BSON type 0x0E (symbol) for fieldname "s1"
44-
OK: MongoDB\Driver\Exception\UnexpectedValueException
45-
Detected unsupported BSON type 0x06 (undefined) for fieldname "u1"
46-
47-
OK: MongoDB\Driver\Exception\UnexpectedValueException
48-
Detected unsupported BSON type 0x06 (undefined) for fieldname "u2"
49-
OK: MongoDB\Driver\Exception\UnexpectedValueException
50-
Detected unsupported BSON type 0x06 (undefined) for fieldname "u1"
51-
52-
OK: MongoDB\Driver\Exception\UnexpectedValueException
53-
Detected unsupported BSON type 0x06 (undefined) for fieldname "u2"
54-
OK: MongoDB\Driver\Exception\UnexpectedValueException
55-
Detected unsupported BSON type 0x06 (undefined) for fieldname "u1"
56-
57-
OK: MongoDB\Driver\Exception\UnexpectedValueException
58-
Detected unsupported BSON type 0x06 (undefined) for fieldname "u2"
59-
OK: MongoDB\Driver\Exception\UnexpectedValueException
60-
Detected unsupported BSON type 0x06 (undefined) for fieldname "u1"
61-
27+
--EXPECTF--
28+
[%s] PHONGO-BSON: WARNING > Detected unsupported BSON type 0x06 (undefined) for fieldname "u1"
29+
[%s] PHONGO-BSON: WARNING > Detected unsupported BSON type 0x06 (undefined) for fieldname "u2"
30+
object(stdClass)#%d (%d) {
31+
}
32+
[%s] PHONGO-BSON: WARNING > Detected unsupported BSON type 0x06 (undefined) for fieldname "u1"
33+
[%s] PHONGO-BSON: WARNING > Detected unsupported BSON type 0x0E (symbol) for fieldname "s1"
34+
object(stdClass)#%d (%d) {
35+
}
36+
[%s] PHONGO-BSON: WARNING > Detected unsupported BSON type 0x06 (undefined) for fieldname "u1"
37+
[%s] PHONGO-BSON: WARNING > Detected unsupported BSON type 0x06 (undefined) for fieldname "u2"
38+
object(stdClass)#%d (%d) {
39+
["e1"]=>
40+
object(stdClass)#%d (0) {
41+
}
42+
}
43+
[%s] PHONGO-BSON: WARNING > Detected unsupported BSON type 0x06 (undefined) for fieldname "u1"
44+
[%s] PHONGO-BSON: WARNING > Detected unsupported BSON type 0x06 (undefined) for fieldname "u2"
45+
object(stdClass)#%d (%d) {
46+
["e1"]=>
47+
object(stdClass)#%d (0) {
48+
}
49+
}
50+
[%s] PHONGO-BSON: WARNING > Detected unsupported BSON type 0x06 (undefined) for fieldname "u1"
51+
[%s] PHONGO-BSON: WARNING > Detected unsupported BSON type 0x06 (undefined) for fieldname "u2"
52+
object(stdClass)#%d (%d) {
53+
["e1"]=>
54+
object(stdClass)#%d (0) {
55+
}
56+
["e2"]=>
57+
object(stdClass)#%d (0) {
58+
}
59+
}
6260
===DONE===

0 commit comments

Comments
 (0)