Skip to content

Commit 695ddcc

Browse files
committed
PHPC-2144 Throw a LogicException when getting info from unacknowledged write result
And remove nullable from WriteResult get*Count accessors
1 parent d9a90ec commit 695ddcc

8 files changed

+30
-26
lines changed

src/MongoDB/WriteResult.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,9 @@
3131
#include "MongoDB/WriteError.h"
3232
#include "WriteResult_arginfo.h"
3333

34-
#define PHONGO_WRITERESULT_CHECK_ACKNOWLEDGED(method) \
35-
if (!mongoc_write_concern_is_acknowledged(intern->write_concern)) { \
36-
php_error_docref(NULL, E_DEPRECATED, "Calling MongoDB\\Driver\\WriteResult::" method "() for an unacknowledged write is deprecated and will throw an exception in ext-mongodb 2.0"); \
37-
RETURN_NULL(); \
34+
#define PHONGO_WRITERESULT_CHECK_ACKNOWLEDGED(method) \
35+
if (!mongoc_write_concern_is_acknowledged(intern->write_concern)) { \
36+
phongo_throw_exception(PHONGO_ERROR_LOGIC, "MongoDB\\Driver\\WriteResult::" method "() should not be called for an unacknowledged write result"); \
3837
}
3938

4039
#define PHONGO_WRITERESULT_RETURN_LONG_FROM_BSON_INT32(iter, bson, key) \

src/MongoDB/WriteResult.stub.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,15 @@ final class WriteResult
1212
{
1313
final private function __construct() {}
1414

15-
final public function getInsertedCount(): ?int {}
15+
final public function getInsertedCount(): int {}
1616

17-
final public function getMatchedCount(): ?int {}
17+
final public function getMatchedCount(): int {}
1818

19-
final public function getModifiedCount(): ?int {}
19+
final public function getModifiedCount(): int {}
2020

21-
final public function getDeletedCount(): ?int {}
21+
final public function getDeletedCount(): int {}
2222

23-
final public function getUpsertedCount(): ?int {}
23+
final public function getUpsertedCount(): int {}
2424

2525
final public function getServer(): Server {}
2626

src/MongoDB/WriteResult_arginfo.h

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/writeResult/writeresult-getdeletedcount-002.phpt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,13 @@ $bulk->delete(['x' => 1]);
1919

2020
$result = $manager->executeBulkWrite(NS, $bulk, new MongoDB\Driver\WriteConcern(0));
2121

22-
var_dump($result->getDeletedCount());
22+
throws(function() use ($result) {
23+
$result->getDeletedCount();
24+
}, MongoDB\Driver\Exception\LogicException::class, 'getDeletedCount');
2325

2426
?>
2527
===DONE===
2628
<?php exit(0); ?>
2729
--EXPECTF--
28-
Deprecated: MongoDB\Driver\WriteResult::getDeletedCount(): Calling MongoDB\Driver\WriteResult::getDeletedCount() for an unacknowledged write is deprecated and will throw an exception in ext-mongodb 2.0 in %s
29-
NULL
30+
OK: Got MongoDB\Driver\Exception\LogicException thrown from getDeletedCount
3031
===DONE===

tests/writeResult/writeresult-getinsertedcount-002.phpt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,13 @@ $bulk->delete(['x' => 1]);
1919

2020
$result = $manager->executeBulkWrite(NS, $bulk, new MongoDB\Driver\WriteConcern(0));
2121

22-
var_dump($result->getInsertedCount());
22+
throws(function() use ($result) {
23+
$result->getInsertedCount();
24+
}, MongoDB\Driver\Exception\LogicException::class, 'getInsertedCount');
2325

2426
?>
2527
===DONE===
2628
<?php exit(0); ?>
2729
--EXPECTF--
28-
Deprecated: MongoDB\Driver\WriteResult::getInsertedCount(): Calling MongoDB\Driver\WriteResult::getInsertedCount() for an unacknowledged write is deprecated and will throw an exception in ext-mongodb 2.0 in %s
29-
NULL
30+
OK: Got MongoDB\Driver\Exception\LogicException thrown from getInsertedCount
3031
===DONE===

tests/writeResult/writeresult-getmatchedcount-002.phpt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,13 @@ $bulk->delete(['x' => 1]);
1919

2020
$result = $manager->executeBulkWrite(NS, $bulk, new MongoDB\Driver\WriteConcern(0));
2121

22-
var_dump($result->getMatchedCount());
22+
throws(function() use ($result) {
23+
$result->getMatchedCount();
24+
}, MongoDB\Driver\Exception\LogicException::class, 'getMatchedCount');
2325

2426
?>
2527
===DONE===
2628
<?php exit(0); ?>
2729
--EXPECTF--
28-
Deprecated: MongoDB\Driver\WriteResult::getMatchedCount(): Calling MongoDB\Driver\WriteResult::getMatchedCount() for an unacknowledged write is deprecated and will throw an exception in %s
29-
NULL
30+
OK: Got MongoDB\Driver\Exception\LogicException thrown from getMatchedCount
3031
===DONE===

tests/writeResult/writeresult-getmodifiedcount-002.phpt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,13 @@ $bulk->delete(['x' => 1]);
1919

2020
$result = $manager->executeBulkWrite(NS, $bulk, new MongoDB\Driver\WriteConcern(0));
2121

22-
var_dump($result->getModifiedCount());
22+
throws(function() use ($result) {
23+
$result->getModifiedCount();
24+
}, MongoDB\Driver\Exception\LogicException::class, 'getModifiedCount');
2325

2426
?>
2527
===DONE===
2628
<?php exit(0); ?>
2729
--EXPECTF--
28-
Deprecated: MongoDB\Driver\WriteResult::getModifiedCount(): Calling MongoDB\Driver\WriteResult::getModifiedCount() for an unacknowledged write is deprecated and will throw an exception in ext-mongodb 2.0 in %s
29-
NULL
30+
OK: Got MongoDB\Driver\Exception\LogicException thrown from getModifiedCount
3031
===DONE===

tests/writeResult/writeresult-getupsertedcount-002.phpt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,13 @@ $bulk->delete(['x' => 1]);
1919

2020
$result = $manager->executeBulkWrite(NS, $bulk, new MongoDB\Driver\WriteConcern(0));
2121

22-
var_dump($result->getUpsertedCount());
22+
throws(function() use ($result) {
23+
$result->getUpsertedCount();
24+
}, MongoDB\Driver\Exception\LogicException::class, 'getUpsertedCount');
2325

2426
?>
2527
===DONE===
2628
<?php exit(0); ?>
2729
--EXPECTF--
28-
Deprecated: MongoDB\Driver\WriteResult::getUpsertedCount(): Calling MongoDB\Driver\WriteResult::getUpsertedCount() for an unacknowledged write is deprecated and will throw an exception in ext-mongodb 2.0 in %s
29-
NULL
30+
OK: Got MongoDB\Driver\Exception\LogicException thrown from getUpsertedCount
3031
===DONE===

0 commit comments

Comments
 (0)