diff --git a/.evergreen/config/build-variants.yml b/.evergreen/config/build-variants.yml index d99c2e19f..02a2c9567 100644 --- a/.evergreen/config/build-variants.yml +++ b/.evergreen/config/build-variants.yml @@ -60,12 +60,6 @@ buildvariants: run_on: rhel80-small tasks: - name: "build-all-php" - - name: build-rhel76 - display_name: "Build: RHEL 7.6" - tags: ["build", "rhel", "x64", "pr", "tag"] - run_on: rhel76-small - tasks: - - name: "build-all-php" # Ubuntu LTS - name: build-ubuntu2204 diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 580870903..b7dcb85e4 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -31,7 +31,7 @@ $ php --ri mongodb ## Generating arginfo from stub files Arginfo structures are generated from stub files using the `gen_stub.php` -file. Note that this requires `phpize` to be run for PHP 8.2 to make use +file. Note that this requires `phpize` to be run for **PHP 8.2** to make use of all features. After changing a stub file, run `./build/gen_stub.php` to regenerate the corresponding arginfo files and commit the results. @@ -44,6 +44,15 @@ when using this extension. To generate the function map, run the ## Testing +The driver includes a test suite that can be run with `make test`. To run a single +test file, define the `TESTS` variable with the file path: + +``` +make test TESTS=tests/.phpt +``` + +### File format + The extension's test use the PHPT format from PHP internals. This format is documented in the following links: diff --git a/src/MongoDB/Query.c b/src/MongoDB/Query.c index b694ae24e..941f9504b 100644 --- a/src/MongoDB/Query.c +++ b/src/MongoDB/Query.c @@ -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") diff --git a/src/contrib/php_array_api.h b/src/contrib/php_array_api.h index 76358dbb9..17dc74810 100644 --- a/src/contrib/php_array_api.h +++ b/src/contrib/php_array_api.h @@ -420,7 +420,9 @@ char *php_array_zval_to_string(zval *z, int *plen, zend_bool *pfree) { * zval *php_array_fetchz_array(zval *zarr, zval *key) */ static inline zval *php_array_zval_to_array(zval *zarr) { - return (zarr && (Z_TYPE_P(zarr) == IS_ARRAY)) ? zarr : NULL; + if (!zarr) { return NULL; } + ZVAL_DEREF(zarr); + return Z_TYPE_P(zarr) == IS_ARRAY ? zarr : NULL; } PHP_ARRAY_FETCH_TYPE_MAP(zval*, array) #define php_array_fetchc_array(zarr, litstr) \ @@ -493,8 +495,10 @@ void *php_array_zval_to_resource(zval *z, int le) { */ static inline zval *php_array_zval_to_object(zval *z, zend_class_entry *ce) { - return (z && (Z_TYPE_P(z) == IS_OBJECT) && - ((!ce) || instanceof_function(Z_OBJCE_P(z), ce))) ? z : NULL; + if (!z) { return NULL; } + ZVAL_DEREF(z); + if (Z_TYPE_P(z) != IS_OBJECT) { return NULL; } + return (!ce) || instanceof_function(Z_OBJCE_P(z), ce) ? z : NULL; } #define php_array_fetch_object(zarr, key, ce) \ php_array_zval_to_object(php_array_fetch(zarr, key), ce) diff --git a/tests/bson/bug2456-001.phpt b/tests/bson/bug2456-001.phpt new file mode 100644 index 000000000..53726a28c --- /dev/null +++ b/tests/bson/bug2456-001.phpt @@ -0,0 +1,22 @@ +--TEST-- +PHPC-2456: References passed in a typeMap +--FILE-- + &$fieldPaths]; + +var_dump(MongoDB\BSON\Document::fromPHP([])->toPHP($typeMap)); +var_dump(MongoDB\BSON\PackedArray::fromPHP([])->toPHP($typeMap)); + +?> +===DONE=== + +--EXPECTF-- +object(stdClass)#%d (0) { +} +array(0) { +} +===DONE=== diff --git a/tests/query/query-ctor-003.phpt b/tests/query/query-ctor-003.phpt index 947e0f18d..e68baeeed 100644 --- a/tests/query/query-ctor-003.phpt +++ b/tests/query/query-ctor-003.phpt @@ -39,6 +39,8 @@ 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 + 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 @@ -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) { @@ -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) { @@ -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) { diff --git a/tests/query/query-ctor-004.phpt b/tests/query/query-ctor-004.phpt index ea111175f..42b148d3d 100644 --- a/tests/query/query-ctor-004.phpt +++ b/tests/query/query-ctor-004.phpt @@ -49,6 +49,8 @@ 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 + 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 @@ -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) { @@ -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) { diff --git a/tests/query/query-ctor_error-002.phpt b/tests/query/query-ctor_error-002.phpt index 790fc1abd..830cd20bc 100644 --- a/tests/query/query-ctor_error-002.phpt +++ b/tests/query/query-ctor_error-002.phpt @@ -28,7 +28,7 @@ foreach ($tests as $options) { ?> ===DONE=== ---EXPECT-- +--EXPECTF-- OK: Got MongoDB\Driver\Exception\InvalidArgumentException Expected "modifiers" option to be array, int given @@ -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 diff --git a/tests/query/query-ctor_error-004.phpt b/tests/query/query-ctor_error-004.phpt index 9c2936c3d..2b74f8181 100644 --- a/tests/query/query-ctor_error-004.phpt +++ b/tests/query/query-ctor_error-004.phpt @@ -31,7 +31,7 @@ foreach ($tests as $test) { ?> ===DONE=== ---EXPECT-- +--EXPECTF-- OK: Got MongoDB\Driver\Exception\InvalidArgumentException Cannot use empty keys in filter document OK: Got MongoDB\Driver\Exception\InvalidArgumentException @@ -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=== diff --git a/tests/query/query-ctor_error-007.phpt b/tests/query/query-ctor_error-007.phpt index 4766d6364..d6111bcae 100644 --- a/tests/query/query-ctor_error-007.phpt +++ b/tests/query/query-ctor_error-007.phpt @@ -30,7 +30,7 @@ foreach ($tests as $options) { ?> ===DONE=== ---EXPECT-- +--EXPECTF-- OK: Got MongoDB\Driver\Exception\UnexpectedValueException MongoDB\BSON\PackedArray cannot be serialized as a root document OK: Got MongoDB\Driver\Exception\UnexpectedValueException @@ -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=== diff --git a/tests/query/query-debug-001.phpt b/tests/query/query-debug-001.phpt index a043b540f..ff6f566b5 100644 --- a/tests/query/query-debug-001.phpt +++ b/tests/query/query-debug-001.phpt @@ -22,6 +22,7 @@ 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) { diff --git a/tests/query/query-debug-003.phpt b/tests/query/query-debug-003.phpt index dee480a8a..c8ed9f16b 100644 --- a/tests/query/query-debug-003.phpt +++ b/tests/query/query-debug-003.phpt @@ -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) { diff --git a/tests/server/server-executeQuery-003.phpt b/tests/server/server-executeQuery-003.phpt index 942aa7cfd..5f09daab5 100644 --- a/tests/server/server-executeQuery-003.phpt +++ b/tests/server/server-executeQuery-003.phpt @@ -29,6 +29,7 @@ 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) { diff --git a/tests/standalone/executiontimeoutexception-001.phpt b/tests/standalone/executiontimeoutexception-001.phpt index 8c35546dd..44d41dbd8 100644 --- a/tests/standalone/executiontimeoutexception-001.phpt +++ b/tests/standalone/executiontimeoutexception-001.phpt @@ -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);