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
12 changes: 9 additions & 3 deletions src/MongoDB/WriteConcern.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,17 @@ PHP_METHOD(WriteConcern, __construct)
zval *w;
long wtimeout = 0;
zend_bool journal = 0;
zend_bool journal_is_null = 0;
zend_bool fsync = 0;
zend_bool fsync_is_null = 0;

(void)return_value; (void)return_value_ptr; (void)return_value_used;


zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling TSRMLS_CC);
intern = (php_phongo_writeconcern_t *)zend_object_store_get_object(getThis() TSRMLS_CC);

if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z|lbb", &w, &wtimeout, &journal, &fsync) == FAILURE) {
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z|lb!b!", &w, &wtimeout, &journal, &journal_is_null, &fsync, &fsync_is_null) == FAILURE) {
zend_restore_error_handling(&error_handling TSRMLS_CC);
return;
}
Expand Down Expand Up @@ -92,10 +94,14 @@ PHP_METHOD(WriteConcern, __construct)

switch(ZEND_NUM_ARGS()) {
case 4:
mongoc_write_concern_set_fsync(intern->write_concern, fsync);
if (!fsync_is_null) {
mongoc_write_concern_set_fsync(intern->write_concern, fsync);
}
/* fallthrough */
case 3:
mongoc_write_concern_set_journal(intern->write_concern, journal);
if (!journal_is_null) {
mongoc_write_concern_set_journal(intern->write_concern, journal);
}
/* fallthrough */
case 2:
if (wtimeout < 0) {
Expand Down
40 changes: 40 additions & 0 deletions tests/writeConcern/writeconcern-ctor-001.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ var_dump(new MongoDB\Driver\WriteConcern("string", 7000, true, true));
var_dump(new MongoDB\Driver\WriteConcern("string", 8000, true, false));
var_dump(new MongoDB\Driver\WriteConcern("string", 9000, false, true));

var_dump(new MongoDB\Driver\WriteConcern("string", 10000, null));
var_dump(new MongoDB\Driver\WriteConcern("string", 11000, null, true));
var_dump(new MongoDB\Driver\WriteConcern("string", 12000, true, null));

?>
===DONE===
<?php exit(0); ?>
Expand Down Expand Up @@ -172,4 +176,40 @@ object(MongoDB\Driver\WriteConcern)#%d (%d) {
["journal"]=>
bool(false)
}
object(MongoDB\Driver\WriteConcern)#%d (%d) {
["w"]=>
string(6) "string"
["wmajority"]=>
bool(false)
["wtimeout"]=>
int(10000)
["fsync"]=>
NULL
["journal"]=>
NULL
}
object(MongoDB\Driver\WriteConcern)#%d (%d) {
["w"]=>
string(6) "string"
["wmajority"]=>
bool(false)
["wtimeout"]=>
int(11000)
["fsync"]=>
bool(true)
["journal"]=>
NULL
}
object(MongoDB\Driver\WriteConcern)#%d (%d) {
["w"]=>
string(6) "string"
["wmajority"]=>
bool(false)
["wtimeout"]=>
int(12000)
["fsync"]=>
NULL
["journal"]=>
bool(true)
}
===DONE===
2 changes: 1 addition & 1 deletion tests/writeConcern/writeconcern-getfsync-001.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,6 @@ bool(true)
bool(false)
bool(true)
bool(false)
bool(false)
NULL
NULL
===DONE===
2 changes: 1 addition & 1 deletion tests/writeConcern/writeconcern-getjournal-001.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,6 @@ bool(true)
bool(false)
bool(true)
bool(false)
bool(false)
NULL
NULL
===DONE===