Skip to content
This repository was archived by the owner on Dec 23, 2021. It is now read-only.

Commit 567c0af

Browse files
committed
HHVM-193: executeBulkWrite() should throw InvalidArgumentException for empty BulkWrite
1 parent 0e953a2 commit 567c0af

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
--TEST--
2+
MongoDB\Driver\Manager::executeBulkWrite() update write error
3+
--FILE--
4+
<?php
5+
include dirname(__FILE__) . '/utils.inc';
6+
7+
$m = new MongoDB\Driver\Manager("mongodb://localhost:27017");
8+
cleanup( $m );
9+
10+
$bw = new MongoDB\Driver\BulkWrite();
11+
12+
try {
13+
$result = $m->executeBulkWrite( 'demo.test', $bw );
14+
} catch ( Exception $e ) {
15+
echo get_class( $e ), "\n";
16+
echo $e->getMessage(), "\n";
17+
}
18+
19+
?>
20+
--EXPECT--
21+
MongoDB\Driver\Exception\InvalidArgumentException
22+
Cannot execute an empty BulkWrite

utils.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,12 +148,14 @@ HPHP::Object Utils::throwExceptionFromBsonError(bson_error_t *error)
148148
case MONGOC_ERROR_BSON_INVALID:
149149
case MONGOC_ERROR_MATCHER_INVALID:
150150
case MONGOC_ERROR_NAMESPACE_INVALID:
151-
case MONGOC_ERROR_COMMAND_INVALID_ARG:
152151
case MONGOC_ERROR_COLLECTION_INSERT_FAILED:
153152
case MONGOC_ERROR_GRIDFS_INVALID_FILENAME:
154153
case MONGOC_ERROR_QUERY_COMMAND_NOT_FOUND:
155154
case MONGOC_ERROR_QUERY_NOT_TAILABLE:
156155
return Utils::CreateAndConstruct(s_MongoDriverExceptionRuntimeException_className, HPHP::Variant(error->message), HPHP::Variant((uint64_t) error->code));
156+
157+
case MONGOC_ERROR_COMMAND_INVALID_ARG:
158+
return Utils::CreateAndConstruct(s_MongoDriverExceptionInvalidArgumentException_className, HPHP::Variant("Cannot execute an empty BulkWrite"), HPHP::Variant((uint64_t) 0));
157159
}
158160
switch (error->domain) {
159161
case MONGOC_ERROR_CLIENT:

0 commit comments

Comments
 (0)