Skip to content

Merge v1.x into v2.x #1693

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Sep 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 0 additions & 6 deletions .evergreen/config/build-variants.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 10 additions & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand All @@ -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/<path-to-test-file>.phpt
```

### File format

The extension's test use the PHPT format from PHP internals. This format is
documented in the following links:

Expand Down
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
10 changes: 7 additions & 3 deletions src/contrib/php_array_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -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) \
Expand Down Expand Up @@ -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)
Expand Down
22 changes: 22 additions & 0 deletions tests/bson/bug2456-001.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
--TEST--
PHPC-2456: References passed in a typeMap
--FILE--
<?php
require_once __DIR__ . "/../utils/basic.inc";

$fieldPaths = [];

$typeMap = ['fieldPaths' => &$fieldPaths];

var_dump(MongoDB\BSON\Document::fromPHP([])->toPHP($typeMap));
var_dump(MongoDB\BSON\PackedArray::fromPHP([])->toPHP($typeMap));

?>
===DONE===
<?php exit(0); ?>
--EXPECTF--
object(stdClass)#%d (0) {
}
array(0) {
}
===DONE===
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