Skip to content

Commit

Permalink
PHPC-2453: Deprecation notice for Query "modifiers" option (#1680)
Browse files Browse the repository at this point in the history
  • Loading branch information
jmikola authored Sep 24, 2024
1 parent 7da337f commit 2543865
Show file tree
Hide file tree
Showing 10 changed files with 46 additions and 6 deletions.
2 changes: 2 additions & 0 deletions src/MongoDB/Query.c
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,8 @@ bool phongo_query_init(zval* return_value, zval* filter, zval* options)
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")
Expand Down
8 changes: 8 additions & 0 deletions tests/query/query-ctor-003.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ var_dump(new MongoDB\Driver\Query(
===DONE===
<?php exit(0); ?>
--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
Expand Down Expand Up @@ -81,6 +83,8 @@ 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 (%d) {
Expand All @@ -95,6 +99,8 @@ 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 (%d) {
Expand All @@ -109,6 +115,8 @@ 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 (%d) {
Expand Down
6 changes: 6 additions & 0 deletions tests/query/query-ctor-004.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ var_dump(new MongoDB\Driver\Query(
===DONE===
<?php exit(0); ?>
--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
Expand Down Expand Up @@ -91,6 +93,8 @@ 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 (%d) {
Expand All @@ -105,6 +109,8 @@ 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 (%d) {
Expand Down
10 changes: 9 additions & 1 deletion tests/query/query-ctor_error-002.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ foreach ($tests as $options) {
?>
===DONE===
<?php exit(0); ?>
--EXPECT--
--EXPECTF--
OK: Got MongoDB\Driver\Exception\InvalidArgumentException
Expected "modifiers" option to be array, int given

Expand All @@ -50,15 +50,23 @@ 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

Expand Down
10 changes: 9 additions & 1 deletion tests/query/query-ctor_error-004.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ foreach ($tests as $test) {
?>
===DONE===
<?php exit(0); ?>
--EXPECT--
--EXPECTF--
OK: Got MongoDB\Driver\Exception\InvalidArgumentException
Cannot use empty keys in filter document
OK: Got MongoDB\Driver\Exception\InvalidArgumentException
Expand All @@ -48,12 +48,20 @@ 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===
8 changes: 7 additions & 1 deletion tests/query/query-ctor_error-007.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ foreach ($tests as $options) {
?>
===DONE===
<?php exit(0); ?>
--EXPECT--
--EXPECTF--
OK: Got MongoDB\Driver\Exception\UnexpectedValueException
MongoDB\BSON\PackedArray cannot be serialized as a root document
OK: Got MongoDB\Driver\Exception\UnexpectedValueException
Expand All @@ -45,10 +45,16 @@ 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===
1 change: 1 addition & 0 deletions tests/query/query-debug-001.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ var_dump(new MongoDB\Driver\Query(
===DONE===
<?php exit(0); ?>
--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) {
Expand Down
2 changes: 2 additions & 0 deletions tests/query/query-debug-003.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ 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) {
Expand Down
1 change: 1 addition & 0 deletions tests/server/server-executeQuery-003.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ var_dump(iterator_to_array($cursor));
===DONE===
<?php exit(0); ?>
--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) {
Expand Down
4 changes: 1 addition & 3 deletions tests/standalone/executiontimeoutexception-001.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@ $server = $manager->selectServer(new \MongoDB\Driver\ReadPreference('primary'));
$query = new MongoDB\Driver\Query(array("company" => "Smith, Carter and Buckridge"), array(
'projection' => array('_id' => 0, 'username' => 1),
'sort' => array('phoneNumber' => 1),
'modifiers' => array(
'$maxTimeMS' => 1,
),
'maxTimeMS' => 1,
));

failMaxTimeMS($server);
Expand Down

0 comments on commit 2543865

Please sign in to comment.