Skip to content
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

Merge v1.x into v2.x #1572

Closed
wants to merge 4 commits into from
Closed
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: 5 additions & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,12 @@ jobs:
fetch-depth: 2
submodules: true

- uses: actions/setup-python@v5
with:
python-version: '3.13'

- id: setup-mongodb
uses: mongodb-labs/drivers-evergreen-tools@81c6b49dd61e833229d750084f9f3c71b31acd8d
uses: mongodb-labs/drivers-evergreen-tools@master
with:
version: ${{ matrix.mongodb-version }}
topology: ${{ matrix.topology }}
Expand Down
1 change: 1 addition & 0 deletions generator/config/stage/geoNear.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ arguments:
name: distanceField
type:
- string
optional: true
description: |
The output field that contains the calculated distance. To specify a field within an embedded document, use dot notation.
-
Expand Down
6 changes: 3 additions & 3 deletions src/Builder/Stage/FactoryTrait.php

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions src/Builder/Stage/FluentFactoryTrait.php

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 7 additions & 7 deletions src/Builder/Stage/GeoNearStage.php

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions src/Exception/InvalidArgumentException.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,17 @@ public static function cannotCombineCodecAndTypeMap(): self
return new self('Cannot provide both "codec" and "typeMap" options');
}

/**
* Thrown when an argument or option is expected to be a string or a document.
*
* @param string $name Name of the argument or option
* @param mixed $value Actual value (used to derive the type)
*/
public static function expectedDocumentOrStringType(string $name, mixed $value): self
{
return new self(sprintf('Expected %s to have type "string" or "document" (array or object) but found "%s"', $name, get_debug_type($value)));
}

