Skip to content

Commit 98887ff

Browse files
committed
PHPC-438: Debug handler should display null for no WC error
1 parent 5732362 commit 98887ff

File tree

6 files changed

+20
-13
lines changed

6 files changed

+20
-13
lines changed

src/MongoDB/WriteResult.c

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -452,6 +452,7 @@ HashTable *php_phongo_writeresult_get_debug_info(zval *object, int *is_temp TSRM
452452
php_phongo_writeresult_t *intern;
453453
zval retval = zval_used_for_init;
454454
php_phongo_bson_state state = PHONGO_BSON_STATE_INITIALIZER;
455+
bson_iter_t iter;
455456

456457
intern = (php_phongo_writeresult_t *)zend_object_store_get_object(object TSRMLS_CC);
457458
*is_temp = 1;
@@ -479,10 +480,21 @@ HashTable *php_phongo_writeresult_get_debug_info(zval *object, int *is_temp TSRM
479480
bson_to_zval(bson_get_data(&intern->write_result.writeErrors), intern->write_result.writeErrors.len, &state);
480481
add_assoc_zval_ex(&retval, ZEND_STRS("writeErrors"), state.zchild);
481482

483+
if (!bson_empty0(&intern->write_result.writeConcernErrors) &&
484+
bson_iter_init(&iter, &intern->write_result.writeConcernErrors) &&
485+
bson_iter_next(&iter) &&
486+
BSON_ITER_HOLDS_DOCUMENT(&iter)) {
487+
uint32_t len;
488+
const uint8_t *data;
482489

483-
MAKE_STD_ZVAL(state.zchild);
484-
bson_to_zval(bson_get_data(&intern->write_result.writeConcernError), intern->write_result.writeConcernError.len, &state);
485-
add_assoc_zval_ex(&retval, ZEND_STRS("writeConcernError"), state.zchild);
490+
bson_iter_document(&iter, &len, &data);
491+
492+
MAKE_STD_ZVAL(state.zchild);
493+
bson_to_zval(data, len, &state);
494+
add_assoc_zval_ex(&retval, ZEND_STRS("writeConcernError"), state.zchild);
495+
} else {
496+
add_assoc_null_ex(&retval, ZEND_STRS("writeConcernError"));
497+
}
486498

487499
if (intern->write_concern) {
488500
zval *write_concern = NULL;

tests/replicaset/writeresult-getserver-002.phpt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,7 @@ object(MongoDB\Driver\WriteResult)#%d (%d) {
7777
array(0) {
7878
}
7979
["writeConcernError"]=>
80-
array(0) {
81-
}
80+
NULL
8281
["writeConcern"]=>
8382
array(%d) {
8483
["w"]=>

tests/server/server-executeBulkWrite-001.phpt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,7 @@ object(MongoDB\Driver\WriteResult)#%d (%d) {
6767
array(0) {
6868
}
6969
["writeConcernError"]=>
70-
array(0) {
71-
}
70+
NULL
7271
["writeConcern"]=>
7372
array(%d) {
7473
["w"]=>

tests/standalone/writeresult-isacknowledged-001.phpt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,7 @@ object(MongoDB\Driver\WriteResult)#%d (%d) {
3636
array(0) {
3737
}
3838
["writeConcernError"]=>
39-
array(0) {
40-
}
39+
NULL
4140
["writeConcern"]=>
4241
array(%d) {
4342
["w"]=>

tests/standalone/writeresult-isacknowledged-002.phpt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,7 @@ object(MongoDB\Driver\WriteResult)#%d (%d) {
3838
array(0) {
3939
}
4040
["writeConcernError"]=>
41-
array(0) {
42-
}
41+
NULL
4342
["writeConcern"]=>
4443
array(%d) {
4544
["w"]=>

tests/standalone/writeresult-isacknowledged-003.phpt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,7 @@ object(MongoDB\Driver\WriteResult)#%d (%d) {
3636
array(0) {
3737
}
3838
["writeConcernError"]=>
39-
array(0) {
40-
}
39+
NULL
4140
["writeConcern"]=>
4241
array(%d) {
4342
["w"]=>

0 commit comments

Comments
 (0)