diff --git a/phpunit.xml b/phpunit.xml index 8ba994793..7469c5341 100755 --- a/phpunit.xml +++ b/phpunit.xml @@ -7,7 +7,7 @@ convertNoticesToExceptions="true" convertWarningsToExceptions="true" processIsolation="false" - stopOnFailure="false"> + stopOnFailure="true"> ./tests/unit diff --git a/src/Database/Database.php b/src/Database/Database.php index 0c7dfbb41..224a08f45 100644 --- a/src/Database/Database.php +++ b/src/Database/Database.php @@ -334,6 +334,8 @@ class Database protected ?\DateTime $timestamp = null; + protected ?Document $cursor = null; + protected bool $resolveRelationships = true; protected bool $checkRelationshipsExist = true; @@ -614,6 +616,26 @@ public function withRequestTimestamp(?\DateTime $requestTimestamp, callable $cal return $result; } + /** + * Executes $callback with $cursor Document + * + * @template T + * @param callable(): T $callback + * @return T + */ + public function withCursor(?Document $cursor, callable $callback): mixed + { + $previous = $this->cursor; + $this->cursor = $cursor; + + try { + $result = $callback(); + } finally { + $this->cursor = $previous; + } + return $result; + } + /** * Set Namespace. * @@ -4358,10 +4380,6 @@ public function updateDocuments( $limit = $grouped['limit']; $cursor = $grouped['cursor']; - if (!empty($cursor) && $cursor->getCollection() !== $collection->getId()) { - throw new DatabaseException("cursor Document must be from the same Collection."); - } - unset($updates['$id']); unset($updates['$createdAt']); unset($updates['$tenant']); @@ -4403,7 +4421,7 @@ public function updateDocuments( ]; if (!empty($last)) { - $new[] = Query::cursorAfter($last); + $new[] = Query::cursorAfter($last->getId()); } $batch = $this->silent(fn () => $this->find( @@ -5755,13 +5773,8 @@ public function deleteDocuments( $grouped = Query::groupByType($queries); $limit = $grouped['limit']; $cursor = $grouped['cursor']; - - if (!empty($cursor) && $cursor->getCollection() !== $collection->getId()) { - throw new DatabaseException("Cursor document must be from the same Collection."); - } - $originalLimit = $limit; - $last = $cursor; + $last = null; $modified = 0; while (true) { @@ -5775,17 +5788,21 @@ public function deleteDocuments( Query::limit($batchSize) ]; - if (!empty($last)) { - $new[] = Query::cursorAfter($last); + if (!empty($cursor)) { + $new[] = Query::cursorAfter($cursor); } /** * @var array $batch */ - $batch = $this->silent(fn () => $this->find( - $collection->getId(), - array_merge($new, $queries), - forPermission: Database::PERMISSION_DELETE + + $batch = $this->silent(fn () => $this->withCursor( + $last, + fn () => $this->find( + $collection->getId(), + array_merge($new, $queries), + forPermission: Database::PERMISSION_DELETE + ) )); if (empty($batch)) { @@ -5795,7 +5812,16 @@ public function deleteDocuments( $internalIds = []; $permissionIds = []; foreach ($batch as $document) { + if (empty($document->getInternalId())){ + throw new QueryException('$internalId must not be empty'); + } + $internalIds[] = $document->getInternalId(); + + if (!isset($document['$permissions'])) { + throw new QueryException('$permissions key is missing'); + } + if (!empty($document->getPermissions())) { $permissionIds[] = $document->getId(); } @@ -5808,6 +5834,10 @@ public function deleteDocuments( } // Check if document was updated after the request timestamp + if (empty($document->getUpdatedAt())){ + throw new QueryException('$updatedAt must not be empty'); + } + try { $oldUpdatedAt = new \DateTime($document->getUpdatedAt()); } catch (Exception $e) { @@ -5819,6 +5849,16 @@ public function deleteDocuments( } } + $last = $batch[array_key_last($batch)]; + $cursor = $last->getId(); + /** + * Since we delete data, no cursor will be found later on so we need to assign a payload + * Independent Cursor data regardless to find selects queries + * todo: add specific selects... (order by , $id, $internalId)) + * Do we need silent here? + */ + $last = $this->silent(fn () => $this->getDocument($collection->getId(), $cursor)); + $this->withTransaction(function () use ($collection, $internalIds, $permissionIds) { $this->adapter->deleteDocuments( $collection->getId(), @@ -5845,8 +5885,6 @@ public function deleteDocuments( } elseif ($originalLimit && $modified >= $originalLimit) { break; } - - $last = \end($batch); } $this->trigger(self::EVENT_DOCUMENTS_DELETE, new Document([ @@ -5960,14 +5998,26 @@ public function find(string $collection, array $queries = [], string $forPermiss $offset = $grouped['offset']; $orderAttributes = $grouped['orderAttributes']; $orderTypes = $grouped['orderTypes']; - $cursor = $grouped['cursor']; + $cursorId = $grouped['cursor']; + $cursor = []; $cursorDirection = $grouped['cursorDirection']; - if (!empty($cursor) && $cursor->getCollection() !== $collection->getId()) { - throw new DatabaseException("cursor Document must be from the same Collection."); - } + if (!empty($cursorId)) { + if (!is_null($this->cursor) && !$this->cursor->isEmpty()) { + $cursor = $this->cursor; + } else { + /** + * todo: add specific select queries, Only what you need for the cursor + */ + $cursor = $this->getDocument($collection->getId(), $cursorId); + } - $cursor = empty($cursor) ? [] : $this->encode($collection, $cursor)->getArrayCopy(); + if ($cursor->isEmpty()) { + throw new DatabaseException("Cursor not found"); + } + + $cursor = $this->encode($collection, $cursor)->getArrayCopy(); + } /** @var array $queries */ $queries = \array_merge( @@ -6105,7 +6155,7 @@ public function foreach(string $collection, callable $callback, array $queries = array_unshift($newQueries, Query::offset(0)); } - array_unshift($newQueries, Query::cursorAfter($latestDocument)); + array_unshift($newQueries, Query::cursorAfter($latestDocument->getId())); } if (!$limitExists) { $newQueries[] = Query::limit($limit); diff --git a/src/Database/Query.php b/src/Database/Query.php index 745227401..bf1c3d607 100644 --- a/src/Database/Query.php +++ b/src/Database/Query.php @@ -512,10 +512,10 @@ public static function offset(int $value): self /** * Helper method to create Query with cursorAfter method * - * @param Document $value + * @param string $value * @return Query */ - public static function cursorAfter(Document $value): self + public static function cursorAfter(string $value): self { return new self(self::TYPE_CURSOR_AFTER, values: [$value]); } @@ -523,10 +523,10 @@ public static function cursorAfter(Document $value): self /** * Helper method to create Query with cursorBefore method * - * @param Document $value + * @param string $value * @return Query */ - public static function cursorBefore(Document $value): self + public static function cursorBefore(string $value): self { return new self(self::TYPE_CURSOR_BEFORE, values: [$value]); } diff --git a/src/Database/Validator/Query/Cursor.php b/src/Database/Validator/Query/Cursor.php index 46020d7b4..197c192b7 100644 --- a/src/Database/Validator/Query/Cursor.php +++ b/src/Database/Validator/Query/Cursor.php @@ -29,9 +29,9 @@ public function isValid($value): bool if ($method === Query::TYPE_CURSOR_AFTER || $method === Query::TYPE_CURSOR_BEFORE) { $cursor = $value->getValue(); - if ($cursor instanceof Document) { - $cursor = $cursor->getId(); - } + // if ($cursor instanceof Document) { + // $cursor = $cursor->getId(); + // } $validator = new UID(); if ($validator->isValid($cursor)) { diff --git a/tests/e2e/Adapter/Scopes/DocumentTests.php b/tests/e2e/Adapter/Scopes/DocumentTests.php index 35ab3d191..426a6b7ed 100644 --- a/tests/e2e/Adapter/Scopes/DocumentTests.php +++ b/tests/e2e/Adapter/Scopes/DocumentTests.php @@ -1550,7 +1550,7 @@ public function testFindOrderByCursorAfter(): void $documents = static::getDatabase()->find('movies', [ Query::limit(2), Query::offset(0), - Query::cursorAfter($movies[1]) + Query::cursorAfter($movies[1]->getId()) ]); $this->assertEquals(2, count($documents)); $this->assertEquals($movies[2]['name'], $documents[0]['name']); @@ -1559,7 +1559,7 @@ public function testFindOrderByCursorAfter(): void $documents = static::getDatabase()->find('movies', [ Query::limit(2), Query::offset(0), - Query::cursorAfter($movies[3]) + Query::cursorAfter($movies[3]->getId()) ]); $this->assertEquals(2, count($documents)); $this->assertEquals($movies[4]['name'], $documents[0]['name']); @@ -1568,7 +1568,7 @@ public function testFindOrderByCursorAfter(): void $documents = static::getDatabase()->find('movies', [ Query::limit(2), Query::offset(0), - Query::cursorAfter($movies[4]) + Query::cursorAfter($movies[4]->getId()) ]); $this->assertEquals(1, count($documents)); $this->assertEquals($movies[5]['name'], $documents[0]['name']); @@ -1576,7 +1576,7 @@ public function testFindOrderByCursorAfter(): void $documents = static::getDatabase()->find('movies', [ Query::limit(2), Query::offset(0), - Query::cursorAfter($movies[5]) + Query::cursorAfter($movies[5]->getId()) ]); $this->assertEmpty(count($documents)); } @@ -1595,7 +1595,7 @@ public function testFindOrderByCursorBefore(): void $documents = static::getDatabase()->find('movies', [ Query::limit(2), Query::offset(0), - Query::cursorBefore($movies[5]) + Query::cursorBefore($movies[5]->getId()) ]); $this->assertEquals(2, count($documents)); $this->assertEquals($movies[3]['name'], $documents[0]['name']); @@ -1604,7 +1604,7 @@ public function testFindOrderByCursorBefore(): void $documents = static::getDatabase()->find('movies', [ Query::limit(2), Query::offset(0), - Query::cursorBefore($movies[3]) + Query::cursorBefore($movies[3]->getId()) ]); $this->assertEquals(2, count($documents)); $this->assertEquals($movies[1]['name'], $documents[0]['name']); @@ -1613,7 +1613,7 @@ public function testFindOrderByCursorBefore(): void $documents = static::getDatabase()->find('movies', [ Query::limit(2), Query::offset(0), - Query::cursorBefore($movies[2]) + Query::cursorBefore($movies[2]->getId()) ]); $this->assertEquals(2, count($documents)); $this->assertEquals($movies[0]['name'], $documents[0]['name']); @@ -1622,7 +1622,7 @@ public function testFindOrderByCursorBefore(): void $documents = static::getDatabase()->find('movies', [ Query::limit(2), Query::offset(0), - Query::cursorBefore($movies[1]) + Query::cursorBefore($movies[1]->getId()) ]); $this->assertEquals(1, count($documents)); $this->assertEquals($movies[0]['name'], $documents[0]['name']); @@ -1630,7 +1630,7 @@ public function testFindOrderByCursorBefore(): void $documents = static::getDatabase()->find('movies', [ Query::limit(2), Query::offset(0), - Query::cursorBefore($movies[0]) + Query::cursorBefore($movies[0]->getId()) ]); $this->assertEmpty(count($documents)); } @@ -1649,7 +1649,7 @@ public function testFindOrderByAfterNaturalOrder(): void Query::limit(2), Query::offset(0), Query::orderDesc(''), - Query::cursorAfter($movies[1]) + Query::cursorAfter($movies[1]->getId()) ]); $this->assertEquals(2, count($documents)); $this->assertEquals($movies[2]['name'], $documents[0]['name']); @@ -1659,7 +1659,7 @@ public function testFindOrderByAfterNaturalOrder(): void Query::limit(2), Query::offset(0), Query::orderDesc(''), - Query::cursorAfter($movies[3]) + Query::cursorAfter($movies[3]->getId()) ]); $this->assertEquals(2, count($documents)); $this->assertEquals($movies[4]['name'], $documents[0]['name']); @@ -1669,7 +1669,7 @@ public function testFindOrderByAfterNaturalOrder(): void Query::limit(2), Query::offset(0), Query::orderDesc(''), - Query::cursorAfter($movies[4]) + Query::cursorAfter($movies[4]->getId()) ]); $this->assertEquals(1, count($documents)); $this->assertEquals($movies[5]['name'], $documents[0]['name']); @@ -1678,7 +1678,7 @@ public function testFindOrderByAfterNaturalOrder(): void Query::limit(2), Query::offset(0), Query::orderDesc(''), - Query::cursorAfter($movies[5]) + Query::cursorAfter($movies[5]->getId()) ]); $this->assertEmpty(count($documents)); } @@ -1697,7 +1697,7 @@ public function testFindOrderByBeforeNaturalOrder(): void Query::limit(2), Query::offset(0), Query::orderDesc(''), - Query::cursorBefore($movies[5]) + Query::cursorBefore($movies[5]->getId()) ]); $this->assertEquals(2, count($documents)); $this->assertEquals($movies[3]['name'], $documents[0]['name']); @@ -1707,7 +1707,7 @@ public function testFindOrderByBeforeNaturalOrder(): void Query::limit(2), Query::offset(0), Query::orderDesc(''), - Query::cursorBefore($movies[3]) + Query::cursorBefore($movies[3]->getId()) ]); $this->assertEquals(2, count($documents)); $this->assertEquals($movies[1]['name'], $documents[0]['name']); @@ -1717,7 +1717,7 @@ public function testFindOrderByBeforeNaturalOrder(): void Query::limit(2), Query::offset(0), Query::orderDesc(''), - Query::cursorBefore($movies[2]) + Query::cursorBefore($movies[2]->getId()) ]); $this->assertEquals(2, count($documents)); $this->assertEquals($movies[0]['name'], $documents[0]['name']); @@ -1727,7 +1727,7 @@ public function testFindOrderByBeforeNaturalOrder(): void Query::limit(2), Query::offset(0), Query::orderDesc(''), - Query::cursorBefore($movies[1]) + Query::cursorBefore($movies[1]->getId()) ]); $this->assertEquals(1, count($documents)); $this->assertEquals($movies[0]['name'], $documents[0]['name']); @@ -1736,7 +1736,7 @@ public function testFindOrderByBeforeNaturalOrder(): void Query::limit(2), Query::offset(0), Query::orderDesc(''), - Query::cursorBefore($movies[0]) + Query::cursorBefore($movies[0]->getId()) ]); $this->assertEmpty(count($documents)); } @@ -1756,7 +1756,7 @@ public function testFindOrderBySingleAttributeAfter(): void Query::limit(2), Query::offset(0), Query::orderDesc('year'), - Query::cursorAfter($movies[1]) + Query::cursorAfter($movies[1]->getId()) ]); $this->assertEquals(2, count($documents)); @@ -1767,7 +1767,7 @@ public function testFindOrderBySingleAttributeAfter(): void Query::limit(2), Query::offset(0), Query::orderDesc('year'), - Query::cursorAfter($movies[3]) + Query::cursorAfter($movies[3]->getId()) ]); $this->assertEquals(2, count($documents)); $this->assertEquals($movies[4]['name'], $documents[0]['name']); @@ -1777,7 +1777,7 @@ public function testFindOrderBySingleAttributeAfter(): void Query::limit(2), Query::offset(0), Query::orderDesc('year'), - Query::cursorAfter($movies[4]) + Query::cursorAfter($movies[4]->getId()) ]); $this->assertEquals(1, count($documents)); $this->assertEquals($movies[5]['name'], $documents[0]['name']); @@ -1786,7 +1786,7 @@ public function testFindOrderBySingleAttributeAfter(): void Query::limit(2), Query::offset(0), Query::orderDesc('year'), - Query::cursorAfter($movies[5]) + Query::cursorAfter($movies[5]->getId()) ]); $this->assertEmpty(count($documents)); } @@ -1807,7 +1807,7 @@ public function testFindOrderBySingleAttributeBefore(): void Query::limit(2), Query::offset(0), Query::orderDesc('year'), - Query::cursorBefore($movies[5]) + Query::cursorBefore($movies[5]->getId()) ]); $this->assertEquals(2, count($documents)); $this->assertEquals($movies[3]['name'], $documents[0]['name']); @@ -1817,7 +1817,7 @@ public function testFindOrderBySingleAttributeBefore(): void Query::limit(2), Query::offset(0), Query::orderDesc('year'), - Query::cursorBefore($movies[3]) + Query::cursorBefore($movies[3]->getId()) ]); $this->assertEquals(2, count($documents)); $this->assertEquals($movies[1]['name'], $documents[0]['name']); @@ -1827,7 +1827,7 @@ public function testFindOrderBySingleAttributeBefore(): void Query::limit(2), Query::offset(0), Query::orderDesc('year'), - Query::cursorBefore($movies[2]) + Query::cursorBefore($movies[2]->getId()) ]); $this->assertEquals(2, count($documents)); $this->assertEquals($movies[0]['name'], $documents[0]['name']); @@ -1837,7 +1837,7 @@ public function testFindOrderBySingleAttributeBefore(): void Query::limit(2), Query::offset(0), Query::orderDesc('year'), - Query::cursorBefore($movies[1]) + Query::cursorBefore($movies[1]->getId()) ]); $this->assertEquals(1, count($documents)); $this->assertEquals($movies[0]['name'], $documents[0]['name']); @@ -1846,7 +1846,7 @@ public function testFindOrderBySingleAttributeBefore(): void Query::limit(2), Query::offset(0), Query::orderDesc('year'), - Query::cursorBefore($movies[0]) + Query::cursorBefore($movies[0]->getId()) ]); $this->assertEmpty(count($documents)); } @@ -1868,7 +1868,7 @@ public function testFindOrderByMultipleAttributeAfter(): void Query::offset(0), Query::orderDesc('price'), Query::orderAsc('year'), - Query::cursorAfter($movies[1]) + Query::cursorAfter($movies[1]->getId()) ]); $this->assertEquals(2, count($documents)); $this->assertEquals($movies[2]['name'], $documents[0]['name']); @@ -1879,7 +1879,7 @@ public function testFindOrderByMultipleAttributeAfter(): void Query::offset(0), Query::orderDesc('price'), Query::orderAsc('year'), - Query::cursorAfter($movies[3]) + Query::cursorAfter($movies[3]->getId()) ]); $this->assertEquals(2, count($documents)); $this->assertEquals($movies[4]['name'], $documents[0]['name']); @@ -1890,7 +1890,7 @@ public function testFindOrderByMultipleAttributeAfter(): void Query::offset(0), Query::orderDesc('price'), Query::orderAsc('year'), - Query::cursorAfter($movies[4]) + Query::cursorAfter($movies[4]->getId()) ]); $this->assertEquals(1, count($documents)); $this->assertEquals($movies[5]['name'], $documents[0]['name']); @@ -1900,7 +1900,7 @@ public function testFindOrderByMultipleAttributeAfter(): void Query::offset(0), Query::orderDesc('price'), Query::orderAsc('year'), - Query::cursorAfter($movies[5]) + Query::cursorAfter($movies[5]->getId()) ]); $this->assertEmpty(count($documents)); } @@ -1922,7 +1922,7 @@ public function testFindOrderByMultipleAttributeBefore(): void Query::offset(0), Query::orderDesc('price'), Query::orderAsc('year'), - Query::cursorBefore($movies[5]) + Query::cursorBefore($movies[5]->getId()) ]); $this->assertEquals(2, count($documents)); @@ -1934,7 +1934,7 @@ public function testFindOrderByMultipleAttributeBefore(): void Query::offset(0), Query::orderDesc('price'), Query::orderAsc('year'), - Query::cursorBefore($movies[4]) + Query::cursorBefore($movies[4]->getId()) ]); $this->assertEquals(2, count($documents)); $this->assertEquals($movies[2]['name'], $documents[0]['name']); @@ -1945,7 +1945,7 @@ public function testFindOrderByMultipleAttributeBefore(): void Query::offset(0), Query::orderDesc('price'), Query::orderAsc('year'), - Query::cursorBefore($movies[2]) + Query::cursorBefore($movies[2]->getId()) ]); $this->assertEquals(2, count($documents)); $this->assertEquals($movies[0]['name'], $documents[0]['name']); @@ -1956,7 +1956,7 @@ public function testFindOrderByMultipleAttributeBefore(): void Query::offset(0), Query::orderDesc('price'), Query::orderAsc('year'), - Query::cursorBefore($movies[1]) + Query::cursorBefore($movies[1]->getId()) ]); $this->assertEquals(1, count($documents)); $this->assertEquals($movies[0]['name'], $documents[0]['name']); @@ -1966,7 +1966,7 @@ public function testFindOrderByMultipleAttributeBefore(): void Query::offset(0), Query::orderDesc('price'), Query::orderAsc('year'), - Query::cursorBefore($movies[0]) + Query::cursorBefore($movies[0]->getId()) ]); $this->assertEmpty(count($documents)); } @@ -1984,7 +1984,7 @@ public function testFindOrderByAndCursor(): void Query::limit(1), Query::offset(0), Query::orderDesc('price'), - Query::cursorAfter($documentsTest[0]) + Query::cursorAfter($documentsTest[0]->getId()) ]); $this->assertEquals($documentsTest[1]['$id'], $documents[0]['$id']); @@ -2003,7 +2003,7 @@ public function testFindOrderByIdAndCursor(): void Query::limit(1), Query::offset(0), Query::orderDesc('$id'), - Query::cursorAfter($documentsTest[0]) + Query::cursorAfter($documentsTest[0]->getId()) ]); $this->assertEquals($documentsTest[1]['$id'], $documents[0]['$id']); @@ -2024,7 +2024,7 @@ public function testFindOrderByCreateDateAndCursor(): void Query::limit(1), Query::offset(0), Query::orderDesc('$createdAt'), - Query::cursorAfter($documentsTest[0]) + Query::cursorAfter($documentsTest[0]->getId()) ]); $this->assertEquals($documentsTest[1]['$id'], $documents[0]['$id']); @@ -2044,7 +2044,7 @@ public function testFindOrderByUpdateDateAndCursor(): void Query::limit(1), Query::offset(0), Query::orderDesc('$updatedAt'), - Query::cursorAfter($documentsTest[0]) + Query::cursorAfter($documentsTest[0]->getId()) ]); $this->assertEquals($documentsTest[1]['$id'], $documents[0]['$id']); @@ -2535,7 +2535,7 @@ public function testForeach(): void $first = $documents[0]; $documents = []; - static::getDatabase()->foreach('movies', queries: [Query::limit(2), Query::cursorAfter($first)], callback: function ($document) use (&$documents) { + static::getDatabase()->foreach('movies', queries: [Query::limit(2), Query::cursorAfter($first->getId())], callback: function ($document) use (&$documents) { $documents[] = $document; }); $this->assertEquals(5, count($documents)); @@ -2554,7 +2554,7 @@ public function testForeach(): void * Test, cursor before throws error */ try { - static::getDatabase()->foreach('movies', queries: [Query::cursorBefore($documents[0]), Query::offset(2)], callback: function ($document) use (&$documents) { + static::getDatabase()->foreach('movies', queries: [Query::cursorBefore($documents[0]->getId()), Query::offset(2)], callback: function ($document) use (&$documents) { $documents[] = $document; }); @@ -3467,7 +3467,7 @@ public function testDeleteBulkDocuments(): void collection: 'bulk_delete', queries: [ Query::select([...$selects, '$createdAt']), - Query::cursorAfter($docs[6]), + Query::cursorAfter($docs[6]->getId()), Query::greaterThan('$createdAt', '2000-01-01'), Query::orderAsc('$createdAt'), Query::orderAsc(), diff --git a/tests/e2e/Adapter/Scopes/GeneralTests.php b/tests/e2e/Adapter/Scopes/GeneralTests.php index c6ae1d4f3..ef6b7ddcf 100644 --- a/tests/e2e/Adapter/Scopes/GeneralTests.php +++ b/tests/e2e/Adapter/Scopes/GeneralTests.php @@ -274,7 +274,7 @@ public function testFindOrderByAfterException(): void static::getDatabase()->find('movies', [ Query::limit(2), Query::offset(0), - Query::cursorAfter($document) + Query::cursorAfter($document->getId()) ]); } diff --git a/tests/unit/QueryTest.php b/tests/unit/QueryTest.php index d9ad6cd93..6db33a599 100644 --- a/tests/unit/QueryTest.php +++ b/tests/unit/QueryTest.php @@ -67,12 +67,11 @@ public function testCreate(): void $this->assertEquals('', $query->getAttribute()); $this->assertEquals([10], $query->getValues()); - $cursor = new Document(); - $query = Query::cursorAfter($cursor); + $query = Query::cursorAfter('abc'); $this->assertEquals(Query::TYPE_CURSOR_AFTER, $query->getMethod()); $this->assertEquals('', $query->getAttribute()); - $this->assertEquals([$cursor], $query->getValues()); + $this->assertEquals('abc', $query->getValue()); $query = Query::isNull('title'); diff --git a/tests/unit/Validator/DocumentsQueriesTest.php b/tests/unit/Validator/DocumentsQueriesTest.php index 45ae23933..ac0b5f2f0 100644 --- a/tests/unit/Validator/DocumentsQueriesTest.php +++ b/tests/unit/Validator/DocumentsQueriesTest.php @@ -130,8 +130,8 @@ public function testValidQueries(): void Query::endsWith('title', 'Night'), Query::isNull('title'), Query::isNotNull('title'), - Query::cursorAfter(new Document(['$id' => 'a'])), - Query::cursorBefore(new Document(['$id' => 'b'])), + Query::cursorAfter('a'), + Query::cursorBefore('b'), Query::orderAsc('title'), Query::limit(10), Query::offset(10), diff --git a/tests/unit/Validator/IndexedQueriesTest.php b/tests/unit/Validator/IndexedQueriesTest.php index 69ed9aeb1..4faa265bb 100644 --- a/tests/unit/Validator/IndexedQueriesTest.php +++ b/tests/unit/Validator/IndexedQueriesTest.php @@ -87,7 +87,7 @@ public function testValid(): void ] ); - $query = Query::cursorAfter(new Document(['$id' => 'abc'])); + $query = Query::cursorAfter('abc'); $this->assertEquals(true, $validator->isValid([$query])); $query = Query::parse('{"method":"cursorAfter","attribute":"","values":["abc"]}'); $this->assertEquals(true, $validator->isValid([$query])); diff --git a/tests/unit/Validator/QueriesTest.php b/tests/unit/Validator/QueriesTest.php index 86158014a..cb85cd808 100644 --- a/tests/unit/Validator/QueriesTest.php +++ b/tests/unit/Validator/QueriesTest.php @@ -70,7 +70,7 @@ public function testValid(): void ] ); - $this->assertEquals(true, $validator->isValid([Query::cursorAfter(new Document(['$id' => 'asdf']))]), $validator->getDescription()); + $this->assertEquals(true, $validator->isValid([Query::cursorAfter('asdf')]), $validator->getDescription()); $this->assertEquals(true, $validator->isValid([Query::equal('name', ['value'])]), $validator->getDescription()); $this->assertEquals(true, $validator->isValid([Query::limit(10)]), $validator->getDescription()); $this->assertEquals(true, $validator->isValid([Query::offset(10)]), $validator->getDescription()); diff --git a/tests/unit/Validator/QueryTest.php b/tests/unit/Validator/QueryTest.php index 7b4125145..893ef8e27 100644 --- a/tests/unit/Validator/QueryTest.php +++ b/tests/unit/Validator/QueryTest.php @@ -119,8 +119,8 @@ public function testQuery(): void $this->assertEquals(true, $validator->isValid([Query::lessThanEqual('price', 6)])); $this->assertEquals(true, $validator->isValid([Query::contains('tags', ['action1', 'action2'])])); $this->assertEquals(true, $validator->isValid([Query::contains('tags', ['action1'])])); - $this->assertEquals(true, $validator->isValid([Query::cursorAfter(new Document(['$id' => 'docId']))])); - $this->assertEquals(true, $validator->isValid([Query::cursorBefore(new Document(['$id' => 'docId']))])); + $this->assertEquals(true, $validator->isValid([Query::cursorAfter('docId')])); + $this->assertEquals(true, $validator->isValid([Query::cursorBefore('docId')])); $this->assertEquals(true, $validator->isValid([Query::orderAsc('title')])); $this->assertEquals(true, $validator->isValid([Query::orderDesc('title')])); $this->assertEquals(true, $validator->isValid([Query::isNull('title')])); @@ -227,7 +227,7 @@ public function testQueryCursor(): void { $validator = new Documents($this->attributes, []); - $response = $validator->isValid([Query::cursorAfter(new Document(['$id' => 'asdf']))]); + $response = $validator->isValid([Query::cursorAfter('asdf')]); $this->assertEquals(true, $response); } @@ -239,8 +239,8 @@ public function testQueryGetByType(): void $queries = [ Query::equal('key', ['value']), Query::select(['attr1', 'attr2']), - Query::cursorBefore(new Document([])), - Query::cursorAfter(new Document([])), + Query::cursorBefore('dsds'), + Query::cursorAfter('dsdsds'), ]; $queries = Query::getByType($queries, [Query::TYPE_CURSOR_AFTER, Query::TYPE_CURSOR_BEFORE]);