/**
* Thrown when an argument or option is expected to be a document.
*
Expand Down
5 changes: 2 additions & 3 deletions src/Operation/Aggregate.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
use function is_array;
use function is_bool;
use function is_integer;
use function is_object;
use function is_string;
use function MongoDB\is_document;
use function MongoDB\is_last_pipeline_operator_write;
Expand Down Expand Up @@ -150,8 +149,8 @@ public function __construct(private string $databaseName, private ?string $colle
throw InvalidArgumentException::invalidType('"explain" option', $this->options['explain'], 'boolean');
}

if (isset($this->options['hint']) && ! is_string($this->options['hint']) && ! is_array($this->options['hint']) && ! is_object($this->options['hint'])) {
throw InvalidArgumentException::invalidType('"hint" option', $this->options['hint'], 'string or array or object');
if (isset($this->options['hint']) && ! is_string($this->options['hint']) && ! is_document($this->options['hint'])) {
throw InvalidArgumentException::expectedDocumentOrStringType('"hint" option', $this->options['hint']);
}

if (isset($this->options['let']) && ! is_document($this->options['let'])) {
Expand Down
4 changes: 2 additions & 2 deletions src/Operation/Count.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,8 @@ public function __construct(private string $databaseName, private string $collec
throw InvalidArgumentException::expectedDocumentType('"collation" option', $this->options['collation']);
}

if (isset($this->options['hint']) && ! is_string($this->options['hint']) && ! is_array($this->options['hint']) && ! is_object($this->options['hint'])) {
throw InvalidArgumentException::invalidType('"hint" option', $this->options['hint'], 'string or array or object');
if (isset($this->options['hint']) && ! is_string($this->options['hint']) && ! is_document($this->options['hint'])) {
throw InvalidArgumentException::expectedDocumentOrStringType('"hint" option', $this->options['hint']);
}

if (isset($this->options['limit']) && ! is_integer($this->options['limit'])) {
Expand Down
6 changes: 2 additions & 4 deletions src/Operation/Delete.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@
use MongoDB\Exception\InvalidArgumentException;
use MongoDB\Exception\UnsupportedException;

use function is_array;
use function is_object;
use function is_string;
use function MongoDB\is_document;
use function MongoDB\is_write_concern_acknowledged;
Expand Down Expand Up @@ -96,8 +94,8 @@ public function __construct(private string $databaseName, private string $collec
throw InvalidArgumentException::expectedDocumentType('"collation" option', $this->options['collation']);
}

if (isset($this->options['hint']) && ! is_string($this->options['hint']) && ! is_array($this->options['hint']) && ! is_object($this->options['hint'])) {
throw InvalidArgumentException::invalidType('"hint" option', $this->options['hint'], ['string', 'array', 'object']);
if (isset($this->options['hint']) && ! is_string($this->options['hint']) && ! is_document($this->options['hint'])) {
throw InvalidArgumentException::expectedDocumentOrStringType('"hint" option', $this->options['hint']);
}

if (isset($this->options['session']) && ! $this->options['session'] instanceof Session) {
Expand Down
2 changes: 1 addition & 1 deletion src/Operation/Distinct.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public function __construct(private string $databaseName, private string $collec
}

if (isset($this->options['hint']) && ! is_string($this->options['hint']) && ! is_document($this->options['hint'])) {
throw InvalidArgumentException::invalidType('"hint" option', $this->options['hint'], 'string or array or object');
throw InvalidArgumentException::expectedDocumentOrStringType('"hint" option', $this->options['hint']);
}

if (isset($this->options['maxTimeMS']) && ! is_integer($this->options['maxTimeMS'])) {
Expand Down
4 changes: 2 additions & 2 deletions src/Operation/Find.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
use function assert;
use function is_array;
use function is_bool;
use function is_integer;

Check failure on line 36 in src/Operation/Find.php

View workflow job for this annotation

GitHub Actions / phpcs

Type is_object is not used in this file.
use function is_object;
use function is_string;
use function MongoDB\document_to_array;
Expand Down Expand Up @@ -195,8 +195,8 @@
}
}

if (isset($this->options['hint']) && ! is_string($this->options['hint']) && ! is_array($this->options['hint']) && ! is_object($this->options['hint'])) {
throw InvalidArgumentException::invalidType('"hint" option', $this->options['hint'], 'string or array or object');
if (isset($this->options['hint']) && ! is_string($this->options['hint']) && ! is_document($this->options['hint'])) {
throw InvalidArgumentException::expectedDocumentOrStringType('"hint" option', $this->options['hint']);
}

if (isset($this->options['limit']) && ! is_integer($this->options['limit'])) {
Expand Down
4 changes: 2 additions & 2 deletions src/Operation/FindAndModify.php
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,8 @@ public function __construct(private string $databaseName, private string $collec
throw InvalidArgumentException::expectedDocumentType('"fields" option', $options['fields']);
}

if (isset($options['hint']) && ! is_string($options['hint']) && ! is_array($options['hint']) && ! is_object($options['hint'])) {
throw InvalidArgumentException::invalidType('"hint" option', $options['hint'], ['string', 'array', 'object']);
if (isset($options['hint']) && ! is_string($options['hint']) && ! is_document($options['hint'])) {
throw InvalidArgumentException::expectedDocumentOrStringType('"hint" option', $options['hint']);
}

if (isset($options['maxTimeMS']) && ! is_integer($options['maxTimeMS'])) {
Expand Down
5 changes: 2 additions & 3 deletions src/Operation/Update.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@

use function is_array;
use function is_bool;
use function is_object;
use function is_string;
use function MongoDB\is_document;
use function MongoDB\is_first_key_operator;
Expand Down Expand Up @@ -122,8 +121,8 @@ public function __construct(private string $databaseName, private string $collec
throw InvalidArgumentException::expectedDocumentType('"collation" option', $options['collation']);
}

if (isset($options['hint']) && ! is_string($options['hint']) && ! is_array($options['hint']) && ! is_object($options['hint'])) {
throw InvalidArgumentException::invalidType('"hint" option', $options['hint'], ['string', 'array', 'object']);
if (isset($options['hint']) && ! is_string($options['hint']) && ! is_document($options['hint'])) {
throw InvalidArgumentException::expectedDocumentOrStringType('"hint" option', $options['hint']);
}

if (! is_bool($options['multi'])) {
Expand Down
2 changes: 1 addition & 1 deletion tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ protected static function getInvalidDocumentCodecValues(): array
*/
protected static function getInvalidHintValues(): array
{
return [123, 3.14, true];
return [123, 3.14, true, PackedArray::fromPHP([])];
}

/**
Expand Down
Loading