diff --git a/src/MongoDB/WriteResult.c b/src/MongoDB/WriteResult.c index 3b6324b31..be0cb66c3 100644 --- a/src/MongoDB/WriteResult.c +++ b/src/MongoDB/WriteResult.c @@ -31,10 +31,9 @@ #include "MongoDB/WriteError.h" #include "WriteResult_arginfo.h" -#define PHONGO_WRITERESULT_CHECK_ACKNOWLEDGED(method) \ - if (!mongoc_write_concern_is_acknowledged(intern->write_concern)) { \ - 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"); \ - RETURN_NULL(); \ +#define PHONGO_WRITERESULT_CHECK_ACKNOWLEDGED(method) \ + if (!mongoc_write_concern_is_acknowledged(intern->write_concern)) { \ + phongo_throw_exception(PHONGO_ERROR_LOGIC, "MongoDB\\Driver\\WriteResult::" method "() should not be called for an unacknowledged write result"); \ } #define PHONGO_WRITERESULT_RETURN_LONG_FROM_BSON_INT32(iter, bson, key) \ diff --git a/src/MongoDB/WriteResult.stub.php b/src/MongoDB/WriteResult.stub.php index 50be751f5..84c3a2e41 100644 --- a/src/MongoDB/WriteResult.stub.php +++ b/src/MongoDB/WriteResult.stub.php @@ -12,15 +12,15 @@ final class WriteResult { final private function __construct() {} - final public function getInsertedCount(): ?int {} + final public function getInsertedCount(): int {} - final public function getMatchedCount(): ?int {} + final public function getMatchedCount(): int {} - final public function getModifiedCount(): ?int {} + final public function getModifiedCount(): int {} - final public function getDeletedCount(): ?int {} + final public function getDeletedCount(): int {} - final public function getUpsertedCount(): ?int {} + final public function getUpsertedCount(): int {} final public function getServer(): Server {} diff --git a/src/MongoDB/WriteResult_arginfo.h b/src/MongoDB/WriteResult_arginfo.h index eff3e9c59..2ffa45b77 100644 --- a/src/MongoDB/WriteResult_arginfo.h +++ b/src/MongoDB/WriteResult_arginfo.h @@ -1,10 +1,10 @@ /* This is a generated file, edit the .stub.php file instead. - * Stub hash: 84f1690181585d88c4e7233a4c959d5f50dc1b40 */ + * Stub hash: 217742ba620620cfaee2758070ff13e651620f87 */ ZEND_BEGIN_ARG_INFO_EX(arginfo_class_MongoDB_Driver_WriteResult___construct, 0, 0, 0) ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_class_MongoDB_Driver_WriteResult_getInsertedCount, 0, 0, IS_LONG, 1) +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_class_MongoDB_Driver_WriteResult_getInsertedCount, 0, 0, IS_LONG, 0) ZEND_END_ARG_INFO() #define arginfo_class_MongoDB_Driver_WriteResult_getMatchedCount arginfo_class_MongoDB_Driver_WriteResult_getInsertedCount diff --git a/tests/manager/manager-executeBulkWrite-012.phpt b/tests/manager/manager-executeBulkWrite-012.phpt index a6092064e..57149dd6a 100644 --- a/tests/manager/manager-executeBulkWrite-012.phpt +++ b/tests/manager/manager-executeBulkWrite-012.phpt @@ -23,17 +23,16 @@ foreach ($writeConcerns as $wc) { $result = $manager->executeBulkWrite(NS, $bulk, $options); var_dump($result->isAcknowledged()); - var_dump($result->getInsertedCount()); + if ($result->isAcknowledged()) { + var_dump($result->getInsertedCount()); + } } ?> ===DONE=== ---EXPECTF-- +--EXPECT-- bool(false) - -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 -NULL bool(true) int(1) bool(true) diff --git a/tests/server/server-executeBulkWrite-002.phpt b/tests/server/server-executeBulkWrite-002.phpt index 02ea0770e..b7ce701e7 100644 --- a/tests/server/server-executeBulkWrite-002.phpt +++ b/tests/server/server-executeBulkWrite-002.phpt @@ -19,17 +19,16 @@ foreach ($writeConcerns as $writeConcern) { $result = $primary->executeBulkWrite(NS, $bulk, new MongoDB\Driver\WriteConcern($writeConcern)); var_dump($result->isAcknowledged()); - var_dump($result->getInsertedCount()); + if ($result->isAcknowledged()) { + var_dump($result->getInsertedCount()); + } } ?> ===DONE=== ---EXPECTF-- +--EXPECT-- bool(false) - -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 -NULL bool(true) int(1) ===DONE=== diff --git a/tests/server/server-executeBulkWrite-003.phpt b/tests/server/server-executeBulkWrite-003.phpt index a31074f85..76db309a5 100644 --- a/tests/server/server-executeBulkWrite-003.phpt +++ b/tests/server/server-executeBulkWrite-003.phpt @@ -20,17 +20,16 @@ foreach ($writeConcerns as $wc) { $result = $server->executeBulkWrite(NS, $bulk, new MongoDB\Driver\WriteConcern($wc)); var_dump($result->isAcknowledged()); - var_dump($result->getInsertedCount()); + if ($result->isAcknowledged()) { + var_dump($result->getInsertedCount()); + } } ?> ===DONE=== ---EXPECTF-- +--EXPECT-- bool(false) - -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 -NULL bool(true) int(1) bool(true) diff --git a/tests/server/server-executeBulkWrite-005.phpt b/tests/server/server-executeBulkWrite-005.phpt index 3a954dbf4..0c2f9a173 100644 --- a/tests/server/server-executeBulkWrite-005.phpt +++ b/tests/server/server-executeBulkWrite-005.phpt @@ -25,7 +25,9 @@ foreach ($writeConcerns as $wc) { $result = $server->executeBulkWrite('local.' . COLLECTION_NAME, $bulk, new MongoDB\Driver\WriteConcern($wc)); var_dump($result->isAcknowledged()); - var_dump($result->getInsertedCount()); + if ($result->isAcknowledged()) { + var_dump($result->getInsertedCount()); + } } $bulk = new MongoDB\Driver\BulkWrite(); @@ -35,11 +37,8 @@ $server->executeBulkWrite('local.' . COLLECTION_NAME, $bulk); ?> ===DONE=== ---EXPECTF-- +--EXPECT-- bool(false) - -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 -NULL bool(true) int(1) ===DONE=== diff --git a/tests/server/server-executeBulkWrite-006.phpt b/tests/server/server-executeBulkWrite-006.phpt index 7e665825f..01c93e00f 100644 --- a/tests/server/server-executeBulkWrite-006.phpt +++ b/tests/server/server-executeBulkWrite-006.phpt @@ -24,17 +24,16 @@ foreach ($writeConcerns as $wc) { $result = $server->executeBulkWrite(NS, $bulk, $options); var_dump($result->isAcknowledged()); - var_dump($result->getInsertedCount()); + if ($result->isAcknowledged()) { + var_dump($result->getInsertedCount()); + } } ?> ===DONE=== ---EXPECTF-- +--EXPECT-- bool(false) - -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 -NULL bool(true) int(1) bool(true) diff --git a/tests/writeResult/writeresult-getdeletedcount-002.phpt b/tests/writeResult/writeresult-getdeletedcount-002.phpt index a3008f22c..2b3d0de48 100644 --- a/tests/writeResult/writeresult-getdeletedcount-002.phpt +++ b/tests/writeResult/writeresult-getdeletedcount-002.phpt @@ -19,12 +19,14 @@ $bulk->delete(['x' => 1]); $result = $manager->executeBulkWrite(NS, $bulk, new MongoDB\Driver\WriteConcern(0)); -var_dump($result->getDeletedCount()); +echo throws(function() use ($result) { + $result->getDeletedCount(); +}, MongoDB\Driver\Exception\LogicException::class), "\n"; ?> ===DONE=== ---EXPECTF-- -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 -NULL +--EXPECT-- +OK: Got MongoDB\Driver\Exception\LogicException +MongoDB\Driver\WriteResult::getDeletedCount() should not be called for an unacknowledged write result ===DONE=== diff --git a/tests/writeResult/writeresult-getinsertedcount-002.phpt b/tests/writeResult/writeresult-getinsertedcount-002.phpt index 4f671b36d..45cf37c19 100644 --- a/tests/writeResult/writeresult-getinsertedcount-002.phpt +++ b/tests/writeResult/writeresult-getinsertedcount-002.phpt @@ -19,12 +19,14 @@ $bulk->delete(['x' => 1]); $result = $manager->executeBulkWrite(NS, $bulk, new MongoDB\Driver\WriteConcern(0)); -var_dump($result->getInsertedCount()); +echo throws(function() use ($result) { + $result->getInsertedCount(); +}, MongoDB\Driver\Exception\LogicException::class), "\n"; ?> ===DONE=== ---EXPECTF-- -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 -NULL +--EXPECT-- +OK: Got MongoDB\Driver\Exception\LogicException +MongoDB\Driver\WriteResult::getInsertedCount() should not be called for an unacknowledged write result ===DONE=== diff --git a/tests/writeResult/writeresult-getmatchedcount-002.phpt b/tests/writeResult/writeresult-getmatchedcount-002.phpt index 75b93c704..588efd2e8 100644 --- a/tests/writeResult/writeresult-getmatchedcount-002.phpt +++ b/tests/writeResult/writeresult-getmatchedcount-002.phpt @@ -19,12 +19,14 @@ $bulk->delete(['x' => 1]); $result = $manager->executeBulkWrite(NS, $bulk, new MongoDB\Driver\WriteConcern(0)); -var_dump($result->getMatchedCount()); +echo throws(function() use ($result) { + $result->getMatchedCount(); +}, MongoDB\Driver\Exception\LogicException::class), "\n"; ?> ===DONE=== ---EXPECTF-- -Deprecated: MongoDB\Driver\WriteResult::getMatchedCount(): Calling MongoDB\Driver\WriteResult::getMatchedCount() for an unacknowledged write is deprecated and will throw an exception in %s -NULL +--EXPECT-- +OK: Got MongoDB\Driver\Exception\LogicException +MongoDB\Driver\WriteResult::getMatchedCount() should not be called for an unacknowledged write result ===DONE=== diff --git a/tests/writeResult/writeresult-getmodifiedcount-002.phpt b/tests/writeResult/writeresult-getmodifiedcount-002.phpt index a27e99c19..3a2fc90da 100644 --- a/tests/writeResult/writeresult-getmodifiedcount-002.phpt +++ b/tests/writeResult/writeresult-getmodifiedcount-002.phpt @@ -19,12 +19,14 @@ $bulk->delete(['x' => 1]); $result = $manager->executeBulkWrite(NS, $bulk, new MongoDB\Driver\WriteConcern(0)); -var_dump($result->getModifiedCount()); +echo throws(function() use ($result) { + $result->getModifiedCount(); +}, MongoDB\Driver\Exception\LogicException::class), "\n"; ?> ===DONE=== ---EXPECTF-- -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 -NULL +--EXPECT-- +OK: Got MongoDB\Driver\Exception\LogicException +MongoDB\Driver\WriteResult::getModifiedCount() should not be called for an unacknowledged write result ===DONE=== diff --git a/tests/writeResult/writeresult-getupsertedcount-002.phpt b/tests/writeResult/writeresult-getupsertedcount-002.phpt index af42f26b6..02ae2d9b3 100644 --- a/tests/writeResult/writeresult-getupsertedcount-002.phpt +++ b/tests/writeResult/writeresult-getupsertedcount-002.phpt @@ -19,12 +19,14 @@ $bulk->delete(['x' => 1]); $result = $manager->executeBulkWrite(NS, $bulk, new MongoDB\Driver\WriteConcern(0)); -var_dump($result->getUpsertedCount()); +echo throws(function() use ($result) { + $result->getUpsertedCount(); +}, MongoDB\Driver\Exception\LogicException::class), "\n"; ?> ===DONE=== ---EXPECTF-- -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 -NULL +--EXPECT-- +OK: Got MongoDB\Driver\Exception\LogicException +MongoDB\Driver\WriteResult::getUpsertedCount() should not be called for an unacknowledged write result ===DONE===