|
11 | 11 |
|
12 | 12 | namespace EventEngine\DocumentStoreTest\Postgres;
|
13 | 13 |
|
| 14 | +use EventEngine\DocumentStore\Filter\AndFilter; |
14 | 15 | use EventEngine\DocumentStore\Filter\AnyOfDocIdFilter;
|
15 | 16 | use EventEngine\DocumentStore\Filter\AnyOfFilter;
|
16 | 17 | use EventEngine\DocumentStore\Filter\DocIdFilter;
|
| 18 | +use EventEngine\DocumentStore\Filter\EqFilter; |
17 | 19 | use EventEngine\DocumentStore\Filter\InArrayFilter;
|
18 | 20 | use EventEngine\DocumentStore\Filter\NotFilter;
|
19 | 21 | use PHPUnit\Framework\TestCase;
|
|
22 | 24 | use EventEngine\DocumentStore\MultiFieldIndex;
|
23 | 25 | use EventEngine\DocumentStore\Postgres\PostgresDocumentStore;
|
24 | 26 | use Ramsey\Uuid\Uuid;
|
| 27 | +use function array_map; |
25 | 28 |
|
26 | 29 | class PostgresDocumentStoreTest extends TestCase
|
27 | 30 | {
|
@@ -396,6 +399,41 @@ public function it_handles_in_array_filter_with_object_items()
|
396 | 399 | $this->assertEquals([$secondDocId, $thirdDocId], $refs);
|
397 | 400 | }
|
398 | 401 |
|
| 402 | + /** |
| 403 | + * @test |
| 404 | + */ |
| 405 | + public function it_handles_not_filter_nested_in_and_filter() |
| 406 | + { |
| 407 | + $collectionName = 'test_not_filter_nested_in_and_filter'; |
| 408 | + $this->documentStore->addCollection($collectionName); |
| 409 | + |
| 410 | + $firstDocId = Uuid::uuid4()->toString(); |
| 411 | + $secondDocId = Uuid::uuid4()->toString(); |
| 412 | + $thirdDocId = Uuid::uuid4()->toString(); |
| 413 | + |
| 414 | + $this->documentStore->addDoc($collectionName, $firstDocId, ['foo' => ['bar' => 'bas'], 'ref' => $firstDocId]); |
| 415 | + $this->documentStore->addDoc($collectionName, $secondDocId, ['foo' => ['bar' => 'bat'], 'ref' => $secondDocId]); |
| 416 | + $this->documentStore->addDoc($collectionName, $thirdDocId, ['foo' => ['bar' => 'bat'], 'ref' => $thirdDocId]); |
| 417 | + |
| 418 | + $filteredDocs = \iterator_to_array($this->documentStore->filterDocs( |
| 419 | + $collectionName, |
| 420 | + new AndFilter( |
| 421 | + new EqFilter('foo.bar', 'bat'), |
| 422 | + new NotFilter( |
| 423 | + new EqFilter('ref', $secondDocId) |
| 424 | + ) |
| 425 | + ) |
| 426 | + )); |
| 427 | + |
| 428 | + $this->assertCount(1, $filteredDocs); |
| 429 | + |
| 430 | + $refs = array_map(function (array $doc) { |
| 431 | + return $doc['ref']; |
| 432 | + }, $filteredDocs); |
| 433 | + |
| 434 | + $this->assertEquals([$thirdDocId], $refs); |
| 435 | + } |
| 436 | + |
399 | 437 | private function getIndexes(string $collectionName): array
|
400 | 438 | {
|
401 | 439 | return TestUtil::getIndexes($this->connection, self::TABLE_PREFIX.$collectionName);
|
|
0 commit comments