diff --git a/lib/Doctrine/ODM/MongoDB/Aggregation/Builder.php b/lib/Doctrine/ODM/MongoDB/Aggregation/Builder.php index 3496f370c4..9b38189483 100644 --- a/lib/Doctrine/ODM/MongoDB/Aggregation/Builder.php +++ b/lib/Doctrine/ODM/MongoDB/Aggregation/Builder.php @@ -160,6 +160,14 @@ public function count(string $fieldName): Stage\Count return $stage; } + /** + * Create a new Expr instance that can be used as an expression with the Builder + */ + public function createAggregationExpression(): Expr + { + return new Expr($this->dm, $this->class); + } + /** * Executes the aggregation pipeline * @@ -180,9 +188,20 @@ public function execute(array $options = []): Iterator return $this->getAggregation($options)->getIterator(); } + /** + * @deprecated use createAggregationExpression instead + */ public function expr(): Expr { - return new Expr($this->dm, $this->class); + trigger_deprecation( + 'doctrine/mongodb-odm', + '2.5', + 'The "%s" method is deprecated. Please use "%s::createAggregationExpression" instead.', + __METHOD__, + static::class + ); + + return $this->createAggregationExpression(); } /** diff --git a/lib/Doctrine/ODM/MongoDB/Aggregation/Expr.php b/lib/Doctrine/ODM/MongoDB/Aggregation/Expr.php index 50cebef908..7f51f12b92 100644 --- a/lib/Doctrine/ODM/MongoDB/Aggregation/Expr.php +++ b/lib/Doctrine/ODM/MongoDB/Aggregation/Expr.php @@ -19,6 +19,7 @@ use function is_array; use function is_string; use function substr; +use function trigger_deprecation; /** * Fluent interface for building aggregation pipelines. @@ -324,6 +325,16 @@ public static function convertExpression($expression) return $expression; } + /** + * Returns a new expression object + * + * @return static + */ + public function createAggregationExpression(): self + { + return new static($this->dm, $this->class); + } + /** * Converts a date object to a string according to a user-specified format. * @@ -453,10 +464,20 @@ public function exp($exponent): self /** * Returns a new expression object + * + * @deprecated use createAggregationExpression instead */ public function expr(): self { - return new static($this->dm, $this->class); + trigger_deprecation( + 'doctrine/mongodb-odm', + '2.5', + 'The "%s" method is deprecated. Please use "%s::createAggregationExpression" instead.', + __METHOD__, + static::class + ); + + return $this->createAggregationExpression(); } /** @@ -1098,6 +1119,20 @@ public function reduce($input, $initialValue, $in): self return $this->operator('$reduce', ['input' => $input, 'initialValue' => $initialValue, 'in' => $in]); } + /** + * Performs a regular expression (regex) pattern matching + * + * @see https://docs.mongodb.com/manual/reference/operator/aggregation/regexMatch/ + * + * @param mixed|self $input The value to compare. (Use "$" format to test your regex on a field) + * @param mixed|self $regex The regular expression (regex) + * @param mixed|self $options A string containing regex flags options. See mongodb doc. above for details + */ + public function regexMatch($input, $regex, $options): self + { + return $this->operator('$regexMatch', ['input' => $input, 'regex' => $regex, 'options' => $options]); + } + /** * Accepts an array expression as an argument and returns an array with the * elements in reverse order. diff --git a/lib/Doctrine/ODM/MongoDB/Aggregation/Stage/Bucket/AbstractOutput.php b/lib/Doctrine/ODM/MongoDB/Aggregation/Stage/Bucket/AbstractOutput.php index 89cde5600b..feb48089ec 100644 --- a/lib/Doctrine/ODM/MongoDB/Aggregation/Stage/Bucket/AbstractOutput.php +++ b/lib/Doctrine/ODM/MongoDB/Aggregation/Stage/Bucket/AbstractOutput.php @@ -25,7 +25,7 @@ public function __construct(Builder $builder, Stage\AbstractBucket $bucket) parent::__construct($builder); $this->bucket = $bucket; - $this->expr = $builder->expr(); + $this->expr = $builder->createAggregationExpression(); } public function getExpression(): array diff --git a/lib/Doctrine/ODM/MongoDB/Aggregation/Stage/Group.php b/lib/Doctrine/ODM/MongoDB/Aggregation/Stage/Group.php index 88bb883dbe..332c79e598 100644 --- a/lib/Doctrine/ODM/MongoDB/Aggregation/Stage/Group.php +++ b/lib/Doctrine/ODM/MongoDB/Aggregation/Stage/Group.php @@ -19,7 +19,7 @@ public function __construct(Builder $builder) { parent::__construct($builder); - $this->expr = $builder->expr(); + $this->expr = $builder->createAggregationExpression(); } public function getExpression(): array diff --git a/lib/Doctrine/ODM/MongoDB/Aggregation/Stage/MatchStage.php b/lib/Doctrine/ODM/MongoDB/Aggregation/Stage/MatchStage.php index 6fbf7f20da..73cc19eb4d 100644 --- a/lib/Doctrine/ODM/MongoDB/Aggregation/Stage/MatchStage.php +++ b/lib/Doctrine/ODM/MongoDB/Aggregation/Stage/MatchStage.php @@ -4,12 +4,14 @@ namespace Doctrine\ODM\MongoDB\Aggregation\Stage; +use Doctrine\ODM\MongoDB\Aggregation; use Doctrine\ODM\MongoDB\Aggregation\Builder; use Doctrine\ODM\MongoDB\Aggregation\Stage; use Doctrine\ODM\MongoDB\Query\Expr; use GeoJson\Geometry\Geometry; use function func_get_args; +use function trigger_deprecation; /** * Fluent interface for building aggregation pipelines. @@ -23,7 +25,7 @@ public function __construct(Builder $builder) { parent::__construct($builder); - $this->query = $this->expr(); + $this->query = $this->createQueryExpression(); } /** @@ -114,6 +116,15 @@ public function all(array $values): self return $this; } + /** + * Create a new Expr instance that can be used to build partial expressions + * for other operator methods. + */ + public function createQueryExpression(): Expr + { + return $this->builder->matchExpr(); + } + /** * Specify $elemMatch criteria for the current field. * @@ -166,12 +177,34 @@ public function exists(bool $bool): self } /** - * Create a new Expr instance that can be used to build partial expressions - * for other operator methods. + * @deprecated use createExpr instead */ public function expr(): Expr { - return $this->builder->matchExpr(); + trigger_deprecation( + 'doctrine/mongodb-odm', + '2.5', + 'The "%s" method is deprecated. Please use "%s::createQueryExpression" instead.', + __METHOD__, + static::class + ); + + return $this->createQueryExpression(); + } + + /** + * Specify $expr criteria for the current field. + * + * @see https://docs.mongodb.com/manual/reference/operator/query/expr/ + * @see Expr::aggregationExpression() + * + * @param array|Aggregation\Expr $expression + */ + public function aggregationExpression($expression): self + { + $this->query->aggregationExpression($expression); + + return $this; } /** diff --git a/lib/Doctrine/ODM/MongoDB/Aggregation/Stage/Operator.php b/lib/Doctrine/ODM/MongoDB/Aggregation/Stage/Operator.php index 2f2c8fd1d1..ede563aa58 100644 --- a/lib/Doctrine/ODM/MongoDB/Aggregation/Stage/Operator.php +++ b/lib/Doctrine/ODM/MongoDB/Aggregation/Stage/Operator.php @@ -27,7 +27,7 @@ public function __construct(Builder $builder) { parent::__construct($builder); - $this->expr = $builder->expr(); + $this->expr = $builder->createAggregationExpression(); } /** diff --git a/lib/Doctrine/ODM/MongoDB/Configuration.php b/lib/Doctrine/ODM/MongoDB/Configuration.php index de421104bf..6cc439a6c4 100644 --- a/lib/Doctrine/ODM/MongoDB/Configuration.php +++ b/lib/Doctrine/ODM/MongoDB/Configuration.php @@ -104,7 +104,8 @@ class Configuration * persistentCollectionGenerator?: PersistentCollectionGenerator, * persistentCollectionDir?: string, * persistentCollectionNamespace?: string, - * repositoryFactory?: RepositoryFactory + * repositoryFactory?: RepositoryFactory, + * writeConcern?: WriteConcern * } */ private array $attributes = []; diff --git a/lib/Doctrine/ODM/MongoDB/DocumentManager.php b/lib/Doctrine/ODM/MongoDB/DocumentManager.php index beafc603fe..de7547f895 100644 --- a/lib/Doctrine/ODM/MongoDB/DocumentManager.php +++ b/lib/Doctrine/ODM/MongoDB/DocumentManager.php @@ -284,7 +284,6 @@ public function getClassNameResolver(): ClassNameResolver * @psalm-return ClassMetadata * * @template T of object - * * @psalm-suppress InvalidReturnType, InvalidReturnStatement see https://github.com/vimeo/psalm/issues/5788 */ public function getClassMetadata($className): ClassMetadata diff --git a/lib/Doctrine/ODM/MongoDB/Iterator/CachingIterator.php b/lib/Doctrine/ODM/MongoDB/Iterator/CachingIterator.php index cfb6d4c022..8c134c15db 100644 --- a/lib/Doctrine/ODM/MongoDB/Iterator/CachingIterator.php +++ b/lib/Doctrine/ODM/MongoDB/Iterator/CachingIterator.php @@ -6,7 +6,6 @@ use Countable; use Generator; -use ReturnTypeWillChange; use RuntimeException; use Traversable; @@ -80,7 +79,7 @@ public function toArray(): array /** * @return TValue|false */ - #[ReturnTypeWillChange] + #[\ReturnTypeWillChange] public function current() { return current($this->items); @@ -89,7 +88,7 @@ public function current() /** * @return mixed */ - #[ReturnTypeWillChange] + #[\ReturnTypeWillChange] public function key() { return key($this->items); diff --git a/lib/Doctrine/ODM/MongoDB/Iterator/HydratingIterator.php b/lib/Doctrine/ODM/MongoDB/Iterator/HydratingIterator.php index 7c8319df59..dcfb27d023 100644 --- a/lib/Doctrine/ODM/MongoDB/Iterator/HydratingIterator.php +++ b/lib/Doctrine/ODM/MongoDB/Iterator/HydratingIterator.php @@ -8,7 +8,6 @@ use Doctrine\ODM\MongoDB\UnitOfWork; use Generator; use Iterator; -use ReturnTypeWillChange; use RuntimeException; use Traversable; @@ -60,7 +59,7 @@ public function __destruct() /** * @return TDocument|null */ - #[ReturnTypeWillChange] + #[\ReturnTypeWillChange] public function current() { return $this->hydrate($this->getIterator()->current()); @@ -69,7 +68,7 @@ public function current() /** * @return mixed */ - #[ReturnTypeWillChange] + #[\ReturnTypeWillChange] public function key() { return $this->getIterator()->key(); diff --git a/lib/Doctrine/ODM/MongoDB/Iterator/PrimingIterator.php b/lib/Doctrine/ODM/MongoDB/Iterator/PrimingIterator.php index cedb8898ef..dd954256a4 100644 --- a/lib/Doctrine/ODM/MongoDB/Iterator/PrimingIterator.php +++ b/lib/Doctrine/ODM/MongoDB/Iterator/PrimingIterator.php @@ -7,7 +7,6 @@ use Doctrine\ODM\MongoDB\Mapping\ClassMetadata; use Doctrine\ODM\MongoDB\Query\ReferencePrimer; use Doctrine\ODM\MongoDB\UnitOfWork; -use ReturnTypeWillChange; use function is_callable; use function iterator_to_array; @@ -62,7 +61,7 @@ public function toArray(): array /** * @return TValue|null */ - #[ReturnTypeWillChange] + #[\ReturnTypeWillChange] public function current() { $this->primeReferences(); @@ -78,7 +77,7 @@ public function next(): void /** * @return mixed */ - #[ReturnTypeWillChange] + #[\ReturnTypeWillChange] public function key() { return $this->iterator->key(); diff --git a/lib/Doctrine/ODM/MongoDB/Iterator/UnrewindableIterator.php b/lib/Doctrine/ODM/MongoDB/Iterator/UnrewindableIterator.php index 9e50eff62b..6883c960cb 100644 --- a/lib/Doctrine/ODM/MongoDB/Iterator/UnrewindableIterator.php +++ b/lib/Doctrine/ODM/MongoDB/Iterator/UnrewindableIterator.php @@ -6,7 +6,6 @@ use Generator; use LogicException; -use ReturnTypeWillChange; use RuntimeException; use Traversable; @@ -61,7 +60,7 @@ public function toArray(): array /** * @return TValue|null */ - #[ReturnTypeWillChange] + #[\ReturnTypeWillChange] public function current() { return $this->getIterator()->current(); @@ -70,7 +69,7 @@ public function current() /** * @return mixed */ - #[ReturnTypeWillChange] + #[\ReturnTypeWillChange] public function key() { if ($this->iterator) { diff --git a/lib/Doctrine/ODM/MongoDB/PersistentCollection/PersistentCollectionTrait.php b/lib/Doctrine/ODM/MongoDB/PersistentCollection/PersistentCollectionTrait.php index c538336958..42549aab18 100644 --- a/lib/Doctrine/ODM/MongoDB/PersistentCollection/PersistentCollectionTrait.php +++ b/lib/Doctrine/ODM/MongoDB/PersistentCollection/PersistentCollectionTrait.php @@ -12,7 +12,6 @@ use Doctrine\ODM\MongoDB\MongoDBException; use Doctrine\ODM\MongoDB\UnitOfWork; use Doctrine\ODM\MongoDB\Utility\CollectionHelper; -use ReturnTypeWillChange; use Traversable; use function array_combine; @@ -410,7 +409,7 @@ public function getValues() /** * @return int */ - #[ReturnTypeWillChange] + #[\ReturnTypeWillChange] public function count() { // Workaround around not being able to directly count inverse collections anymore @@ -438,7 +437,7 @@ public function isEmpty() * @return Traversable * @psalm-return Traversable */ - #[ReturnTypeWillChange] + #[\ReturnTypeWillChange] public function getIterator() { $this->initialize(); @@ -537,7 +536,7 @@ public function __sleep() * * @return bool */ - #[ReturnTypeWillChange] + #[\ReturnTypeWillChange] public function offsetExists($offset) { $this->initialize(); @@ -551,7 +550,7 @@ public function offsetExists($offset) * @return mixed * @psalm-return T|null */ - #[ReturnTypeWillChange] + #[\ReturnTypeWillChange] public function offsetGet($offset) { $this->initialize(); @@ -565,7 +564,7 @@ public function offsetGet($offset) * * @return void */ - #[ReturnTypeWillChange] + #[\ReturnTypeWillChange] public function offsetSet($offset, $value) { if (! isset($offset)) { @@ -582,7 +581,7 @@ public function offsetSet($offset, $value) * * @return void */ - #[ReturnTypeWillChange] + #[\ReturnTypeWillChange] public function offsetUnset($offset) { $this->doRemove($offset, true); diff --git a/lib/Doctrine/ODM/MongoDB/Query/Builder.php b/lib/Doctrine/ODM/MongoDB/Query/Builder.php index 1dc91e98e2..386937c73d 100644 --- a/lib/Doctrine/ODM/MongoDB/Query/Builder.php +++ b/lib/Doctrine/ODM/MongoDB/Query/Builder.php @@ -5,6 +5,7 @@ namespace Doctrine\ODM\MongoDB\Query; use BadMethodCallException; +use Doctrine\ODM\MongoDB\Aggregation; use Doctrine\ODM\MongoDB\DocumentManager; use Doctrine\ODM\MongoDB\Mapping\ClassMetadata; use GeoJson\Geometry\Geometry; @@ -25,6 +26,7 @@ use function is_callable; use function is_string; use function strtolower; +use function trigger_deprecation; /** * Query builder for ODM. @@ -120,7 +122,7 @@ public function __clone() /** * Add one or more $and clauses to the current query. * - * You can create a new expression using the {@link Builder::expr()} method. + * You can create a new expression using the {@link Builder::createAggregationExpression()} method. * * @see Expr::addAnd() * @see https://docs.mongodb.com/manual/reference/operator/and/ @@ -138,7 +140,7 @@ public function addAnd($expression, ...$expressions): self /** * Add one or more $nor clauses to the current query. * - * You can create a new expression using the {@link Builder::expr()} method. + * You can create a new expression using the {@link Builder::createAggregationExpression()} method. * * @see Expr::addNor() * @see https://docs.mongodb.com/manual/reference/operator/nor/ @@ -156,7 +158,7 @@ public function addNor($expression, ...$expressions): self /** * Add one or more $or clauses to the current query. * - * You can create a new expression using the {@link Builder::expr()} method. + * You can create a new expression using the {@link Builder::createAggregationExpression()} method. * * @see Expr::addOr() * @see https://docs.mongodb.com/manual/reference/operator/or/ @@ -356,6 +358,17 @@ public function count(): self return $this; } + /** + * Create a new Expr instance that can be used as an expression with the Builder + */ + public function createQueryExpression(): Expr + { + $expr = new Expr($this->dm); + $expr->setClassMetadata($this->class); + + return $expr; + } + /** * Sets the value of the current field to the current date, either as a date or a timestamp. * @@ -417,7 +430,7 @@ public function distinct(string $field): self /** * Specify $elemMatch criteria for the current field. * - * You can create a new expression using the {@link Builder::expr()} method. + * You can create a new expression using the {@link Builder::createAggregationExpression()} method. * * @see Expr::elemMatch() * @see https://docs.mongodb.com/manual/reference/operator/elemMatch/ @@ -452,6 +465,9 @@ public function equals($value): self * excluded. * * @param string[]|string $fieldName,... + * @param null|string|string[] $fieldName + * + * @psalm-param 'comments'|array{0: 'name', 1: 'issues'}|null $fieldName */ public function exclude($fieldName = null): self { @@ -483,13 +499,35 @@ public function exists(bool $bool): self /** * Create a new Expr instance that can be used as an expression with the Builder + * + * @deprecated use createQueryExpression instead */ public function expr(): Expr { - $expr = new Expr($this->dm); - $expr->setClassMetadata($this->class); + trigger_deprecation( + 'doctrine/mongodb-odm', + '2.5', + 'The "%s" method is deprecated. Please use "%s::createQueryExpression" instead.', + __METHOD__, + static::class + ); - return $expr; + return $this->createQueryExpression(); + } + + /** + * Specify $expr criteria for the current field. + * + * @see https://docs.mongodb.com/manual/reference/operator/query/expr/ + * @see Aggregation\Expr::aggregationExpression() + * + * @param array|Aggregation\Expr $expression + */ + public function aggregationExpression($expression): self + { + $this->expr->aggregationExpression($expression); + + return $this; } /** @@ -1019,7 +1057,7 @@ public function nearSphere($x, $y = null): self /** * Negates an expression for the current field. * - * You can create a new expression using the {@link Builder::expr()} method. + * You can create a new expression using the {@link Builder::createAggregationExpression()} method. * * @see Expr::not() * @see https://docs.mongodb.com/manual/reference/operator/not/ @@ -1253,7 +1291,9 @@ public function returnNew(bool $bool = true): self /** * Set one or more fields to be included in the query projection. * - * @param string[]|string $fieldName,... + * @param null|string|string[] $fieldName + * + * @return Builder */ public function select($fieldName = null): self { diff --git a/lib/Doctrine/ODM/MongoDB/Query/Expr.php b/lib/Doctrine/ODM/MongoDB/Query/Expr.php index 3439ceeb04..53d8a84bea 100644 --- a/lib/Doctrine/ODM/MongoDB/Query/Expr.php +++ b/lib/Doctrine/ODM/MongoDB/Query/Expr.php @@ -5,6 +5,7 @@ namespace Doctrine\ODM\MongoDB\Query; use BadMethodCallException; +use Doctrine\ODM\MongoDB\Aggregation; use Doctrine\ODM\MongoDB\DocumentManager; use Doctrine\ODM\MongoDB\Mapping\ClassMetadata; use Doctrine\ODM\MongoDB\Mapping\MappingException; @@ -404,6 +405,19 @@ public function elemMatch($expression): self return $this->operator('$elemMatch', $expression); } + /** + * Specify $expr criteria for the current field. + * + * @see Builder::aggregationExpression() + * @see https://docs.mongodb.com/manual/reference/operator/query/expr/ + * + * @param array|Aggregation\Expr $expression + */ + public function aggregationExpression($expression): self + { + return $this->operator('$expr', $expression); + } + /** * Specify an equality match for the current field. * diff --git a/lib/Doctrine/ODM/MongoDB/Query/QueryExpressionVisitor.php b/lib/Doctrine/ODM/MongoDB/Query/QueryExpressionVisitor.php index e9fe6f1d7a..a652ebdf7b 100644 --- a/lib/Doctrine/ODM/MongoDB/Query/QueryExpressionVisitor.php +++ b/lib/Doctrine/ODM/MongoDB/Query/QueryExpressionVisitor.php @@ -71,14 +71,14 @@ public function walkComparison(Comparison $comparison): Expr case Comparison::NIN: $method = self::$operatorMethods[$comparison->getOperator()]; - return $this->builder->expr() + return $this->builder->createQueryExpression() ->field($comparison->getField()) ->{$method}($this->walkValue($comparison->getValue())); case Comparison::CONTAINS: $value = $this->walkValue($comparison->getValue()); - return $this->builder->expr() + return $this->builder->createQueryExpression() ->field($comparison->getField()) ->equals(new Regex($value, '')); @@ -99,7 +99,7 @@ public function walkCompositeExpression(CompositeExpression $expr): Expr } $method = self::$compositeMethods[$expr->getType()]; - $outputExpr = $this->builder->expr(); + $outputExpr = $this->builder->createQueryExpression(); foreach ($expr->getExpressionList() as $child) { $outputExpr->{$method}($this->dispatch($child)); diff --git a/lib/Doctrine/ODM/MongoDB/Types/DateImmutableType.php b/lib/Doctrine/ODM/MongoDB/Types/DateImmutableType.php index edaac74042..96fde2023d 100644 --- a/lib/Doctrine/ODM/MongoDB/Types/DateImmutableType.php +++ b/lib/Doctrine/ODM/MongoDB/Types/DateImmutableType.php @@ -16,6 +16,8 @@ class DateImmutableType extends DateType { /** * @return DateTimeImmutable + * + * @param \MongoDB\BSON\UTCDateTime|float $value */ public static function getDateTime($value): DateTimeInterface { diff --git a/lib/Doctrine/ODM/MongoDB/UnitOfWork.php b/lib/Doctrine/ODM/MongoDB/UnitOfWork.php index 2dbb82a82e..6b2ee9706e 100644 --- a/lib/Doctrine/ODM/MongoDB/UnitOfWork.php +++ b/lib/Doctrine/ODM/MongoDB/UnitOfWork.php @@ -55,7 +55,7 @@ * 1: mixed * } * @psalm-type Hints = array - * @psalm-type CommitOptions array{ + * @psalm-type CommitOptions = array{ * fsync?: bool, * safe?: int, * w?: int, @@ -1601,7 +1601,6 @@ public function removeFromIdentityMap(object $document): bool * @throws InvalidArgumentException If the class does not have an identifier. * * @template T of object - * * @psalm-suppress InvalidReturnStatement, InvalidReturnType because of the inability of defining a generic property map */ public function getById($id, ClassMetadata $class): object @@ -1630,7 +1629,6 @@ public function getById($id, ClassMetadata $class): object * @throws InvalidArgumentException If the class does not have an identifier. * * @template T of object - * * @psalm-suppress InvalidReturnStatement, InvalidReturnType because of the inability of defining a generic property map */ public function tryGetById($id, ClassMetadata $class) diff --git a/tests/Doctrine/ODM/MongoDB/Tests/Aggregation/BuilderTest.php b/tests/Doctrine/ODM/MongoDB/Tests/Aggregation/BuilderTest.php index 1a8e1e1e14..0d1ecc40ad 100644 --- a/tests/Doctrine/ODM/MongoDB/Tests/Aggregation/BuilderTest.php +++ b/tests/Doctrine/ODM/MongoDB/Tests/Aggregation/BuilderTest.php @@ -135,7 +135,7 @@ public function testGetPipeline(): void ->unwind('b') ->redact() ->cond( - $builder->expr()->lte('$accessLevel', 3), + $builder->createAggregationExpression()->lte('$accessLevel', 3), '$$KEEP', '$$REDACT' ) @@ -144,9 +144,9 @@ public function testGetPipeline(): void ->includeFields(['user', 'amount', 'invoiceAddress']) ->field('deliveryAddress') ->cond( - $builder->expr() - ->addAnd($builder->expr()->eq('$useAlternateDeliveryAddress', true)) - ->addAnd($builder->expr()->ne('$deliveryAddress', null)), + $builder->createAggregationExpression() + ->addAnd($builder->createAggregationExpression()->eq('$useAlternateDeliveryAddress', true)) + ->addAnd($builder->createAggregationExpression()->ne('$deliveryAddress', null)), '$deliveryAddress', '$invoiceAddress' ) @@ -157,7 +157,7 @@ public function testGetPipeline(): void ->sum(1) ->field('amount') ->expression( - $builder->expr() + $builder->createAggregationExpression() ->field('total') ->sum('$amount') ->field('avg') @@ -267,9 +267,9 @@ public function testPipelineConvertsTypes(): void ->group() ->field('id') ->expression( - $builder->expr() + $builder->createAggregationExpression() ->cond( - $builder->expr()->lt('$createdAt', $dateTime), + $builder->createAggregationExpression()->lt('$createdAt', $dateTime), true, false ) diff --git a/tests/Doctrine/ODM/MongoDB/Tests/Aggregation/Stage/RedactTest.php b/tests/Doctrine/ODM/MongoDB/Tests/Aggregation/Stage/RedactTest.php index 6f3e5a22dd..ab715d9c85 100644 --- a/tests/Doctrine/ODM/MongoDB/Tests/Aggregation/Stage/RedactTest.php +++ b/tests/Doctrine/ODM/MongoDB/Tests/Aggregation/Stage/RedactTest.php @@ -19,7 +19,7 @@ public function testRedactStage(): void $redactStage = new Redact($builder); $redactStage ->cond( - $builder->expr()->lte('$accessLevel', 3), + $builder->createAggregationExpression()->lte('$accessLevel', 3), '$$KEEP', '$$REDACT' ); @@ -33,7 +33,7 @@ public function testRedactFromBuilder(): void $builder ->redact() ->cond( - $builder->expr()->lte('$accessLevel', 3), + $builder->createAggregationExpression()->lte('$accessLevel', 3), '$$KEEP', '$$REDACT' ); diff --git a/tests/Doctrine/ODM/MongoDB/Tests/Aggregation/Stage/ReplaceRootTest.php b/tests/Doctrine/ODM/MongoDB/Tests/Aggregation/Stage/ReplaceRootTest.php index 84cd7884ea..aad032e638 100644 --- a/tests/Doctrine/ODM/MongoDB/Tests/Aggregation/Stage/ReplaceRootTest.php +++ b/tests/Doctrine/ODM/MongoDB/Tests/Aggregation/Stage/ReplaceRootTest.php @@ -43,7 +43,7 @@ public function testTypeConversionWithDirectExpression(): void $mongoDate = new UTCDateTime((int) $dateTime->format('Uv')); $stage = $builder ->replaceRoot( - $builder->expr() + $builder->createAggregationExpression() ->field('isToday') ->eq('$createdAt', $dateTime) ); diff --git a/tests/Doctrine/ODM/MongoDB/Tests/Functional/QueryTest.php b/tests/Doctrine/ODM/MongoDB/Tests/Functional/QueryTest.php index a5132850e1..c66e763cea 100644 --- a/tests/Doctrine/ODM/MongoDB/Tests/Functional/QueryTest.php +++ b/tests/Doctrine/ODM/MongoDB/Tests/Functional/QueryTest.php @@ -53,7 +53,7 @@ public function testAddElemMatch(): void $qb = $this->dm->createQueryBuilder(User::class); $embeddedQb = $this->dm->createQueryBuilder(Phonenumber::class); - $qb->field('phonenumbers')->elemMatch($embeddedQb->expr()->field('phonenumber')->equals('6155139185')); + $qb->field('phonenumbers')->elemMatch($embeddedQb->createQueryExpression()->field('phonenumber')->equals('6155139185')); $query = $qb->getQuery(); $user = $query->getSingleResult(); self::assertNotNull($user); @@ -76,7 +76,8 @@ public function testAddElemMatchWithDeepFields(): void $qb = $this->dm->createQueryBuilder(User::class); $embeddedQb = $this->dm->createQueryBuilder(Phonenumber::class); - $qb->field('phonenumbers')->elemMatch($embeddedQb->expr()->field('lastCalledBy.$id')->equals(new ObjectId($user1->getId()))); + $qb->field('phonenumbers')->elemMatch($embeddedQb->createQueryExpression()->field('lastCalledBy.$id')->equals(new ObjectId + ($user1->getId()))); $query = $qb->getQuery(); $user = $query->getSingleResult(); self::assertNotNull($user); @@ -91,12 +92,12 @@ public function testAddNot(): void $this->dm->flush(); $qb = $this->dm->createQueryBuilder(User::class); - $qb->field('username')->not($qb->expr()->in(['boo'])); + $qb->field('username')->not($qb->createQueryExpression()->in(['boo'])); $query = $qb->getQuery(); $user = $query->getSingleResult(); self::assertNull($user); - $qb->field('username')->not($qb->expr()->in(['1boo'])); + $qb->field('username')->not($qb->createQueryExpression()->in(['1boo'])); $query = $qb->getQuery(); $user = $query->getSingleResult(); self::assertNotNull($user); diff --git a/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/GH1674Test.php b/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/GH1674Test.php index 9bf8e0ab93..4c1a2f3e5b 100644 --- a/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/GH1674Test.php +++ b/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/GH1674Test.php @@ -18,7 +18,7 @@ public function testElemMatchUsesCorrectMapping(): void $builder ->field('embedded') ->elemMatch( - $builder->expr() + $builder->createQueryExpression() ->field('id') ->equals(1) ); diff --git a/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/GH2251Test.php b/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/GH2251Test.php index ac2cc32d9a..eb5512888b 100644 --- a/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/GH2251Test.php +++ b/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/GH2251Test.php @@ -23,8 +23,8 @@ public function testElemMatchQuery(string $fieldName): void new ObjectId('5fae9a775ef4492e3c72b3f4'), ]; - $notIn = $builder->expr()->notIn($objectIds); - $elemMatch = $builder->expr() + $notIn = $builder->createQueryExpression()->notIn($objectIds); + $elemMatch = $builder->createQueryExpression() ->field($fieldName) ->elemMatch($notIn); diff --git a/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/GH596Test.php b/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/GH596Test.php index 5350aea919..bbf34bb157 100644 --- a/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/GH596Test.php +++ b/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/GH596Test.php @@ -26,8 +26,8 @@ public function testExpressionPreparationDoesNotInjectFilterCriteria(): void $repository = $this->dm->getRepository($class); $qb = $repository->createQueryBuilder(); - $qb->addOr($qb->expr()->field('name')->equals('foo')); - $qb->addOr($qb->expr()->field('name')->equals('bar')); + $qb->addOr($qb->createQueryExpression()->field('name')->equals('foo')); + $qb->addOr($qb->createQueryExpression()->field('name')->equals('bar')); $query = $qb->getQuery(); $query = $query->getQuery(); diff --git a/tests/Doctrine/ODM/MongoDB/Tests/Query/BuilderTest.php b/tests/Doctrine/ODM/MongoDB/Tests/Query/BuilderTest.php index 4e6ac2ef4b..e817229495 100644 --- a/tests/Doctrine/ODM/MongoDB/Tests/Query/BuilderTest.php +++ b/tests/Doctrine/ODM/MongoDB/Tests/Query/BuilderTest.php @@ -242,8 +242,8 @@ public function provideArrayUpdateOperatorsOnReferenceOne(): Generator public function testThatOrAcceptsAnotherQuery(): void { $qb = $this->getTestQueryBuilder(); - $qb->addOr($qb->expr()->field('firstName')->equals('Kris')); - $qb->addOr($qb->expr()->field('firstName')->equals('Chris')); + $qb->addOr($qb->createQueryExpression()->field('firstName')->equals('Kris')); + $qb->addOr($qb->createQueryExpression()->field('firstName')->equals('Chris')); self::assertEquals([ '$or' => [ @@ -256,8 +256,8 @@ public function testThatOrAcceptsAnotherQuery(): void public function testThatAndAcceptsAnotherQuery(): void { $qb = $this->getTestQueryBuilder(); - $qb->addAnd($qb->expr()->field('hits')->gte(1)); - $qb->addAnd($qb->expr()->field('hits')->lt(5)); + $qb->addAnd($qb->createQueryExpression()->field('hits')->gte(1)); + $qb->addAnd($qb->createQueryExpression()->field('hits')->lt(5)); self::assertEquals([ '$and' => [ @@ -270,8 +270,8 @@ public function testThatAndAcceptsAnotherQuery(): void public function testThatNorAcceptsAnotherQuery(): void { $qb = $this->getTestQueryBuilder(); - $qb->addNor($qb->expr()->field('firstName')->equals('Kris')); - $qb->addNor($qb->expr()->field('firstName')->equals('Chris')); + $qb->addNor($qb->createQueryExpression()->field('firstName')->equals('Kris')); + $qb->addNor($qb->createQueryExpression()->field('firstName')->equals('Chris')); self::assertEquals([ '$nor' => [ @@ -284,7 +284,7 @@ public function testThatNorAcceptsAnotherQuery(): void public function testAddElemMatch(): void { $qb = $this->getTestQueryBuilder(); - $qb->field('phonenumbers')->elemMatch($qb->expr()->field('phonenumber')->equals('6155139185')); + $qb->field('phonenumbers')->elemMatch($qb->createQueryExpression()->field('phonenumber')->equals('6155139185')); $expected = [ 'phonenumbers' => [ '$elemMatch' => ['phonenumber' => '6155139185'], @@ -296,7 +296,7 @@ public function testAddElemMatch(): void public function testAddNot(): void { $qb = $this->getTestQueryBuilder(); - $qb->field('username')->not($qb->expr()->in(['boo'])); + $qb->field('username')->not($qb->createQueryExpression()->in(['boo'])); $expected = [ 'username' => [ '$not' => [ @@ -662,7 +662,7 @@ public function testSelectElemMatchWithArray(): void public function testSelectElemMatchWithExpr(): void { $qb = $this->getTestQueryBuilder(); - $qb->selectElemMatch('addresses', $qb->expr()->field('state')->equals('ny')); + $qb->selectElemMatch('addresses', $qb->createQueryExpression()->field('state')->equals('ny')); $expected = ['addresses' => ['$elemMatch' => ['state' => 'ny']]]; diff --git a/tests/Doctrine/ODM/MongoDB/Tests/Query/ExprTest.php b/tests/Doctrine/ODM/MongoDB/Tests/Query/ExprTest.php index 661763d831..cc1da7834a 100644 --- a/tests/Doctrine/ODM/MongoDB/Tests/Query/ExprTest.php +++ b/tests/Doctrine/ODM/MongoDB/Tests/Query/ExprTest.php @@ -87,7 +87,7 @@ public function testAndIsPrepared(): void $qb = $this->dm->createQueryBuilder(User::class); $qb - ->addAnd($qb->expr()->field('groups.id')->in($ids)) + ->addAnd($qb->createQueryExpression()->field('groups.id')->in($ids)) ->select('id')->hydrate(false); $query = $qb->getQuery(); $debug = $query->debug('query'); @@ -102,7 +102,7 @@ public function testOrIsPrepared(): void $qb = $this->dm->createQueryBuilder(User::class); $qb - ->addOr($qb->expr()->field('groups.id')->in($ids)) + ->addOr($qb->createQueryExpression()->field('groups.id')->in($ids)) ->select('id')->hydrate(false); $query = $qb->getQuery(); $debug = $query->debug('query'); diff --git a/tests/Doctrine/ODM/MongoDB/Tests/QueryTest.php b/tests/Doctrine/ODM/MongoDB/Tests/QueryTest.php index abed16a68c..e1d58dbe19 100644 --- a/tests/Doctrine/ODM/MongoDB/Tests/QueryTest.php +++ b/tests/Doctrine/ODM/MongoDB/Tests/QueryTest.php @@ -59,8 +59,8 @@ public function testThatOrAcceptsAnotherQuery(): void $expression2 = ['firstName' => 'Chris']; $qb = $this->dm->createQueryBuilder($class); - $qb->addOr($qb->expr()->field('firstName')->equals('Kris')); - $qb->addOr($qb->expr()->field('firstName')->equals('Chris')); + $qb->addOr($qb->createQueryExpression()->field('firstName')->equals('Kris')); + $qb->addOr($qb->createQueryExpression()->field('firstName')->equals('Chris')); self::assertEquals([ '$or' => [ @@ -283,7 +283,7 @@ public function testElemMatch(): void $qb = $this->dm->createQueryBuilder(User::class); $embeddedQb = $this->dm->createQueryBuilder(Phonenumber::class); - $qb->field('phonenumbers')->elemMatch($embeddedQb->expr() + $qb->field('phonenumbers')->elemMatch($embeddedQb->createQueryExpression() ->field('lastCalledBy.id')->equals($refId)); $query = $qb->getQuery();