diff --git a/UPGRADE-2.0.md b/UPGRADE-2.0.md index 6f1e309af..f85232f85 100644 --- a/UPGRADE-2.0.md +++ b/UPGRADE-2.0.md @@ -34,3 +34,7 @@ UPGRADE FROM 1.x to 2.0 ensure that it is detected by `pkg-config`. * The `--with-system-ciphers` configure option has been removed. Use `--enable-mongodb-crypto-system-profile` instead. + * `MongoDB\Driver\Query` removes the following options: `partial` (use + `allowPartialResults` instead), `maxScan`, `modifiers` (use alternative + top-level options instead), `oplogReplay`, and `snapshot`. Support for + negative `limit` values has been removed (use `singleBatch` instead). diff --git a/src/MongoDB/Query.c b/src/MongoDB/Query.c index 79c6135e0..d411d7422 100644 --- a/src/MongoDB/Query.c +++ b/src/MongoDB/Query.c @@ -39,7 +39,7 @@ static bool php_phongo_query_opts_append_string(bson_t* opts, const char* opts_k zval* value = php_array_fetch_deref(zarr, zarr_key); if (Z_TYPE_P(value) != IS_STRING) { - phongo_throw_exception(PHONGO_ERROR_INVALID_ARGUMENT, "Expected \"%s\" %s to be string, %s given", zarr_key, zarr_key[0] == '$' ? "modifier" : "option", PHONGO_ZVAL_CLASS_OR_TYPE_NAME_P(value)); + phongo_throw_exception(PHONGO_ERROR_INVALID_ARGUMENT, "Expected \"%s\" option to be string, %s given", zarr_key, PHONGO_ZVAL_CLASS_OR_TYPE_NAME_P(value)); return false; } @@ -59,7 +59,7 @@ static bool php_phongo_query_opts_append_document(bson_t* opts, const char* opts bson_t b = BSON_INITIALIZER; if (Z_TYPE_P(value) != IS_OBJECT && Z_TYPE_P(value) != IS_ARRAY) { - phongo_throw_exception(PHONGO_ERROR_INVALID_ARGUMENT, "Expected \"%s\" %s to be array or object, %s given", zarr_key, zarr_key[0] == '$' ? "modifier" : "option", PHONGO_ZVAL_CLASS_OR_TYPE_NAME_P(value)); + phongo_throw_exception(PHONGO_ERROR_INVALID_ARGUMENT, "Expected \"%s\" option to be array or object, %s given", zarr_key, PHONGO_ZVAL_CLASS_OR_TYPE_NAME_P(value)); return false; } @@ -71,7 +71,7 @@ static bool php_phongo_query_opts_append_document(bson_t* opts, const char* opts } if (!bson_validate(&b, BSON_VALIDATE_EMPTY_KEYS, NULL)) { - phongo_throw_exception(PHONGO_ERROR_INVALID_ARGUMENT, "Cannot use empty keys in \"%s\" %s", zarr_key, zarr_key[0] == '$' ? "modifier" : "option"); + phongo_throw_exception(PHONGO_ERROR_INVALID_ARGUMENT, "Cannot use empty keys in \"%s\" option", zarr_key); bson_destroy(&b); return false; } @@ -110,20 +110,14 @@ static bool php_phongo_query_opts_append_value(bson_t* opts, const char* opts_ke return true; } -#define PHONGO_QUERY_OPT_BOOL_EX(opt, zarr, key, deprecated) \ - if ((zarr) && php_array_existsc((zarr), (key))) { \ - if ((deprecated)) { \ - php_error_docref(NULL, E_DEPRECATED, "The \"%s\" option is deprecated and will be removed in a future release", key); \ - } \ - if (!BSON_APPEND_BOOL(intern->opts, (opt), php_array_fetchc_bool((zarr), (key)))) { \ - phongo_throw_exception(PHONGO_ERROR_INVALID_ARGUMENT, "Error appending \"%s\" option", (opt)); \ - return false; \ - } \ +#define PHONGO_QUERY_OPT_BOOL(opt, zarr, key) \ + if ((zarr) && php_array_existsc((zarr), (key))) { \ + if (!BSON_APPEND_BOOL(intern->opts, (opt), php_array_fetchc_bool((zarr), (key)))) { \ + phongo_throw_exception(PHONGO_ERROR_INVALID_ARGUMENT, "Error appending \"%s\" option", (opt)); \ + return false; \ + } \ } -#define PHONGO_QUERY_OPT_BOOL(opt, zarr, key) PHONGO_QUERY_OPT_BOOL_EX((opt), (zarr), (key), 0) -#define PHONGO_QUERY_OPT_BOOL_DEPRECATED(opt, zarr, key) PHONGO_QUERY_OPT_BOOL_EX((opt), (zarr), (key), 1) - #define PHONGO_QUERY_OPT_BSON_VALUE(opt, zarr, key) \ if ((zarr) && php_array_existsc((zarr), (key))) { \ if (!php_phongo_query_opts_append_value(intern->opts, (opt), (zarr), (key))) { \ @@ -140,21 +134,14 @@ static bool php_phongo_query_opts_append_value(bson_t* opts, const char* opts_ke /* Note: handling of integer options will depend on SIZEOF_ZEND_LONG and we * are not converting strings to 64-bit integers for 32-bit platforms. */ - -#define PHONGO_QUERY_OPT_INT64_EX(opt, zarr, key, deprecated) \ - if ((zarr) && php_array_existsc((zarr), (key))) { \ - if ((deprecated)) { \ - php_error_docref(NULL, E_DEPRECATED, "The \"%s\" option is deprecated and will be removed in a future release", key); \ - } \ - if (!BSON_APPEND_INT64(intern->opts, (opt), php_array_fetchc_long((zarr), (key)))) { \ - phongo_throw_exception(PHONGO_ERROR_INVALID_ARGUMENT, "Error appending \"%s\" option", (opt)); \ - return false; \ - } \ +#define PHONGO_QUERY_OPT_INT64(opt, zarr, key) \ + if ((zarr) && php_array_existsc((zarr), (key))) { \ + if (!BSON_APPEND_INT64(intern->opts, (opt), php_array_fetchc_long((zarr), (key)))) { \ + phongo_throw_exception(PHONGO_ERROR_INVALID_ARGUMENT, "Error appending \"%s\" option", (opt)); \ + return false; \ + } \ } -#define PHONGO_QUERY_OPT_INT64(opt, zarr, key) PHONGO_QUERY_OPT_INT64_EX((opt), (zarr), (key), 0) -#define PHONGO_QUERY_OPT_INT64_DEPRECATED(opt, zarr, key) PHONGO_QUERY_OPT_INT64_EX((opt), (zarr), (key), 1) - #define PHONGO_QUERY_OPT_STRING(opt, zarr, key) \ if ((zarr) && php_array_existsc((zarr), (key))) { \ if (!php_phongo_query_opts_append_string(intern->opts, (opt), (zarr), (key))) { \ @@ -165,12 +152,10 @@ static bool php_phongo_query_opts_append_value(bson_t* opts, const char* opts_ke /* Initialize the "hint" option. Returns true on success; otherwise, false is * returned and an exception is thrown. * - * The "hint" option (or "$hint" modifier) must be a string or document. Check - * for both types and merge into BSON options accordingly. */ -static bool php_phongo_query_init_hint(php_phongo_query_t* intern, zval* options, zval* modifiers) + * The "hint" option must be a string or document. Check for both types and + * merge into BSON options accordingly. */ +static bool php_phongo_query_init_hint(php_phongo_query_t* intern, zval* options) { - /* The "hint" option (or "$hint" modifier) must be a string or document. - * Check for both types and merge into BSON options accordingly. */ if (php_array_existsc(options, "hint")) { zend_uchar type = Z_TYPE_P(php_array_fetchc_deref(options, "hint")); @@ -182,50 +167,6 @@ static bool php_phongo_query_init_hint(php_phongo_query_t* intern, zval* options phongo_throw_exception(PHONGO_ERROR_INVALID_ARGUMENT, "Expected \"hint\" option to be string, array, or object, %s given", zend_get_type_by_const(type)); return false; } - } else if (modifiers && php_array_existsc(modifiers, "$hint")) { - zend_uchar type = Z_TYPE_P(php_array_fetchc_deref(modifiers, "$hint")); - - if (type == IS_STRING) { - PHONGO_QUERY_OPT_STRING("hint", modifiers, "$hint"); - } else if (type == IS_OBJECT || type == IS_ARRAY) { - PHONGO_QUERY_OPT_DOCUMENT("hint", modifiers, "$hint"); - } else { - phongo_throw_exception(PHONGO_ERROR_INVALID_ARGUMENT, "Expected \"$hint\" modifier to be string, array, or object, %s given", zend_get_type_by_const(type)); - return false; - } - } - - return true; -} - -/* Initialize the "limit" and "singleBatch" options. Returns true on success; - * otherwise, false is returned and an exception is thrown. - * - * mongoc_collection_find_with_opts() requires a non-negative limit. For - * backwards compatibility, a negative limit should be set as a positive value - * and default singleBatch to true. */ -static bool php_phongo_query_init_limit_and_singlebatch(php_phongo_query_t* intern, zval* options) -{ - if (php_array_fetchc_long(options, "limit") < 0) { - zend_long limit = php_array_fetchc_long(options, "limit"); - - if (!BSON_APPEND_INT64(intern->opts, "limit", -limit)) { - phongo_throw_exception(PHONGO_ERROR_INVALID_ARGUMENT, "Error appending \"limit\" option"); - return false; - } - - if (php_array_existsc(options, "singleBatch") && !php_array_fetchc_bool(options, "singleBatch")) { - phongo_throw_exception(PHONGO_ERROR_INVALID_ARGUMENT, "Negative \"limit\" option conflicts with false \"singleBatch\" option"); - return false; - } else { - if (!BSON_APPEND_BOOL(intern->opts, "singleBatch", true)) { - phongo_throw_exception(PHONGO_ERROR_INVALID_ARGUMENT, "Error appending \"singleBatch\" option"); - return false; - } - } - } else { - PHONGO_QUERY_OPT_INT64("limit", options, "limit"); - PHONGO_QUERY_OPT_BOOL("singleBatch", options, "singleBatch"); } return true; @@ -287,14 +228,10 @@ static bool php_phongo_query_init_max_await_time_ms(php_phongo_query_t* intern, } /* Initializes the query from filter and options arguments and returns whether - * an error occurred. If query is undefined, it will be initialized. - * - * This function will fall back to a modifier in the absence of a top-level - * option (where applicable). */ + * an error occurred. If query is undefined, it will be initialized. */ bool phongo_query_init(zval* return_value, zval* filter, zval* options) { php_phongo_query_t* intern; - zval* modifiers = NULL; if (Z_ISUNDEF_P(return_value)) { object_init_ex(return_value, php_phongo_query_ce); @@ -330,59 +267,28 @@ bool phongo_query_init(zval* return_value, zval* filter, zval* options) return true; } - if (php_array_existsc(options, "modifiers")) { - modifiers = php_array_fetchc_deref(options, "modifiers"); - - if (Z_TYPE_P(modifiers) != IS_ARRAY) { - phongo_throw_exception(PHONGO_ERROR_INVALID_ARGUMENT, "Expected \"modifiers\" option to be array, %s given", PHONGO_ZVAL_CLASS_OR_TYPE_NAME_P(modifiers)); - return false; - } - - php_error_docref(NULL, E_DEPRECATED, "The \"modifiers\" option is deprecated and will be removed in a future release"); - } - - PHONGO_QUERY_OPT_BOOL("allowDiskUse", options, "allowDiskUse") - PHONGO_QUERY_OPT_BOOL("allowPartialResults", options, "allowPartialResults") - else PHONGO_QUERY_OPT_BOOL("allowPartialResults", options, "partial"); + PHONGO_QUERY_OPT_BOOL("allowDiskUse", options, "allowDiskUse"); + PHONGO_QUERY_OPT_BOOL("allowPartialResults", options, "allowPartialResults"); PHONGO_QUERY_OPT_BOOL("awaitData", options, "awaitData"); PHONGO_QUERY_OPT_INT64("batchSize", options, "batchSize"); PHONGO_QUERY_OPT_DOCUMENT("collation", options, "collation"); - PHONGO_QUERY_OPT_BSON_VALUE("comment", options, "comment") - else PHONGO_QUERY_OPT_BSON_VALUE("comment", modifiers, "$comment"); + PHONGO_QUERY_OPT_BSON_VALUE("comment", options, "comment"); PHONGO_QUERY_OPT_BOOL("exhaust", options, "exhaust"); PHONGO_QUERY_OPT_DOCUMENT("let", options, "let"); - PHONGO_QUERY_OPT_DOCUMENT("max", options, "max") - else PHONGO_QUERY_OPT_DOCUMENT("max", modifiers, "$max"); - PHONGO_QUERY_OPT_INT64_DEPRECATED("maxScan", options, "maxScan") - else PHONGO_QUERY_OPT_INT64_DEPRECATED("maxScan", modifiers, "$maxScan"); - PHONGO_QUERY_OPT_INT64("maxTimeMS", options, "maxTimeMS") - else PHONGO_QUERY_OPT_INT64("maxTimeMS", modifiers, "$maxTimeMS"); - PHONGO_QUERY_OPT_DOCUMENT("min", options, "min") - else PHONGO_QUERY_OPT_DOCUMENT("min", modifiers, "$min"); + PHONGO_QUERY_OPT_INT64("limit", options, "limit"); + PHONGO_QUERY_OPT_DOCUMENT("max", options, "max"); + PHONGO_QUERY_OPT_INT64("maxTimeMS", options, "maxTimeMS"); + PHONGO_QUERY_OPT_DOCUMENT("min", options, "min"); PHONGO_QUERY_OPT_BOOL("noCursorTimeout", options, "noCursorTimeout"); - PHONGO_QUERY_OPT_BOOL_DEPRECATED("oplogReplay", options, "oplogReplay"); PHONGO_QUERY_OPT_DOCUMENT("projection", options, "projection"); - PHONGO_QUERY_OPT_BOOL("returnKey", options, "returnKey") - else PHONGO_QUERY_OPT_BOOL("returnKey", modifiers, "$returnKey"); - PHONGO_QUERY_OPT_BOOL("showRecordId", options, "showRecordId") - else PHONGO_QUERY_OPT_BOOL("showRecordId", modifiers, "$showDiskLoc"); + PHONGO_QUERY_OPT_BOOL("returnKey", options, "returnKey"); + PHONGO_QUERY_OPT_BOOL("showRecordId", options, "showRecordId"); + PHONGO_QUERY_OPT_BOOL("singleBatch", options, "singleBatch"); PHONGO_QUERY_OPT_INT64("skip", options, "skip"); - PHONGO_QUERY_OPT_DOCUMENT("sort", options, "sort") - else PHONGO_QUERY_OPT_DOCUMENT("sort", modifiers, "$orderby"); - PHONGO_QUERY_OPT_BOOL_DEPRECATED("snapshot", options, "snapshot") - else PHONGO_QUERY_OPT_BOOL_DEPRECATED("snapshot", modifiers, "$snapshot"); + PHONGO_QUERY_OPT_DOCUMENT("sort", options, "sort"); PHONGO_QUERY_OPT_BOOL("tailable", options, "tailable"); - /* The "$explain" modifier should be converted to an "explain" option, which - * libmongoc will later convert back to a modifier for the OP_QUERY code - * path. This modifier will be ignored for the find command code path. */ - PHONGO_QUERY_OPT_BOOL("explain", modifiers, "$explain"); - - if (!php_phongo_query_init_hint(intern, options, modifiers)) { - return false; - } - - if (!php_phongo_query_init_limit_and_singlebatch(intern, options)) { + if (!php_phongo_query_init_hint(intern, options)) { return false; } @@ -397,14 +303,10 @@ bool phongo_query_init(zval* return_value, zval* filter, zval* options) return true; } -#undef PHONGO_QUERY_OPT_BOOL_EX #undef PHONGO_QUERY_OPT_BOOL -#undef PHONGO_QUERY_OPT_BOOL_DEPRECATED #undef PHONGO_QUERY_OPT_BSON_VALUE #undef PHONGO_QUERY_OPT_DOCUMENT -#undef PHONGO_QUERY_OPT_INT64_EX #undef PHONGO_QUERY_OPT_INT64 -#undef PHONGO_QUERY_OPT_INT64_DEPRECATED #undef PHONGO_QUERY_OPT_STRING /* Constructs a new Query */ diff --git a/tests/query/query-ctor-002.phpt b/tests/query/query-ctor-002.phpt index af8449e67..1a35785cc 100644 --- a/tests/query/query-ctor-002.phpt +++ b/tests/query/query-ctor-002.phpt @@ -15,18 +15,15 @@ var_dump(new MongoDB\Driver\Query( 'exhaust' => false, 'limit' => 20, 'max' => ['y' => 100], - 'maxScan' => 50, 'maxTimeMS' => 1000, 'min' => ['y' => 1], 'noCursorTimeout' => false, - 'oplogReplay' => false, 'projection' => ['x' => 1, 'y' => 1], 'returnKey' => false, 'showRecordId' => false, 'singleBatch' => false, 'skip' => 5, 'sort' => ['y' => -1], - 'snapshot' => false, 'tailable' => false, ] )); @@ -50,11 +47,6 @@ var_dump(new MongoDB\Driver\Query( ===DONE=== --EXPECTF-- -Deprecated: MongoDB\Driver\Query::__construct(): The "maxScan" option is deprecated and will be removed in a future release in %s on line %d - -Deprecated: MongoDB\Driver\Query::__construct(): The "oplogReplay" option is deprecated and will be removed in a future release in %s on line %d - -Deprecated: MongoDB\Driver\Query::__construct(): The "snapshot" option is deprecated and will be removed in a future release in %s on line %d object(MongoDB\Driver\Query)#%d (%d) { ["filter"]=> object(stdClass)#%d (%d) { @@ -80,13 +72,13 @@ object(MongoDB\Driver\Query)#%d (%d) { string(3) "foo" ["exhaust"]=> bool(false) + ["limit"]=> + int(20) ["max"]=> object(stdClass)#%d (%d) { ["y"]=> int(100) } - ["maxScan"]=> - int(50) ["maxTimeMS"]=> int(1000) ["min"]=> @@ -96,8 +88,6 @@ object(MongoDB\Driver\Query)#%d (%d) { } ["noCursorTimeout"]=> bool(false) - ["oplogReplay"]=> - bool(false) ["projection"]=> object(stdClass)#%d (%d) { ["x"]=> @@ -109,6 +99,8 @@ object(MongoDB\Driver\Query)#%d (%d) { bool(false) ["showRecordId"]=> bool(false) + ["singleBatch"]=> + bool(false) ["skip"]=> int(5) ["sort"]=> @@ -116,14 +108,8 @@ object(MongoDB\Driver\Query)#%d (%d) { ["y"]=> int(-1) } - ["snapshot"]=> - bool(false) ["tailable"]=> bool(false) - ["limit"]=> - int(20) - ["singleBatch"]=> - bool(false) } ["readConcern"]=> NULL diff --git a/tests/query/query-ctor-003.phpt b/tests/query/query-ctor-003.phpt deleted file mode 100644 index e68baeeed..000000000 --- a/tests/query/query-ctor-003.phpt +++ /dev/null @@ -1,137 +0,0 @@ ---TEST-- -MongoDB\Driver\Query construction with modifier options ---FILE-- - 1], - [ - 'modifiers' => [ - '$comment' => 'foo', - '$max' => ['y' => 100], - '$maxScan' => 50, - '$maxTimeMS' => 1000, - '$min' => ['y' => 1], - '$orderby' => ['y' => -1], - '$returnKey' => false, - '$showDiskLoc' => false, - '$snapshot' => false, - ], - ] -)); - -var_dump(new MongoDB\Driver\Query( - ['x' => 1], - ['modifiers' => ['$explain' => true]] -)); - -var_dump(new MongoDB\Driver\Query( - ['x' => 1], - ['modifiers' => ['$hint' => 'y_1']] -)); - -var_dump(new MongoDB\Driver\Query( - ['x' => 1], - ['modifiers' => ['$hint' => ['y' => 1]]] -)); - -?> -===DONE=== - ---EXPECTF-- -Deprecated: MongoDB\Driver\Query::__construct(): The "modifiers" option is deprecated and will be removed in a future release in %s on line %d - -Deprecated: MongoDB\Driver\Query::__construct(): The "$maxScan" option is deprecated and will be removed in a future release in %s on line %d - -Deprecated: MongoDB\Driver\Query::__construct(): The "$snapshot" option is deprecated and will be removed in a future release in %s on line %d -object(MongoDB\Driver\Query)#%d (%d) { - ["filter"]=> - object(stdClass)#%d (%d) { - ["x"]=> - int(1) - } - ["options"]=> - object(stdClass)#%d (%d) { - ["comment"]=> - string(3) "foo" - ["max"]=> - object(stdClass)#%d (%d) { - ["y"]=> - int(100) - } - ["maxScan"]=> - int(50) - ["maxTimeMS"]=> - int(1000) - ["min"]=> - object(stdClass)#%d (%d) { - ["y"]=> - int(1) - } - ["returnKey"]=> - bool(false) - ["showRecordId"]=> - bool(false) - ["sort"]=> - object(stdClass)#%d (%d) { - ["y"]=> - int(-1) - } - ["snapshot"]=> - bool(false) - } - ["readConcern"]=> - NULL -} - -Deprecated: MongoDB\Driver\Query::__construct(): The "modifiers" option is deprecated and will be removed in a future release in %s on line %d -object(MongoDB\Driver\Query)#%d (%d) { - ["filter"]=> - object(stdClass)#%d (%d) { - ["x"]=> - int(1) - } - ["options"]=> - object(stdClass)#%d (%d) { - ["explain"]=> - bool(true) - } - ["readConcern"]=> - NULL -} - -Deprecated: MongoDB\Driver\Query::__construct(): The "modifiers" option is deprecated and will be removed in a future release in %s on line %d -object(MongoDB\Driver\Query)#%d (%d) { - ["filter"]=> - object(stdClass)#%d (%d) { - ["x"]=> - int(1) - } - ["options"]=> - object(stdClass)#%d (%d) { - ["hint"]=> - string(3) "y_1" - } - ["readConcern"]=> - NULL -} - -Deprecated: MongoDB\Driver\Query::__construct(): The "modifiers" option is deprecated and will be removed in a future release in %s on line %d -object(MongoDB\Driver\Query)#%d (%d) { - ["filter"]=> - object(stdClass)#%d (%d) { - ["x"]=> - int(1) - } - ["options"]=> - object(stdClass)#%d (%d) { - ["hint"]=> - object(stdClass)#%d (%d) { - ["y"]=> - int(1) - } - } - ["readConcern"]=> - NULL -} -===DONE=== diff --git a/tests/query/query-ctor-004.phpt b/tests/query/query-ctor-004.phpt deleted file mode 100644 index 42b148d3d..000000000 --- a/tests/query/query-ctor-004.phpt +++ /dev/null @@ -1,131 +0,0 @@ ---TEST-- -MongoDB\Driver\Query construction with options overriding modifiers ---FILE-- - 1], - [ - 'comment' => 'foo', - 'max' => ['y' => 100], - 'maxScan' => 50, - 'maxTimeMS' => 1000, - 'min' => ['y' => 1], - 'returnKey' => false, - 'showRecordId' => false, - 'sort' => ['y' => -1], - 'snapshot' => false, - 'modifiers' => [ - '$comment' => 'bar', - '$max' => ['y' => 200], - '$maxScan' => 60, - '$maxTimeMS' => 2000, - '$min' => ['y' => 101], - '$orderby' => ['y' => 1], - '$returnKey' => true, - '$showDiskLoc' => true, - '$snapshot' => true, - ], - ] -)); - -var_dump(new MongoDB\Driver\Query( - ['x' => 1], - [ - 'hint' => 'y_1', - 'modifiers' => ['$hint' => 'x_1'], - ] -)); - -var_dump(new MongoDB\Driver\Query( - ['x' => 1], - [ - 'hint' => ['y' => 1], - 'modifiers' => ['$hint' => ['x' => 1]], - ] -)); - -?> -===DONE=== - ---EXPECTF-- -Deprecated: MongoDB\Driver\Query::__construct(): The "modifiers" option is deprecated and will be removed in a future release in %s on line %d - -Deprecated: MongoDB\Driver\Query::__construct(): The "maxScan" option is deprecated and will be removed in a future release in %s on line %d - -Deprecated: MongoDB\Driver\Query::__construct(): The "snapshot" option is deprecated and will be removed in a future release in %s on line %d -object(MongoDB\Driver\Query)#%d (%d) { - ["filter"]=> - object(stdClass)#%d (%d) { - ["x"]=> - int(1) - } - ["options"]=> - object(stdClass)#%d (%d) { - ["comment"]=> - string(3) "foo" - ["max"]=> - object(stdClass)#%d (%d) { - ["y"]=> - int(100) - } - ["maxScan"]=> - int(50) - ["maxTimeMS"]=> - int(1000) - ["min"]=> - object(stdClass)#%d (%d) { - ["y"]=> - int(1) - } - ["returnKey"]=> - bool(false) - ["showRecordId"]=> - bool(false) - ["sort"]=> - object(stdClass)#%d (%d) { - ["y"]=> - int(-1) - } - ["snapshot"]=> - bool(false) - } - ["readConcern"]=> - NULL -} - -Deprecated: MongoDB\Driver\Query::__construct(): The "modifiers" option is deprecated and will be removed in a future release in %s on line %d -object(MongoDB\Driver\Query)#%d (%d) { - ["filter"]=> - object(stdClass)#%d (%d) { - ["x"]=> - int(1) - } - ["options"]=> - object(stdClass)#%d (%d) { - ["hint"]=> - string(3) "y_1" - } - ["readConcern"]=> - NULL -} - -Deprecated: MongoDB\Driver\Query::__construct(): The "modifiers" option is deprecated and will be removed in a future release in %s on line %d -object(MongoDB\Driver\Query)#%d (%d) { - ["filter"]=> - object(stdClass)#%d (%d) { - ["x"]=> - int(1) - } - ["options"]=> - object(stdClass)#%d (%d) { - ["hint"]=> - object(stdClass)#%d (%d) { - ["y"]=> - int(1) - } - } - ["readConcern"]=> - NULL -} -===DONE=== diff --git a/tests/query/query-ctor-005.phpt b/tests/query/query-ctor-005.phpt index e206d731c..317e37e92 100644 --- a/tests/query/query-ctor-005.phpt +++ b/tests/query/query-ctor-005.phpt @@ -3,19 +3,13 @@ MongoDB\Driver\Query construction with negative limit --FILE-- 1], ['limit' => -5] )); -var_dump(new MongoDB\Driver\Query( - ['x' => 1], - [ - 'limit' => -5, - 'singleBatch' => true - ] -)); - ?> ===DONE=== @@ -29,25 +23,7 @@ object(MongoDB\Driver\Query)#%d (%d) { ["options"]=> object(stdClass)#%d (%d) { ["limit"]=> - int(5) - ["singleBatch"]=> - bool(true) - } - ["readConcern"]=> - NULL -} -object(MongoDB\Driver\Query)#%d (%d) { - ["filter"]=> - object(stdClass)#%d (%d) { - ["x"]=> - int(1) - } - ["options"]=> - object(stdClass)#%d (%d) { - ["limit"]=> - int(5) - ["singleBatch"]=> - bool(true) + int(-5) } ["readConcern"]=> NULL diff --git a/tests/query/query-ctor-006.phpt b/tests/query/query-ctor-006.phpt deleted file mode 100644 index 91795cc16..000000000 --- a/tests/query/query-ctor-006.phpt +++ /dev/null @@ -1,51 +0,0 @@ ---TEST-- -MongoDB\Driver\Query construction "allowPartialResults" overrides "partial" option ---FILE-- - 1], - ['partial' => true] -)); - -var_dump(new MongoDB\Driver\Query( - ['x' => 1], - [ - 'allowPartialResults' => false, - 'partial' => true, - ] -)); - -?> -===DONE=== - ---EXPECTF-- -object(MongoDB\Driver\Query)#%d (%d) { - ["filter"]=> - object(stdClass)#%d (%d) { - ["x"]=> - int(1) - } - ["options"]=> - object(stdClass)#%d (%d) { - ["allowPartialResults"]=> - bool(true) - } - ["readConcern"]=> - NULL -} -object(MongoDB\Driver\Query)#%d (%d) { - ["filter"]=> - object(stdClass)#%d (%d) { - ["x"]=> - int(1) - } - ["options"]=> - object(stdClass)#%d (%d) { - ["allowPartialResults"]=> - bool(false) - } - ["readConcern"]=> - NULL -} -===DONE=== diff --git a/tests/query/query-ctor_error-002.phpt b/tests/query/query-ctor_error-002.phpt index 830cd20bc..10f1e694c 100644 --- a/tests/query/query-ctor_error-002.phpt +++ b/tests/query/query-ctor_error-002.phpt @@ -6,68 +6,34 @@ MongoDB\Driver\Query construction (invalid option types) require_once __DIR__ . '/../utils/basic.inc'; $tests = [ - ['modifiers' => 0], ['collation' => 0], ['hint' => 0], ['max' => 0], ['min' => 0], ['projection' => 0], ['sort' => 0], - ['modifiers' => ['$hint' => 0]], - ['modifiers' => ['$max' => 0]], - ['modifiers' => ['$min' => 0]], - ['modifiers' => ['$orderby' => 0]], ]; foreach ($tests as $options) { echo throws(function() use ($options) { new MongoDB\Driver\Query([], $options); - }, 'MongoDB\Driver\Exception\InvalidArgumentException'), "\n\n"; + }, 'MongoDB\Driver\Exception\InvalidArgumentException'), "\n"; } ?> ===DONE=== --EXPECTF-- -OK: Got MongoDB\Driver\Exception\InvalidArgumentException -Expected "modifiers" option to be array, int given - OK: Got MongoDB\Driver\Exception\InvalidArgumentException Expected "collation" option to be array or object, int given - OK: Got MongoDB\Driver\Exception\InvalidArgumentException Expected "hint" option to be string, array, or object, int given - OK: Got MongoDB\Driver\Exception\InvalidArgumentException Expected "max" option to be array or object, int given - OK: Got MongoDB\Driver\Exception\InvalidArgumentException Expected "min" option to be array or object, int given - OK: Got MongoDB\Driver\Exception\InvalidArgumentException Expected "projection" option to be array or object, int given - OK: Got MongoDB\Driver\Exception\InvalidArgumentException Expected "sort" option to be array or object, int given - - -Deprecated: MongoDB\Driver\Query::__construct(): The "modifiers" option is deprecated and will be removed in a future release in %s on line %d -OK: Got MongoDB\Driver\Exception\InvalidArgumentException -Expected "$hint" modifier to be string, array, or object, int given - - -Deprecated: MongoDB\Driver\Query::__construct(): The "modifiers" option is deprecated and will be removed in a future release in %s on line %d -OK: Got MongoDB\Driver\Exception\InvalidArgumentException -Expected "$max" modifier to be array or object, int given - - -Deprecated: MongoDB\Driver\Query::__construct(): The "modifiers" option is deprecated and will be removed in a future release in %s on line %d -OK: Got MongoDB\Driver\Exception\InvalidArgumentException -Expected "$min" modifier to be array or object, int given - - -Deprecated: MongoDB\Driver\Query::__construct(): The "modifiers" option is deprecated and will be removed in a future release in %s on line %d -OK: Got MongoDB\Driver\Exception\InvalidArgumentException -Expected "$orderby" modifier to be array or object, int given - ===DONE=== diff --git a/tests/query/query-ctor_error-003.phpt b/tests/query/query-ctor_error-003.phpt deleted file mode 100644 index 7616f8058..000000000 --- a/tests/query/query-ctor_error-003.phpt +++ /dev/null @@ -1,18 +0,0 @@ ---TEST-- -MongoDB\Driver\Query construction (negative limit conflicts with false singleBatch) ---FILE-- - -1, 'singleBatch' => false]); -}, 'MongoDB\Driver\Exception\InvalidArgumentException'), "\n"; - -?> -===DONE=== - ---EXPECT-- -OK: Got MongoDB\Driver\Exception\InvalidArgumentException -Negative "limit" option conflicts with false "singleBatch" option -===DONE=== diff --git a/tests/query/query-ctor_error-004.phpt b/tests/query/query-ctor_error-004.phpt index 2b74f8181..b8a5db3c4 100644 --- a/tests/query/query-ctor_error-004.phpt +++ b/tests/query/query-ctor_error-004.phpt @@ -14,10 +14,6 @@ $tests = [ [[], ['min' => ['' => 1]]], [[], ['projection' => ['' => 1]]], [[], ['sort' => ['' => 1]]], - [[], ['modifiers' => ['$hint' => ['' => 1]]]], - [[], ['modifiers' => ['$max' => ['' => 1]]]], - [[], ['modifiers' => ['$min' => ['' => 1]]]], - [[], ['modifiers' => ['$orderby' => ['' => 1]]]], ]; foreach ($tests as $test) { @@ -48,20 +44,4 @@ OK: Got MongoDB\Driver\Exception\InvalidArgumentException Cannot use empty keys in "projection" option OK: Got MongoDB\Driver\Exception\InvalidArgumentException Cannot use empty keys in "sort" option - -Deprecated: MongoDB\Driver\Query::__construct(): The "modifiers" option is deprecated and will be removed in a future release in %s on line %d -OK: Got MongoDB\Driver\Exception\InvalidArgumentException -Cannot use empty keys in "$hint" modifier - -Deprecated: MongoDB\Driver\Query::__construct(): The "modifiers" option is deprecated and will be removed in a future release in %s on line %d -OK: Got MongoDB\Driver\Exception\InvalidArgumentException -Cannot use empty keys in "$max" modifier - -Deprecated: MongoDB\Driver\Query::__construct(): The "modifiers" option is deprecated and will be removed in a future release in %s on line %d -OK: Got MongoDB\Driver\Exception\InvalidArgumentException -Cannot use empty keys in "$min" modifier - -Deprecated: MongoDB\Driver\Query::__construct(): The "modifiers" option is deprecated and will be removed in a future release in %s on line %d -OK: Got MongoDB\Driver\Exception\InvalidArgumentException -Cannot use empty keys in "$orderby" modifier ===DONE=== diff --git a/tests/query/query-ctor_error-007.phpt b/tests/query/query-ctor_error-007.phpt index d6111bcae..01cf672ec 100644 --- a/tests/query/query-ctor_error-007.phpt +++ b/tests/query/query-ctor_error-007.phpt @@ -16,9 +16,6 @@ $tests = [ ['min' => MongoDB\BSON\PackedArray::fromPHP([])], ['projection' => MongoDB\BSON\PackedArray::fromPHP([])], ['sort' => MongoDB\BSON\PackedArray::fromPHP([])], - ['modifiers' => ['$max' => MongoDB\BSON\PackedArray::fromPHP([])]], - ['modifiers' => ['$min' => MongoDB\BSON\PackedArray::fromPHP([])]], - ['modifiers' => ['$orderby' => MongoDB\BSON\PackedArray::fromPHP([])]], ]; foreach ($tests as $options) { @@ -45,16 +42,4 @@ OK: Got MongoDB\Driver\Exception\UnexpectedValueException MongoDB\BSON\PackedArray cannot be serialized as a root document OK: Got MongoDB\Driver\Exception\UnexpectedValueException MongoDB\BSON\PackedArray cannot be serialized as a root document - -Deprecated: MongoDB\Driver\Query::__construct(): The "modifiers" option is deprecated and will be removed in a future release in %s on line %d -OK: Got MongoDB\Driver\Exception\UnexpectedValueException -MongoDB\BSON\PackedArray cannot be serialized as a root document - -Deprecated: MongoDB\Driver\Query::__construct(): The "modifiers" option is deprecated and will be removed in a future release in %s on line %d -OK: Got MongoDB\Driver\Exception\UnexpectedValueException -MongoDB\BSON\PackedArray cannot be serialized as a root document - -Deprecated: MongoDB\Driver\Query::__construct(): The "modifiers" option is deprecated and will be removed in a future release in %s on line %d -OK: Got MongoDB\Driver\Exception\UnexpectedValueException -MongoDB\BSON\PackedArray cannot be serialized as a root document ===DONE=== diff --git a/tests/query/query-debug-001.phpt b/tests/query/query-debug-001.phpt index ff6f566b5..97c57b5b8 100644 --- a/tests/query/query-debug-001.phpt +++ b/tests/query/query-debug-001.phpt @@ -7,10 +7,6 @@ var_dump(new MongoDB\Driver\Query( ['a' => 123], [ 'limit' => 5, - 'modifiers' => [ - '$comment' => 'foo', - '$maxTimeMS' => 500, - ], 'projection' => ['c' => 1], 'readConcern' => new MongoDB\Driver\ReadConcern(MongoDB\Driver\ReadConcern::LOCAL), 'skip' => 10, @@ -22,7 +18,6 @@ var_dump(new MongoDB\Driver\Query( ===DONE=== --EXPECTF-- -Deprecated: MongoDB\Driver\Query::__construct(): The "modifiers" option is deprecated and will be removed in a future release in %s on line %d object(MongoDB\Driver\Query)#%d (%d) { ["filter"]=> object(stdClass)#%d (%d) { @@ -31,10 +26,8 @@ object(MongoDB\Driver\Query)#%d (%d) { } ["options"]=> object(stdClass)#%d (%d) { - ["comment"]=> - string(3) "foo" - ["maxTimeMS"]=> - int(500) + ["limit"]=> + int(5) ["projection"]=> object(stdClass)#%d (%d) { ["c"]=> @@ -47,8 +40,6 @@ object(MongoDB\Driver\Query)#%d (%d) { ["b"]=> int(-1) } - ["limit"]=> - int(5) } ["readConcern"]=> array(1) { diff --git a/tests/query/query-debug-003.phpt b/tests/query/query-debug-003.phpt index c8ed9f16b..170bcff04 100644 --- a/tests/query/query-debug-003.phpt +++ b/tests/query/query-debug-003.phpt @@ -8,11 +8,6 @@ var_dump(new MongoDB\Driver\Query( ['comment' => ['foo' => 1]] )); -var_dump(new MongoDB\Driver\Query( - [], - ['modifiers' => ['$comment' => ['foo' => 1]]] -)); - ?> ===DONE=== @@ -32,21 +27,4 @@ object(MongoDB\Driver\Query)#%d (%d) { ["readConcern"]=> NULL } - -Deprecated: MongoDB\Driver\Query::__construct(): The "modifiers" option is deprecated and will be removed in a future release in %s on line %d -object(MongoDB\Driver\Query)#%d (%d) { - ["filter"]=> - object(stdClass)#%d (0) { - } - ["options"]=> - object(stdClass)#%d (%d) { - ["comment"]=> - object(stdClass)#%d (%d) { - ["foo"]=> - int(1) - } - } - ["readConcern"]=> - NULL -} ===DONE=== diff --git a/tests/server/server-executeQuery-003.phpt b/tests/server/server-executeQuery-003.phpt deleted file mode 100644 index 5f09daab5..000000000 --- a/tests/server/server-executeQuery-003.phpt +++ /dev/null @@ -1,64 +0,0 @@ ---TEST-- -MongoDB\Driver\Server::executeQuery() with modifiers and empty filter ---SKIPIF-- - - - ---FILE-- -executeQuery(NS, new MongoDB\Driver\Query(array()))->getServer(); - -// load fixtures for test -$bulk = new \MongoDB\Driver\BulkWrite(); -$bulk->insert(array('_id' => 1, 'x' => 2, 'y' => 3)); -$bulk->insert(array('_id' => 2, 'x' => 3, 'y' => 4)); -$bulk->insert(array('_id' => 3, 'x' => 4, 'y' => 5)); -$server->executeBulkWrite(NS, $bulk); - -$query = new MongoDB\Driver\Query(array(), array('modifiers' => array('$comment' => 'foo'))); -$cursor = $server->executeQuery(NS, $query); - -var_dump($cursor instanceof MongoDB\Driver\Cursor); -var_dump($server == $cursor->getServer()); -var_dump(iterator_to_array($cursor)); - -?> -===DONE=== - ---EXPECTF-- -Deprecated: MongoDB\Driver\Query::__construct(): The "modifiers" option is deprecated and will be removed in a future release in %s on line %d -bool(true) -bool(true) -array(3) { - [0]=> - object(stdClass)#%d (3) { - ["_id"]=> - int(1) - ["x"]=> - int(2) - ["y"]=> - int(3) - } - [1]=> - object(stdClass)#%d (3) { - ["_id"]=> - int(2) - ["x"]=> - int(3) - ["y"]=> - int(4) - } - [2]=> - object(stdClass)#%d (3) { - ["_id"]=> - int(3) - ["x"]=> - int(4) - ["y"]=> - int(5) - } -} -===DONE=== diff --git a/tests/server/server-executeQuery-007.phpt b/tests/server/server-executeQuery-007.phpt index 22dd82cae..67279c6f8 100644 --- a/tests/server/server-executeQuery-007.phpt +++ b/tests/server/server-executeQuery-007.phpt @@ -1,5 +1,5 @@ --TEST-- -MongoDB\Driver\Server::executeQuery() with negative limit returns a single batch +MongoDB\Driver\Server::executeQuery() with limit and single batch --SKIPIF-- @@ -18,7 +18,7 @@ $bulk->insert(['_id' => 2, 'x' => 3, 'y' => 4]); $bulk->insert(['_id' => 3, 'x' => 4, 'y' => 5]); $server->executeBulkWrite(NS, $bulk); -$query = new MongoDB\Driver\Query([], ['limit' => -2]); +$query = new MongoDB\Driver\Query([], ['limit' => 2, 'singleBatch' => true]); $cursor = $server->executeQuery(NS, $query); var_dump($cursor instanceof MongoDB\Driver\Cursor); diff --git a/tests/standalone/query-errors.phpt b/tests/standalone/query-errors.phpt deleted file mode 100644 index ca4b89a33..000000000 --- a/tests/standalone/query-errors.phpt +++ /dev/null @@ -1,37 +0,0 @@ ---TEST-- -MongoDB\Driver\Query: Invalid types ---FILE-- - "Smith, Carter and Buckridge"), array( - "projection" => array("_id" => 0, "username" => 1), - "sort" => array("phoneNumber" => 1), - "modifiers" => "string", - )); -}, "MongoDB\Driver\Exception\InvalidArgumentException"); - -throws(function() { - $query = new MongoDB\Driver\Query(array("company" => "Smith, Carter and Buckridge"), array( - "projection" => array("_id" => 0, "username" => 1), - "sort" => array("phoneNumber" => 1), - "projection" => "string", - )); -}, "MongoDB\Driver\Exception\InvalidArgumentException"); - -throws(function() { - $query = new MongoDB\Driver\Query(array("company" => "Smith, Carter and Buckridge"), array( - "projection" => array("_id" => 0, "username" => 1), - "sort" => "string" - )); -}, "MongoDB\Driver\Exception\InvalidArgumentException"); - -?> -===DONE=== - ---EXPECT-- -OK: Got MongoDB\Driver\Exception\InvalidArgumentException -OK: Got MongoDB\Driver\Exception\InvalidArgumentException -OK: Got MongoDB\Driver\Exception\InvalidArgumentException -===DONE===