From 4f6f7743a628ba49e626bd0ae577db5a3b5991b2 Mon Sep 17 00:00:00 2001 From: Jeremy Mikola Date: Tue, 1 Oct 2024 14:02:21 -0400 Subject: [PATCH 1/2] PHPC-2464: Emit deprecation notice for negative "limit" Query option --- src/MongoDB/Query.c | 2 ++ tests/query/query-ctor-005.phpt | 3 +++ tests/query/query-ctor_error-003.phpt | 1 + tests/server/server-executeQuery-007.phpt | 1 + 4 files changed, 7 insertions(+) diff --git a/src/MongoDB/Query.c b/src/MongoDB/Query.c index 79c6135e0..ec0f1476f 100644 --- a/src/MongoDB/Query.c +++ b/src/MongoDB/Query.c @@ -209,6 +209,8 @@ static bool php_phongo_query_init_limit_and_singlebatch(php_phongo_query_t* inte if (php_array_fetchc_long(options, "limit") < 0) { zend_long limit = php_array_fetchc_long(options, "limit"); + php_error_docref(NULL, E_DEPRECATED, "Support for negative \"limit\" values is deprecated and will be removed in ext-mongodb 2.0"); + if (!BSON_APPEND_INT64(intern->opts, "limit", -limit)) { phongo_throw_exception(PHONGO_ERROR_INVALID_ARGUMENT, "Error appending \"limit\" option"); return false; diff --git a/tests/query/query-ctor-005.phpt b/tests/query/query-ctor-005.phpt index e206d731c..c0a534613 100644 --- a/tests/query/query-ctor-005.phpt +++ b/tests/query/query-ctor-005.phpt @@ -20,6 +20,7 @@ var_dump(new MongoDB\Driver\Query( ===DONE=== --EXPECTF-- +Deprecated: MongoDB\Driver\Query::__construct(): Support for negative "limit" values is deprecated and will be removed in ext-mongodb 2.0 in %s on line %d object(MongoDB\Driver\Query)#%d (%d) { ["filter"]=> object(stdClass)#%d (%d) { @@ -36,6 +37,8 @@ object(MongoDB\Driver\Query)#%d (%d) { ["readConcern"]=> NULL } + +Deprecated: MongoDB\Driver\Query::__construct(): Support for negative "limit" values is deprecated and will be removed in ext-mongodb 2.0 in %s on line %d object(MongoDB\Driver\Query)#%d (%d) { ["filter"]=> object(stdClass)#%d (%d) { diff --git a/tests/query/query-ctor_error-003.phpt b/tests/query/query-ctor_error-003.phpt index 7616f8058..e10b69166 100644 --- a/tests/query/query-ctor_error-003.phpt +++ b/tests/query/query-ctor_error-003.phpt @@ -13,6 +13,7 @@ echo throws(function() { ===DONE=== --EXPECT-- +Deprecated: MongoDB\Driver\Query::__construct(): Support for negative "limit" values is deprecated and will be removed in ext-mongodb 2.0 in %s on line %d OK: Got MongoDB\Driver\Exception\InvalidArgumentException Negative "limit" option conflicts with false "singleBatch" option ===DONE=== diff --git a/tests/server/server-executeQuery-007.phpt b/tests/server/server-executeQuery-007.phpt index 22dd82cae..3f8c960cf 100644 --- a/tests/server/server-executeQuery-007.phpt +++ b/tests/server/server-executeQuery-007.phpt @@ -29,6 +29,7 @@ var_dump(iterator_to_array($cursor)); ===DONE=== --EXPECTF-- +Deprecated: MongoDB\Driver\Query::__construct(): Support for negative "limit" values is deprecated and will be removed in ext-mongodb 2.0 in %s on line %d bool(true) bool(true) array(2) { From 2edc427cf831a73e966eab7db984fac3c2f1e2c6 Mon Sep 17 00:00:00 2001 From: Andreas Braun Date: Wed, 2 Oct 2024 08:26:58 +0200 Subject: [PATCH 2/2] Fix wrong test expectation --- tests/query/query-ctor_error-003.phpt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/query/query-ctor_error-003.phpt b/tests/query/query-ctor_error-003.phpt index e10b69166..696222477 100644 --- a/tests/query/query-ctor_error-003.phpt +++ b/tests/query/query-ctor_error-003.phpt @@ -12,7 +12,7 @@ echo throws(function() { ?> ===DONE=== ---EXPECT-- +--EXPECTF-- Deprecated: MongoDB\Driver\Query::__construct(): Support for negative "limit" values is deprecated and will be removed in ext-mongodb 2.0 in %s on line %d OK: Got MongoDB\Driver\Exception\InvalidArgumentException Negative "limit" option conflicts with false "singleBatch" option