-
-
Notifications
You must be signed in to change notification settings - Fork 505
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix preparation of $elemMatch operators in queries
- Loading branch information
Showing
3 changed files
with
62 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/GH2251Test.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Doctrine\ODM\MongoDB\Tests\Functional\Ticket; | ||
|
||
use Doctrine\ODM\MongoDB\Tests\BaseTest; | ||
use Documents\User; | ||
use MongoDB\BSON\ObjectId; | ||
|
||
class GH2251Test extends BaseTest | ||
{ | ||
/** | ||
* @testWith ["groups"] | ||
* ["groupsSimple"] | ||
*/ | ||
public function testElemMatchQuery(string $fieldName) | ||
{ | ||
$builder = $this->dm->createQueryBuilder(User::class); | ||
|
||
$objectIds = [ | ||
new ObjectId('5fae9a775ef4492e3c72b3f3'), | ||
new ObjectId('5fae9a775ef4492e3c72b3f4'), | ||
]; | ||
|
||
$notIn = $builder->expr()->notIn($objectIds); | ||
$elemMatch = $builder->expr() | ||
->field($fieldName) | ||
->elemMatch($notIn); | ||
|
||
$builder->addNor( | ||
$elemMatch | ||
); | ||
|
||
$this->assertSame( | ||
[ | ||
'$nor' => [ | ||
[ | ||
$fieldName => [ | ||
'$elemMatch' => ['$nin' => $objectIds], | ||
], | ||
], | ||
], | ||
], | ||
$builder->getQueryArray() | ||
); | ||
} | ||
} |