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: 2 additions & 0 deletions php_phongo.c
Original file line number Diff line number Diff line change
Expand Up @@ -1426,6 +1426,8 @@ void php_phongo_write_concern_to_zval(zval *retval, const mongoc_write_concern_t
add_assoc_string_ex(retval, ZEND_STRS("w"), (char *)PHONGO_WRITE_CONCERN_W_MAJORITY, 1);
} else if (w != MONGOC_WRITE_CONCERN_W_DEFAULT) {
add_assoc_long_ex(retval, ZEND_STRS("w"), w);
} else {
add_assoc_null_ex(retval, ZEND_STRS("w"));
}

add_assoc_bool_ex(retval, ZEND_STRS("wmajority"), mongoc_write_concern_get_wmajority(write_concern));
Expand Down
8 changes: 6 additions & 2 deletions src/MongoDB/WriteConcern.c
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ PHP_METHOD(WriteConcern, __construct)
}
/* }}} */

/* {{{ proto string|integer WriteConcern::getW()
/* {{{ proto string|integer|null WriteConcern::getW()
Returns the WriteConcern "w" option */
PHP_METHOD(WriteConcern, getW)
{
Expand All @@ -132,7 +132,11 @@ PHP_METHOD(WriteConcern, getW)
RETURN_STRING(PHONGO_WRITE_CONCERN_W_MAJORITY, 1);
}

RETURN_LONG(intern->write_concern->w);
if (intern->write_concern->w != MONGOC_WRITE_CONCERN_W_DEFAULT) {
RETURN_LONG(mongoc_write_concern_get_w(intern->write_concern));
}

RETURN_NULL();
}
/* }}} */

Expand Down
6 changes: 6 additions & 0 deletions tests/manager/manager-getwriteconcern-001.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ foreach ($tests as $i => $test) {
<?php exit(0); ?>
--EXPECTF--
object(MongoDB\Driver\WriteConcern)#%d (%d) {
["w"]=>
NULL
["wmajority"]=>
bool(false)
["wtimeout"]=>
Expand Down Expand Up @@ -106,6 +108,8 @@ object(MongoDB\Driver\WriteConcern)#%d (%d) {
bool(false)
}
object(MongoDB\Driver\WriteConcern)#%d (%d) {
["w"]=>
NULL
["wmajority"]=>
bool(false)
["wtimeout"]=>
Expand All @@ -116,6 +120,8 @@ object(MongoDB\Driver\WriteConcern)#%d (%d) {
NULL
}
object(MongoDB\Driver\WriteConcern)#%d (%d) {
["w"]=>
NULL
["wmajority"]=>
bool(false)
["wtimeout"]=>
Expand Down
4 changes: 3 additions & 1 deletion tests/replicaset/writeresult-getserver-002.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,9 @@ object(MongoDB\Driver\WriteResult)#%d (%d) {
array(0) {
}
["writeConcern"]=>
array(4) {
array(%d) {
["w"]=>
NULL
["wmajority"]=>
bool(false)
["wtimeout"]=>
Expand Down
4 changes: 3 additions & 1 deletion tests/server/server-executeBulkWrite-001.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,9 @@ object(MongoDB\Driver\WriteResult)#%d (%d) {
array(0) {
}
["writeConcern"]=>
array(4) {
array(%d) {
["w"]=>
NULL
["wmajority"]=>
bool(false)
["wtimeout"]=>
Expand Down
4 changes: 3 additions & 1 deletion tests/standalone/writeresult-isacknowledged-001.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ object(MongoDB\Driver\WriteResult)#%d (%d) {
array(0) {
}
["writeConcern"]=>
array(4) {
array(%d) {
["w"]=>
NULL
["wmajority"]=>
bool(false)
["wtimeout"]=>
Expand Down
6 changes: 3 additions & 3 deletions tests/writeConcern/writeconcern-debug-001.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ require_once __DIR__ . "/../utils/basic.inc";
* Although "w" will be omitted from the write concern sent to the server, we
* should still yield other fields in the debug output, which may be sent.
*/
$w = new MongoDB\Driver\WriteConcern(-2, 1000, true, true);

var_dump($w);
var_dump(new MongoDB\Driver\WriteConcern(-2, 1000, true, true));

?>
===DONE===
<?php exit(0); ?>
--EXPECTF--
object(MongoDB\Driver\WriteConcern)#%d (%d) {
["w"]=>
NULL
["wmajority"]=>
bool(false)
["wtimeout"]=>
Expand Down
53 changes: 53 additions & 0 deletions tests/writeConcern/writeconcern-debug-002.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
--TEST--
MongoDB\Driver\WriteConcern debug output
--SKIPIF--
<?php require __DIR__ . "/../utils/basic-skipif.inc"?>
--FILE--
<?php
require_once __DIR__ . "/../utils/basic.inc";

var_dump(new MongoDB\Driver\WriteConcern(1));
var_dump(new MongoDB\Driver\WriteConcern("tag", 1000, false, false));
var_dump(new MongoDB\Driver\WriteConcern(MongoDB\Driver\WriteConcern::MAJORITY, 500, true, true));

?>
===DONE===
<?php exit(0); ?>
--EXPECTF--
object(MongoDB\Driver\WriteConcern)#%d (%d) {
["w"]=>
int(1)
["wmajority"]=>
bool(false)
["wtimeout"]=>
int(0)
["fsync"]=>
NULL
["journal"]=>
NULL
}
object(MongoDB\Driver\WriteConcern)#%d (%d) {
["w"]=>
string(3) "tag"
["wmajority"]=>
bool(false)
["wtimeout"]=>
int(1000)
["fsync"]=>
bool(false)
["journal"]=>
bool(false)
}
object(MongoDB\Driver\WriteConcern)#%d (%d) {
["w"]=>
string(8) "majority"
["wmajority"]=>
bool(true)
["wtimeout"]=>
int(500)
["fsync"]=>
bool(true)
["journal"]=>
bool(true)
}
===DONE===
2 changes: 1 addition & 1 deletion tests/writeConcern/writeconcern-getw-001.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ foreach ($tests as $test) {
--EXPECT--
string(8) "majority"
string(8) "majority"
int(-2)
NULL
int(-1)
int(0)
int(1)
Expand Down