Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/MongoDB/BulkWrite.c
Original file line number Diff line number Diff line change
Expand Up @@ -642,7 +642,7 @@ static HashTable* phongo_bulkwrite_get_debug_info(zend_object* object, int* is_t
if (mongoc_bulk_operation_get_write_concern(intern->bulk)) {
zval write_concern;

phongo_write_concern_to_zval(&write_concern, mongoc_bulk_operation_get_write_concern(intern->bulk));
phongo_writeconcern_init(&write_concern, mongoc_bulk_operation_get_write_concern(intern->bulk));
ADD_ASSOC_ZVAL_EX(&retval, "write_concern", &write_concern);
} else {
ADD_ASSOC_NULL_EX(&retval, "write_concern");
Expand Down
33 changes: 0 additions & 33 deletions src/MongoDB/WriteConcern.c
Original file line number Diff line number Diff line change
Expand Up @@ -388,36 +388,3 @@ const mongoc_write_concern_t* phongo_write_concern_from_zval(zval* zwrite_concer

return NULL;
}

void phongo_write_concern_to_zval(zval* retval, const mongoc_write_concern_t* write_concern)
{
const char* wtag = mongoc_write_concern_get_wtag(write_concern);
const int32_t w = mongoc_write_concern_get_w(write_concern);
const int64_t wtimeout = mongoc_write_concern_get_wtimeout_int64(write_concern);

array_init_size(retval, 4);

if (wtag) {
ADD_ASSOC_STRING(retval, "w", wtag);
} else if (mongoc_write_concern_get_wmajority(write_concern)) {
ADD_ASSOC_STRING(retval, "w", PHONGO_WRITE_CONCERN_W_MAJORITY);
} else if (w != MONGOC_WRITE_CONCERN_W_DEFAULT) {
ADD_ASSOC_LONG_EX(retval, "w", w);
}

if (mongoc_write_concern_journal_is_set(write_concern)) {
ADD_ASSOC_BOOL_EX(retval, "j", mongoc_write_concern_get_journal(write_concern));
}

if (wtimeout != 0) {
#if SIZEOF_ZEND_LONG == 4
if (wtimeout > INT32_MAX || wtimeout < INT32_MIN) {
ADD_ASSOC_INT64_AS_STRING(retval, "wtimeout", wtimeout);
} else {
ADD_ASSOC_LONG_EX(retval, "wtimeout", wtimeout);
}
#else
ADD_ASSOC_LONG_EX(retval, "wtimeout", wtimeout);
#endif
}
}
2 changes: 0 additions & 2 deletions src/MongoDB/WriteConcern.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,4 @@ void phongo_writeconcern_init(zval* return_value, const mongoc_write_concern_t*

const mongoc_write_concern_t* phongo_write_concern_from_zval(zval* zwrite_concern);

void phongo_write_concern_to_zval(zval* retval, const mongoc_write_concern_t* write_concern);

#endif /* PHONGO_WRITECONCERN_H */
4 changes: 3 additions & 1 deletion tests/bulk/write-0002.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,11 @@ object(MongoDB\Driver\BulkWrite)#%d (%d) {
["session"]=>
NULL
["write_concern"]=>
array(%d) {
object(MongoDB\Driver\WriteConcern)#%d (%d) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To make our intent explicit, we can add an assertion stating that this property is an instance of WriteConcern.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand this one. Is this not already clear from the debug output?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it's already clear. It’s just that I find it easier to modify an output snapshot by telling myself it’s a minor change. Whereas if it’s a specific assertion, we know that the result was intended.

Comment thread
paulinevos marked this conversation as resolved.
["w"]=>
int(1)
["j"]=>
NULL
["wtimeout"]=>
int(1000)
}
Expand Down
Loading