Skip to content

Commit a6932d5

Browse files
committed
PHPC-423: WriteConcern should report default "w" option as null
1 parent 9c38811 commit a6932d5

File tree

8 files changed

+27
-9
lines changed

8 files changed

+27
-9
lines changed

php_phongo.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1426,6 +1426,8 @@ void php_phongo_write_concern_to_zval(zval *retval, const mongoc_write_concern_t
14261426
add_assoc_string_ex(retval, ZEND_STRS("w"), (char *)PHONGO_WRITE_CONCERN_W_MAJORITY, 1);
14271427
} else if (w != MONGOC_WRITE_CONCERN_W_DEFAULT) {
14281428
add_assoc_long_ex(retval, ZEND_STRS("w"), w);
1429+
} else {
1430+
add_assoc_null_ex(retval, ZEND_STRS("w"));
14291431
}
14301432

14311433
add_assoc_bool_ex(retval, ZEND_STRS("wmajority"), mongoc_write_concern_get_wmajority(write_concern));

src/MongoDB/WriteConcern.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ PHP_METHOD(WriteConcern, __construct)
108108
}
109109
/* }}} */
110110

111-
/* {{{ proto string|integer WriteConcern::getW()
111+
/* {{{ proto string|integer|null WriteConcern::getW()
112112
Returns the WriteConcern "w" option */
113113
PHP_METHOD(WriteConcern, getW)
114114
{
@@ -132,7 +132,11 @@ PHP_METHOD(WriteConcern, getW)
132132
RETURN_STRING(PHONGO_WRITE_CONCERN_W_MAJORITY, 1);
133133
}
134134

135-
RETURN_LONG(intern->write_concern->w);
135+
if (intern->write_concern->w != MONGOC_WRITE_CONCERN_W_DEFAULT) {
136+
RETURN_LONG(mongoc_write_concern_get_w(intern->write_concern));
137+
}
138+
139+
RETURN_NULL();
136140
}
137141
/* }}} */
138142

tests/manager/manager-getwriteconcern-001.phpt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ foreach ($tests as $i => $test) {
3636
<?php exit(0); ?>
3737
--EXPECTF--
3838
object(MongoDB\Driver\WriteConcern)#%d (%d) {
39+
["w"]=>
40+
NULL
3941
["wmajority"]=>
4042
bool(false)
4143
["wtimeout"]=>
@@ -106,6 +108,8 @@ object(MongoDB\Driver\WriteConcern)#%d (%d) {
106108
bool(false)
107109
}
108110
object(MongoDB\Driver\WriteConcern)#%d (%d) {
111+
["w"]=>
112+
NULL
109113
["wmajority"]=>
110114
bool(false)
111115
["wtimeout"]=>
@@ -116,6 +120,8 @@ object(MongoDB\Driver\WriteConcern)#%d (%d) {
116120
NULL
117121
}
118122
object(MongoDB\Driver\WriteConcern)#%d (%d) {
123+
["w"]=>
124+
NULL
119125
["wmajority"]=>
120126
bool(false)
121127
["wtimeout"]=>

tests/replicaset/writeresult-getserver-002.phpt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,9 @@ object(MongoDB\Driver\WriteResult)#%d (%d) {
8080
array(0) {
8181
}
8282
["writeConcern"]=>
83-
array(4) {
83+
array(%d) {
84+
["w"]=>
85+
NULL
8486
["wmajority"]=>
8587
bool(false)
8688
["wtimeout"]=>

tests/server/server-executeBulkWrite-001.phpt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,9 @@ object(MongoDB\Driver\WriteResult)#%d (%d) {
7070
array(0) {
7171
}
7272
["writeConcern"]=>
73-
array(4) {
73+
array(%d) {
74+
["w"]=>
75+
NULL
7476
["wmajority"]=>
7577
bool(false)
7678
["wtimeout"]=>

tests/standalone/writeresult-isacknowledged-001.phpt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,9 @@ object(MongoDB\Driver\WriteResult)#%d (%d) {
3939
array(0) {
4040
}
4141
["writeConcern"]=>
42-
array(4) {
42+
array(%d) {
43+
["w"]=>
44+
NULL
4345
["wmajority"]=>
4446
bool(false)
4547
["wtimeout"]=>

tests/writeConcern/writeconcern-debug-001.phpt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,15 @@ require_once __DIR__ . "/../utils/basic.inc";
1010
* Although "w" will be omitted from the write concern sent to the server, we
1111
* should still yield other fields in the debug output, which may be sent.
1212
*/
13-
$w = new MongoDB\Driver\WriteConcern(-2, 1000, true, true);
14-
15-
var_dump($w);
13+
var_dump(new MongoDB\Driver\WriteConcern(-2, 1000, true, true));
1614

1715
?>
1816
===DONE===
1917
<?php exit(0); ?>
2018
--EXPECTF--
2119
object(MongoDB\Driver\WriteConcern)#%d (%d) {
20+
["w"]=>
21+
NULL
2222
["wmajority"]=>
2323
bool(false)
2424
["wtimeout"]=>

tests/writeConcern/writeconcern-getw-001.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ foreach ($tests as $test) {
2929
--EXPECT--
3030
string(8) "majority"
3131
string(8) "majority"
32-
int(-2)
32+
NULL
3333
int(-1)
3434
int(0)
3535
int(1)

0 commit comments

Comments
 (0)