Skip to content
This repository was archived by the owner on Feb 1, 2022. It is now read-only.

Commit ba9c5d7

Browse files
committed
PHP-1510: Fix assertions from write methods return values
Now that unacknowledged writes are routed through legacy opcodes, these write methods return true (as documented). It appears that the false assertion was due to mongo_convert_write_api_return_to_legacy_retval() converting the response from an unacknowledged write command (likely an empty array) to a boolean.
1 parent 419ccbe commit ba9c5d7

File tree

2 files changed

+12
-12
lines changed

2 files changed

+12
-12
lines changed

tests/standalone/bug01085-001.phpt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,14 @@ Test for PHP-1085: w=0 returns unexpected exception on failure (socketTimeoutMS
88

99
require_once "tests/utils/server.inc";
1010

11-
function assertFalse($value) {
11+
function assertTrue($value) {
1212
if ( ! is_bool($value)) {
1313
printf("Expected boolean type but received %s\n", gettype($value));
1414
return;
1515
}
1616

17-
if ($value !== false) {
18-
echo "Expected boolean false but received boolean true\n";
17+
if ($value !== true) {
18+
echo "Expected boolean true but received boolean false\n";
1919
}
2020
}
2121

@@ -34,7 +34,7 @@ for ($i = 0; $i < 10; ++$i) {
3434
array('x' => $i, 'y' => str_repeat('a', 4*1024*1024)),
3535
array('w' => 0)
3636
);
37-
assertFalse($retval);
37+
assertTrue($retval);
3838
}
3939

4040
echo "Testing update() with w=0\n";
@@ -44,15 +44,15 @@ $retval = $collection->update(
4444
array('$set' => array('y' => 1)),
4545
array('w' => 0)
4646
);
47-
assertFalse($retval);
47+
assertTrue($retval);
4848

4949
echo "Testing remove() with w=0\n";
5050

5151
$retval = $collection->remove(
5252
array('$where' => 'sleep(1) && false'),
5353
array('w' => 0)
5454
);
55-
assertFalse($retval);
55+
assertTrue($retval);
5656

5757
echo "Testing update() with w=1\n";
5858

tests/standalone/bug01085-002.phpt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,14 @@ Test for PHP-1085: w=0 returns unexpected exception on failure (socketTimeoutMS
88

99
require_once "tests/utils/server.inc";
1010

11-
function assertFalse($value) {
11+
function assertTrue($value) {
1212
if ( ! is_bool($value)) {
1313
printf("Expected boolean type but received %s\n", gettype($value));
1414
return;
1515
}
1616

17-
if ($value !== false) {
18-
echo "Expected boolean false but received boolean true\n";
17+
if ($value !== true) {
18+
echo "Expected boolean true but received boolean false\n";
1919
}
2020
}
2121

@@ -32,7 +32,7 @@ for ($i = 0; $i < 10; ++$i) {
3232
array('x' => $i, 'y' => str_repeat('a', 4*1024*1024)),
3333
array('w' => 0, 'socketTimeoutMS' => 1)
3434
);
35-
assertFalse($retval);
35+
assertTrue($retval);
3636
}
3737

3838
echo "Testing update() with w=0\n";
@@ -42,15 +42,15 @@ $retval = $collection->update(
4242
array('$set' => array('y' => 1)),
4343
array('w' => 0, 'socketTimeoutMS' => 1)
4444
);
45-
assertFalse($retval);
45+
assertTrue($retval);
4646

4747
echo "Testing remove() with w=0\n";
4848

4949
$retval = $collection->remove(
5050
array('$where' => 'sleep(1) && false'),
5151
array('w' => 0, 'socketTimeoutMS' => 1)
5252
);
53-
assertFalse($retval);
53+
assertTrue($retval);
5454

5555
echo "Testing update() with w=1\n";
5656

0 commit comments

Comments
 (0)