Skip to content

Commit 68d6b7c

Browse files
committed
Merge pull request #110
2 parents 9c38811 + 380aee3 commit 68d6b7c

9 files changed

+80
-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"]=>
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
--TEST--
2+
MongoDB\Driver\WriteConcern debug output
3+
--SKIPIF--
4+
<?php require __DIR__ . "/../utils/basic-skipif.inc"?>
5+
--FILE--
6+
<?php
7+
require_once __DIR__ . "/../utils/basic.inc";
8+
9+
var_dump(new MongoDB\Driver\WriteConcern(1));
10+
var_dump(new MongoDB\Driver\WriteConcern("tag", 1000, false, false));
11+
var_dump(new MongoDB\Driver\WriteConcern(MongoDB\Driver\WriteConcern::MAJORITY, 500, true, true));
12+
13+
?>
14+
===DONE===
15+
<?php exit(0); ?>
16+
--EXPECTF--
17+
object(MongoDB\Driver\WriteConcern)#%d (%d) {
18+
["w"]=>
19+
int(1)
20+
["wmajority"]=>
21+
bool(false)
22+
["wtimeout"]=>
23+
int(0)
24+
["fsync"]=>
25+
NULL
26+
["journal"]=>
27+
NULL
28+
}
29+
object(MongoDB\Driver\WriteConcern)#%d (%d) {
30+
["w"]=>
31+
string(3) "tag"
32+
["wmajority"]=>
33+
bool(false)
34+
["wtimeout"]=>
35+
int(1000)
36+
["fsync"]=>
37+
bool(false)
38+
["journal"]=>
39+
bool(false)
40+
}
41+
object(MongoDB\Driver\WriteConcern)#%d (%d) {
42+
["w"]=>
43+
string(8) "majority"
44+
["wmajority"]=>
45+
bool(true)
46+
["wtimeout"]=>
47+
int(500)
48+
["fsync"]=>
49+
bool(true)
50+
["journal"]=>
51+
bool(true)
52+
}
53+
===DONE===

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)