From 6c45aa784e7a32d8efb0e228e676e02ba3530517 Mon Sep 17 00:00:00 2001 From: Bruno Casali Date: Wed, 29 Jun 2022 17:52:51 -0300 Subject: [PATCH 1/2] Replace /indexes/:name/tasks /indexes/:name/tasks/:id routes --- src/Endpoints/Indexes.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Endpoints/Indexes.php b/src/Endpoints/Indexes.php index 9186c222f..576d6c70f 100644 --- a/src/Endpoints/Indexes.php +++ b/src/Endpoints/Indexes.php @@ -151,12 +151,12 @@ public function delete(): array public function getTask($uid): array { - return $this->http->get(self::PATH.'/'.$this->uid.'/tasks'.'/'.$uid); + return $this->http->get('/tasks/'.$uid, ['indexUid' => $this->uid]); } public function getTasks(): array { - return $this->http->get(self::PATH.'/'.$this->uid.'/tasks'); + return $this->http->get('/tasks', ['indexUid' => $this->uid]); } // Search From aa57628f6d215f21995a31f74beab084742e2016 Mon Sep 17 00:00:00 2001 From: Bruno Casali Date: Wed, 29 Jun 2022 17:53:32 -0300 Subject: [PATCH 2/2] Replace uid to taskUid in summarized task places --- tests/Endpoints/ClientTest.php | 8 +-- tests/Endpoints/DocumentsTest.php | 62 ++++++++++----------- tests/Endpoints/IndexTest.php | 14 ++--- tests/Endpoints/SearchTest.php | 42 +++++++------- tests/Endpoints/TasksTest.php | 36 ++++++------ tests/Endpoints/TenantTokenTest.php | 8 +-- tests/Settings/DisplayedAttributesTest.php | 6 +- tests/Settings/DistinctAttributeTest.php | 6 +- tests/Settings/FilterableAttributesTest.php | 6 +- tests/Settings/RankingRulesTest.php | 4 +- tests/Settings/SearchableAttributesTest.php | 4 +- tests/Settings/SettingsTest.php | 14 ++--- tests/Settings/SortableAttributesTest.php | 6 +- tests/Settings/StopWordsTest.php | 6 +- tests/Settings/SynonymsTest.php | 8 +-- tests/Settings/TypoToleranceTest.php | 4 +- tests/TestCase.php | 6 +- 17 files changed, 122 insertions(+), 118 deletions(-) diff --git a/tests/Endpoints/ClientTest.php b/tests/Endpoints/ClientTest.php index a108d642c..69f9c9cc0 100644 --- a/tests/Endpoints/ClientTest.php +++ b/tests/Endpoints/ClientTest.php @@ -132,7 +132,7 @@ public function testUpdateIndex(): void $this->createEmptyIndex('indexA'); $response = $this->client->updateIndex('indexA', ['primaryKey' => 'id']); - $this->client->waitForTask($response['uid']); + $this->client->waitForTask($response['taskUid']); $index = $this->client->getIndex($response['indexUid']); $this->assertSame($index->getPrimaryKey(), 'id'); @@ -147,7 +147,7 @@ public function testDeleteIndex(): void $this->assertCount(1, $response); $response = $this->client->deleteIndex('index'); - $this->client->waitForTask($response['uid']); + $this->client->waitForTask($response['taskUid']); $this->expectException(ApiException::class); $index = $this->client->getIndex('index'); @@ -170,7 +170,7 @@ public function testDeleteAllIndexes(): void $res = $this->client->deleteAllIndexes(); $taskUids = array_map(function ($task) { - return $task['uid']; + return $task['uid'] ?? $task['taskUid']; }, $res); $res = $this->client->waitForTasks($taskUids); @@ -186,7 +186,7 @@ public function testDeleteAllIndexesWhenThereAreNoIndexes(): void $res = $this->client->deleteAllIndexes(); $taskUids = array_map(function ($task) { - return $task['uid']; + return $task['uid'] ?? $task['taskUid']; }, $res); $this->client->waitForTasks($taskUids); diff --git a/tests/Endpoints/DocumentsTest.php b/tests/Endpoints/DocumentsTest.php index 53a74782a..4a363911b 100644 --- a/tests/Endpoints/DocumentsTest.php +++ b/tests/Endpoints/DocumentsTest.php @@ -18,7 +18,7 @@ public function testAddDocuments(): void $this->assertIsValidPromise($promise); - $index->waitForTask($promise['uid']); + $index->waitForTask($promise['taskUid']); $response = $index->getDocuments(); $this->assertCount(\count(self::DOCUMENTS), $response); @@ -33,7 +33,7 @@ public function testAddDocumentsInBatches(): void foreach ($promises as $promise) { $this->assertIsValidPromise($promise); - $index->waitForTask($promise['uid']); + $index->waitForTask($promise['taskUid']); } $response = $index->getDocuments(); @@ -52,7 +52,7 @@ public function testAddDocumentWithSpecialChars(): void $promise = $index->addDocuments($documents); $this->assertIsValidPromise($promise); - $index->waitForTask($promise['uid']); + $index->waitForTask($promise['taskUid']); $response = $index->getDocuments(); $this->assertCount(\count($documents), $response); @@ -75,7 +75,7 @@ public function testAddDocumentsCsv(): void $this->assertIsValidPromise($promise); - $update = $index->waitForTask($promise['uid']); + $update = $index->waitForTask($promise['taskUid']); $this->assertEquals($update['status'], 'succeeded'); $this->assertNotEquals($update['details']['receivedDocuments'], 0); @@ -96,7 +96,7 @@ public function testAddDocumentsJson(): void $this->assertIsValidPromise($promise); - $update = $index->waitForTask($promise['uid']); + $update = $index->waitForTask($promise['taskUid']); $this->assertEquals($update['status'], 'succeeded'); $this->assertNotEquals($update['details']['receivedDocuments'], 0); @@ -117,7 +117,7 @@ public function testAddDocumentsNdJson(): void $this->assertIsValidPromise($promise); - $update = $index->waitForTask($promise['uid']); + $update = $index->waitForTask($promise['taskUid']); $this->assertEquals($update['status'], 'succeeded'); $this->assertNotEquals($update['details']['receivedDocuments'], 0); @@ -141,7 +141,7 @@ public function testGetSingleDocumentWithIntegerDocumentId(): void { $index = $this->createEmptyIndex('documents'); $response = $index->addDocuments(self::DOCUMENTS); - $index->waitForTask($response['uid']); + $index->waitForTask($response['taskUid']); $doc = $this->findDocumentWithId(self::DOCUMENTS, 4); $response = $index->getDocument($doc['id']); @@ -155,7 +155,7 @@ public function testGetSingleDocumentWithStringDocumentId(): void $stringDocumentId = 'myUniqueId'; $index = $this->createEmptyIndex('documents'); $addDocumentResponse = $index->addDocuments([['id' => $stringDocumentId]]); - $index->waitForTask($addDocumentResponse['uid']); + $index->waitForTask($addDocumentResponse['taskUid']); $response = $index->getDocument($stringDocumentId); $this->assertIsArray($response); @@ -166,7 +166,7 @@ public function testReplaceDocuments(): void { $index = $this->createEmptyIndex('documents'); $response = $index->addDocuments(self::DOCUMENTS); - $index->waitForTask($response['uid']); + $index->waitForTask($response['taskUid']); $replacement = [ 'id' => 2, 'title' => 'The Red And The Black', @@ -175,7 +175,7 @@ public function testReplaceDocuments(): void $this->assertIsValidPromise($response); - $index->waitForTask($response['uid']); + $index->waitForTask($response['taskUid']); $response = $index->getDocument($replacement['id']); $this->assertSame($replacement['id'], $response['id']); @@ -189,7 +189,7 @@ public function testUpdateDocuments(): void { $index = $this->createEmptyIndex('documents'); $promise = $index->addDocuments(self::DOCUMENTS); - $index->waitForTask($promise['uid']); + $index->waitForTask($promise['taskUid']); $replacement = [ 'id' => 456, 'title' => 'The Little Prince', @@ -198,7 +198,7 @@ public function testUpdateDocuments(): void $this->assertIsValidPromise($promise); - $index->waitForTask($promise['uid']); + $index->waitForTask($promise['taskUid']); $response = $index->getDocument($replacement['id']); $this->assertSame($replacement['id'], $response['id']); @@ -214,7 +214,7 @@ public function testUpdateDocumentsInBatches(): void { $index = $this->createEmptyIndex('documents'); $documentPromise = $index->addDocuments(self::DOCUMENTS); - $index->waitForTask($documentPromise['uid']); + $index->waitForTask($documentPromise['taskUid']); $replacements = [ ['id' => 1, 'title' => 'Alice Outside Wonderland'], @@ -229,7 +229,7 @@ public function testUpdateDocumentsInBatches(): void foreach ($promises as $promise) { $this->assertIsValidPromise($promise); - $index->waitForTask($promise['uid']); + $index->waitForTask($promise['taskUid']); } foreach ($replacements as $replacement) { @@ -247,7 +247,7 @@ public function testAddWithUpdateDocuments(): void { $index = $this->createEmptyIndex('documents'); $response = $index->addDocuments(self::DOCUMENTS); - $index->waitForTask($response['uid']); + $index->waitForTask($response['taskUid']); $document = [ 'id' => 9, 'title' => '1984', @@ -256,7 +256,7 @@ public function testAddWithUpdateDocuments(): void $this->assertIsValidPromise($promise); - $index->waitForTask($promise['uid']); + $index->waitForTask($promise['taskUid']); $response = $index->getDocument($document['id']); $this->assertSame($document['id'], $response['id']); @@ -272,14 +272,14 @@ public function testDeleteNonExistingDocument(): void { $index = $this->createEmptyIndex('documents'); $response = $index->addDocuments(self::DOCUMENTS); - $index->waitForTask($response['uid']); + $index->waitForTask($response['taskUid']); $documentId = 9; $promise = $index->deleteDocument($documentId); $this->assertIsValidPromise($promise); - $index->waitForTask($promise['uid']); + $index->waitForTask($promise['taskUid']); $response = $index->getDocuments(); $this->assertCount(\count(self::DOCUMENTS), $response); @@ -290,14 +290,14 @@ public function testDeleteSingleExistingDocumentWithDocumentIdAsInteger(): void { $index = $this->createEmptyIndex('documents'); $response = $index->addDocuments(self::DOCUMENTS); - $index->waitForTask($response['uid']); + $index->waitForTask($response['taskUid']); $documentId = 123; $promise = $index->deleteDocument($documentId); $this->assertIsValidPromise($promise); - $index->waitForTask($promise['uid']); + $index->waitForTask($promise['taskUid']); $response = $index->getDocuments(); $this->assertCount(\count(self::DOCUMENTS) - 1, $response); @@ -309,10 +309,10 @@ public function testDeleteSingleExistingDocumentWithDocumentIdAsString(): void $stringDocumentId = 'myUniqueId'; $index = $this->createEmptyIndex('documents'); $addDocumentResponse = $index->addDocuments([['id' => $stringDocumentId]]); - $index->waitForTask($addDocumentResponse['uid']); + $index->waitForTask($addDocumentResponse['taskUid']); $promise = $index->deleteDocument($stringDocumentId); - $index->waitForTask($promise['uid']); + $index->waitForTask($promise['taskUid']); $response = $index->getDocuments(); @@ -323,13 +323,13 @@ public function testDeleteMultipleDocumentsWithDocumentIdAsInteger(): void { $index = $this->createEmptyIndex('documents'); $response = $index->addDocuments(self::DOCUMENTS); - $index->waitForTask($response['uid']); + $index->waitForTask($response['taskUid']); $documentIds = [1, 2]; $promise = $index->deleteDocuments($documentIds); $this->assertIsValidPromise($promise); - $index->waitForTask($promise['uid']); + $index->waitForTask($promise['taskUid']); $response = $index->getDocuments(); $this->assertCount(\count(self::DOCUMENTS) - 2, $response); @@ -346,10 +346,10 @@ public function testDeleteMultipleDocumentsWithDocumentIdAsString(): void ]; $index = $this->createEmptyIndex('documents'); $addDocumentResponse = $index->addDocuments($documents); - $index->waitForTask($addDocumentResponse['uid']); + $index->waitForTask($addDocumentResponse['taskUid']); $promise = $index->deleteDocuments(['myUniqueId1', 'myUniqueId3']); - $index->waitForTask($promise['uid']); + $index->waitForTask($promise['taskUid']); $response = $index->getDocuments(); $this->assertCount(1, $response); @@ -360,12 +360,12 @@ public function testDeleteAllDocuments(): void { $index = $this->createEmptyIndex('documents'); $response = $index->addDocuments(self::DOCUMENTS); - $index->waitForTask($response['uid']); + $index->waitForTask($response['taskUid']); $promise = $index->deleteAllDocuments(); $this->assertIsValidPromise($promise); - $index->waitForTask($promise['uid']); + $index->waitForTask($promise['taskUid']); $response = $index->getDocuments(); $this->assertCount(0, $response); @@ -392,8 +392,8 @@ public function testAddDocumentWithPrimaryKey(): void $index = $this->createEmptyIndex('an-index'); $response = $index->addDocuments($documents, 'unique'); - $this->assertArrayHasKey('uid', $response); - $index->waitForTask($response['uid']); + $this->assertArrayHasKey('taskUid', $response); + $index->waitForTask($response['taskUid']); $this->assertSame('unique', $index->fetchPrimaryKey()); $this->assertCount(1, $index->getDocuments()); @@ -413,7 +413,7 @@ public function testUpdateDocumentWithPrimaryKey(): void $this->assertIsValidPromise($promise); - $index->waitForTask($promise['uid']); + $index->waitForTask($promise['taskUid']); $this->assertSame('unique', $index->fetchPrimaryKey()); $this->assertCount(1, $index->getDocuments()); diff --git a/tests/Endpoints/IndexTest.php b/tests/Endpoints/IndexTest.php index e7215002b..fd1384bfd 100644 --- a/tests/Endpoints/IndexTest.php +++ b/tests/Endpoints/IndexTest.php @@ -116,7 +116,7 @@ public function testPrimaryKeyUpdate(): void $primaryKey = 'id'; $response = $this->index->update(['primaryKey' => $primaryKey]); - $this->client->waitForTask($response['uid']); + $this->client->waitForTask($response['taskUid']); $index = $this->client->getIndex($response['indexUid']); $this->assertSame($index->getPrimaryKey(), $primaryKey); @@ -171,12 +171,12 @@ public function testWaitForTaskDefault(): void { $promise = $this->index->addDocuments([['id' => 1, 'title' => 'Pride and Prejudice']]); - $response = $this->index->waitForTask($promise['uid']); + $response = $this->index->waitForTask($promise['taskUid']); /* @phpstan-ignore-next-line */ $this->assertIsArray($response); $this->assertSame($response['status'], 'succeeded'); - $this->assertSame($response['uid'], $promise['uid']); + $this->assertSame($response['uid'], $promise['taskUid']); $this->assertArrayHasKey('type', $response); $this->assertSame($response['type'], 'documentAddition'); $this->assertArrayHasKey('duration', $response); @@ -187,10 +187,10 @@ public function testWaitForTaskDefault(): void public function testWaitForTaskWithTimeoutAndInterval(): void { $promise = $this->index->addDocuments([['id' => 1, 'title' => 'Pride and Prejudice']]); - $response = $this->index->waitForTask($promise['uid'], 100, 20); + $response = $this->index->waitForTask($promise['taskUid'], 100, 20); $this->assertSame($response['status'], 'succeeded'); - $this->assertSame($response['uid'], $promise['uid']); + $this->assertSame($response['uid'], $promise['taskUid']); $this->assertArrayHasKey('type', $response); $this->assertSame($response['type'], 'documentAddition'); $this->assertArrayHasKey('duration', $response); @@ -202,10 +202,10 @@ public function testWaitForTaskWithTimeoutAndInterval(): void public function testWaitForTaskWithTimeout(): void { $promise = $this->index->addDocuments([['id' => 1, 'title' => 'Pride and Prejudice']]); - $response = $this->index->waitForTask($promise['uid'], 100); + $response = $this->index->waitForTask($promise['taskUid'], 100); $this->assertSame($response['status'], 'succeeded'); - $this->assertSame($response['uid'], $promise['uid']); + $this->assertSame($response['uid'], $promise['taskUid']); $this->assertArrayHasKey('type', $response); $this->assertSame($response['type'], 'documentAddition'); $this->assertArrayHasKey('duration', $response); diff --git a/tests/Endpoints/SearchTest.php b/tests/Endpoints/SearchTest.php index 2b17d7965..03e5e92a1 100644 --- a/tests/Endpoints/SearchTest.php +++ b/tests/Endpoints/SearchTest.php @@ -17,7 +17,7 @@ protected function setUp(): void parent::setUp(); $this->index = $this->createEmptyIndex('index'); $promise = $this->index->updateDocuments(self::DOCUMENTS); - $this->index->waitForTask($promise['uid']); + $this->index->waitForTask($promise['taskUid']); } public function testBasicSearch(): void @@ -132,7 +132,7 @@ public function testExceptionIfNoIndexWhenSearching(): void { $index = $this->createEmptyIndex('another-index'); $res = $index->delete(); - $index->waitForTask($res['uid']); + $index->waitForTask($res['taskUid']); $this->expectException(ApiException::class); @@ -236,7 +236,7 @@ public function testParametersWithCustomizedHighlightTag(): void public function testParametersArray(): void { $response = $this->index->updateFilterableAttributes(['title']); - $this->index->waitForTask($response['uid']); + $this->index->waitForTask($response['taskUid']); $response = $this->index->search('prince', [ 'limit' => 5, @@ -280,7 +280,7 @@ public function testParametersArray(): void public function testParametersCanBeAStar(): void { $response = $this->index->updateFilterableAttributes(['title']); - $this->index->waitForTask($response['uid']); + $this->index->waitForTask($response['taskUid']); $response = $this->index->search('prince', [ 'limit' => 5, @@ -324,7 +324,7 @@ public function testParametersCanBeAStar(): void public function testSearchWithFilterCanBeInt(): void { $response = $this->index->updateFilterableAttributes(['id', 'genre']); - $this->index->waitForTask($response['uid']); + $this->index->waitForTask($response['taskUid']); $response = $this->index->search('prince', [ 'filter' => 'id < 12', @@ -347,7 +347,7 @@ public function testSearchWithFilterCanBeInt(): void public function testBasicSearchWithFacetDistribution(): void { $response = $this->index->updateFilterableAttributes(['genre']); - $this->index->waitForTask($response['uid']); + $this->index->waitForTask($response['taskUid']); $response = $this->index->search('prince', [ 'facets' => ['genre'], @@ -373,7 +373,7 @@ public function testBasicSearchWithFacetDistribution(): void public function testBasicSearchWithFilters(): void { $response = $this->index->updateFilterableAttributes(['genre']); - $this->index->waitForTask($response['uid']); + $this->index->waitForTask($response['taskUid']); $response = $this->index->search('prince', [ 'filter' => [['genre = fantasy']], @@ -395,7 +395,7 @@ public function testBasicSearchWithFilters(): void public function testBasicSearchWithMultipleFilter(): void { $response = $this->index->updateFilterableAttributes(['genre']); - $this->index->waitForTask($response['uid']); + $this->index->waitForTask($response['taskUid']); $response = $this->index->search('prince', [ 'filter' => ['genre = fantasy', ['genre = fantasy', 'genre = fantasy']], @@ -417,7 +417,7 @@ public function testBasicSearchWithMultipleFilter(): void public function testCustomSearchWithFilterAndAttributesToRetrieve(): void { $response = $this->index->updateFilterableAttributes(['genre']); - $this->index->waitForTask($response['uid']); + $this->index->waitForTask($response['taskUid']); $response = $this->index->search('prince', [ 'filter' => [['genre = fantasy']], @@ -454,9 +454,9 @@ public function testSearchSortWithString(): void 'attribute', 'exactness', ]); - $this->index->waitForTask($response['uid']); + $this->index->waitForTask($response['taskUid']); $response = $this->index->updateSortableAttributes(['genre']); - $this->index->waitForTask($response['uid']); + $this->index->waitForTask($response['taskUid']); $response = $this->index->search('prince', [ 'sort' => ['genre:asc'], @@ -485,9 +485,9 @@ public function testSearchSortWithInt(): void 'attribute', 'exactness', ]); - $this->index->waitForTask($response['uid']); + $this->index->waitForTask($response['taskUid']); $response = $this->index->updateSortableAttributes(['id']); - $this->index->waitForTask($response['uid']); + $this->index->waitForTask($response['taskUid']); $response = $this->index->search('prince', [ 'sort' => ['id:asc'], @@ -516,9 +516,9 @@ public function testSearchSortWithMultipleParameter(): void 'attribute', 'exactness', ]); - $this->index->waitForTask($response['uid']); + $this->index->waitForTask($response['taskUid']); $response = $this->index->updateSortableAttributes(['id', 'title']); - $this->index->waitForTask($response['uid']); + $this->index->waitForTask($response['taskUid']); $response = $this->index->search('prince', [ 'sort' => ['id:asc', 'title:asc'], @@ -668,7 +668,7 @@ function (array $hit): bool { return 'Le Petit Prince' === $hit['title']; } public function testBasicSearchWithFacetsOption(): void { $response = $this->index->updateFilterableAttributes(['genre']); - $this->index->waitForTask($response['uid']); + $this->index->waitForTask($response['taskUid']); $response = $this->index->search( 'prince', @@ -686,9 +686,9 @@ public function testBasicSearchWithFacetsOption(): void public function testBasicSearchWithFacetsOptionAndMultipleFacets(): void { $response = $this->index->addDocuments([['id' => 32, 'title' => 'The Witcher', 'genre' => 'adventure', 'adaptation' => 'video game']]); - $this->index->waitForTask($response['uid']); + $this->index->waitForTask($response['taskUid']); $response = $this->index->updateFilterableAttributes(['genre', 'adaptation']); - $this->index->waitForTask($response['uid']); + $this->index->waitForTask($response['taskUid']); $response = $this->index->search( 'witch', @@ -708,7 +708,7 @@ public function testBasicSearchWithFacetsOptionAndMultipleFacets(): void public function testBasicSearchWithTransformFacetsDritributionOptionToFilter(): void { $response = $this->index->updateFilterableAttributes(['genre']); - $this->index->waitForTask($response['uid']); + $this->index->waitForTask($response['taskUid']); $filterAllFacets = function (array $facets): array { $filterOneFacet = function (array $facet): array { @@ -745,7 +745,7 @@ function (int $facetValue): bool { return 1 < $facetValue; }, public function testBasicSearchWithTransformFacetsDritributionOptionToMap(): void { $response = $this->index->updateFilterableAttributes(['genre']); - $this->index->waitForTask($response['uid']); + $this->index->waitForTask($response['taskUid']); $facetsToUpperFunc = function (array $facets): array { $changeOneFacet = function (array $facet): array { @@ -783,7 +783,7 @@ public function testBasicSearchWithTransformFacetsDritributionOptionToMap(): voi public function testBasicSearchWithTransformFacetsDritributionOptionToOder(): void { $response = $this->index->updateFilterableAttributes(['genre']); - $this->index->waitForTask($response['uid']); + $this->index->waitForTask($response['taskUid']); $facetsToUpperFunc = function (array $facets): array { $sortOneFacet = function (array $facet): array { diff --git a/tests/Endpoints/TasksTest.php b/tests/Endpoints/TasksTest.php index c5316861e..dff6aed51 100644 --- a/tests/Endpoints/TasksTest.php +++ b/tests/Endpoints/TasksTest.php @@ -24,7 +24,7 @@ public function testGetOneTaskFromWaitTask(): void $this->assertIsArray($response); $this->assertArrayHasKey('status', $response); - $this->assertSame($response['uid'], $promise['uid']); + $this->assertSame($response['uid'], $promise['taskUid']); $this->assertArrayHasKey('type', $response); $this->assertSame($response['type'], 'documentPartial'); $this->assertArrayHasKey('indexUid', $response); @@ -40,9 +40,9 @@ public function testGetOneTaskClient(): void [$promise, $response] = $this->seedIndex(); $this->assertIsArray($promise); - $response = $this->client->getTask($promise['uid']); + $response = $this->client->getTask($promise['taskUid']); $this->assertArrayHasKey('status', $response); - $this->assertSame($response['uid'], $promise['uid']); + $this->assertSame($response['uid'], $promise['taskUid']); $this->assertArrayHasKey('type', $response); $this->assertSame($response['type'], 'documentPartial'); $this->assertArrayHasKey('indexUid', $response); @@ -56,12 +56,13 @@ public function testGetOneTaskClient(): void public function testGetAllTasksClient(): void { $response = $this->client->getTasks(); - $preCount = \count($response['results']); - [$promise, $response] = $this->seedIndex(); + $firstIndex = $response['results'][0]['uid']; + $this->seedIndex(); - $this->assertIsArray($promise); $response = $this->client->getTasks(); - $this->assertCount($preCount + 1, $response['results']); + $newFirstIndex = $response['results'][0]['uid']; + + $this->assertNotEquals($firstIndex, $newFirstIndex); } public function testGetOneTaskIndex(): void @@ -69,9 +70,9 @@ public function testGetOneTaskIndex(): void [$promise, $response] = $this->seedIndex(); $this->assertIsArray($promise); - $response = $this->index->getTask($promise['uid']); + $response = $this->index->getTask($promise['taskUid']); $this->assertArrayHasKey('status', $response); - $this->assertSame($response['uid'], $promise['uid']); + $this->assertSame($response['uid'], $promise['taskUid']); $this->assertArrayHasKey('type', $response); $this->assertSame($response['type'], 'documentPartial'); $this->assertArrayHasKey('indexUid', $response); @@ -82,27 +83,30 @@ public function testGetOneTaskIndex(): void $this->assertIsArray($response['details']); } - public function testGetAllTasksIndex(): void + public function testGetAllTasksByIndex(): void { $response = $this->index->getTasks(); - $preCount = \count($response['results']); - [$promise, $response] = $this->seedIndex(); + $firstIndex = $response['results'][0]['uid']; + + $newIndex = $this->createEmptyIndex('a_new_index'); + $newIndex->updateDocuments(self::DOCUMENTS); - $this->assertIsArray($promise); $response = $this->index->getTasks(); - $this->assertCount($preCount + 1, $response['results']); + $newFirstIndex = $response['results'][0]['uid']; + + $this->assertEquals($firstIndex, $newFirstIndex); } public function testExceptionIfNoTaskIdWhenGetting(): void { $this->expectException(ApiException::class); - $this->index->getTask(9999999999); + $this->index->getTask(99999999); } private function seedIndex(): array { $promise = $this->index->updateDocuments(self::DOCUMENTS); - $response = $this->client->waitForTask($promise['uid']); + $response = $this->client->waitForTask($promise['taskUid']); return [$promise, $response]; } diff --git a/tests/Endpoints/TenantTokenTest.php b/tests/Endpoints/TenantTokenTest.php index 99be4ce17..919753066 100644 --- a/tests/Endpoints/TenantTokenTest.php +++ b/tests/Endpoints/TenantTokenTest.php @@ -33,7 +33,7 @@ protected function setUp(): void public function testGenerateTenantTokenWithSearchRulesOnly(): void { $promise = $this->client->index('tenantToken')->addDocuments(self::DOCUMENTS); - $this->client->waitForTask($promise['uid']); + $this->client->waitForTask($promise['taskUid']); $token = $this->privateClient->generateTenantToken(['*']); $tokenClient = new Client($this->host, $token); @@ -46,7 +46,7 @@ public function testGenerateTenantTokenWithSearchRulesOnly(): void public function testGenerateTenantTokenWithSearchRulesAsObject(): void { $promise = $this->client->index('tenantToken')->addDocuments(self::DOCUMENTS); - $this->client->waitForTask($promise['uid']); + $this->client->waitForTask($promise['taskUid']); $token = $this->privateClient->generateTenantToken((object) ['*' => (object) []]); $tokenClient = new Client($this->host, $token); @@ -59,11 +59,11 @@ public function testGenerateTenantTokenWithSearchRulesAsObject(): void public function testGenerateTenantTokenWithFilter(): void { $promise = $this->client->index('tenantToken')->addDocuments(self::DOCUMENTS); - $this->client->waitForTask($promise['uid']); + $this->client->waitForTask($promise['taskUid']); $promiseFromFilter = $this->client->index('tenantToken')->updateFilterableAttributes([ 'id', ]); - $this->client->waitForTask($promiseFromFilter['uid']); + $this->client->waitForTask($promiseFromFilter['taskUid']); $token = $this->privateClient->generateTenantToken((object) ['tenantToken' => (object) ['filter' => 'id > 10']]); $tokenClient = new Client($this->host, $token); diff --git a/tests/Settings/DisplayedAttributesTest.php b/tests/Settings/DisplayedAttributesTest.php index 9f14d4e30..c0f3025f9 100644 --- a/tests/Settings/DisplayedAttributesTest.php +++ b/tests/Settings/DisplayedAttributesTest.php @@ -28,7 +28,7 @@ public function testUpdateDisplayedAttributes(): void $promise = $index->updateDisplayedAttributes($newAttributes); $this->assertIsValidPromise($promise); - $index->waitForTask($promise['uid']); + $index->waitForTask($promise['taskUid']); $displayedAttributes = $index->getDisplayedAttributes(); @@ -41,13 +41,13 @@ public function testResetDisplayedAttributes(): void $newAttributes = ['title']; $promise = $index->updateDisplayedAttributes($newAttributes); - $index->waitForTask($promise['uid']); + $index->waitForTask($promise['taskUid']); $promise = $index->resetDisplayedAttributes(); $this->assertIsValidPromise($promise); - $index->waitForTask($promise['uid']); + $index->waitForTask($promise['taskUid']); $displayedAttributes = $index->getDisplayedAttributes(); $this->assertEquals(['*'], $displayedAttributes); diff --git a/tests/Settings/DistinctAttributeTest.php b/tests/Settings/DistinctAttributeTest.php index 2a52a3e65..88c39b99e 100644 --- a/tests/Settings/DistinctAttributeTest.php +++ b/tests/Settings/DistinctAttributeTest.php @@ -29,7 +29,7 @@ public function testUpdateDistinctAttribute(): void $promise = $this->index->updateDistinctAttribute($distinctAttribute); $this->assertIsValidPromise($promise); - $this->index->waitForTask($promise['uid']); + $this->index->waitForTask($promise['taskUid']); $this->assertEquals($distinctAttribute, $this->index->getDistinctAttribute()); } @@ -38,12 +38,12 @@ public function testResetDistinctAttribute(): void { $distinctAttribute = 'description'; $promise = $this->index->updateDistinctAttribute($distinctAttribute); - $this->index->waitForTask($promise['uid']); + $this->index->waitForTask($promise['taskUid']); $promise = $this->index->resetDistinctAttribute(); $this->assertIsValidPromise($promise); - $this->index->waitForTask($promise['uid']); + $this->index->waitForTask($promise['taskUid']); $this->assertNull($this->index->getDistinctAttribute()); } } diff --git a/tests/Settings/FilterableAttributesTest.php b/tests/Settings/FilterableAttributesTest.php index 1fdb6eae0..f3ace8df2 100644 --- a/tests/Settings/FilterableAttributesTest.php +++ b/tests/Settings/FilterableAttributesTest.php @@ -25,7 +25,7 @@ public function testUpdateFilterableAttributes(): void $promise = $index->updateFilterableAttributes($newAttributes); $this->assertIsValidPromise($promise); - $index->waitForTask($promise['uid']); + $index->waitForTask($promise['taskUid']); $filterableAttributes = $index->getFilterableAttributes(); @@ -38,13 +38,13 @@ public function testResetFilterableAttributes(): void $newAttributes = ['title']; $promise = $index->updateFilterableAttributes($newAttributes); - $index->waitForTask($promise['uid']); + $index->waitForTask($promise['taskUid']); $promise = $index->resetFilterableAttributes(); $this->assertIsValidPromise($promise); - $index->waitForTask($promise['uid']); + $index->waitForTask($promise['taskUid']); $filterableAttributes = $index->getFilterableAttributes(); $this->assertEmpty($filterableAttributes); diff --git a/tests/Settings/RankingRulesTest.php b/tests/Settings/RankingRulesTest.php index 9f33e8bb5..0cbd6554b 100644 --- a/tests/Settings/RankingRulesTest.php +++ b/tests/Settings/RankingRulesTest.php @@ -44,7 +44,7 @@ public function testUpdateRankingRules(): void $promise = $this->index->updateRankingRules($newRankingRules); $this->assertIsValidPromise($promise); - $this->index->waitForTask($promise['uid']); + $this->index->waitForTask($promise['taskUid']); $rankingRules = $this->index->getRankingRules(); @@ -57,7 +57,7 @@ public function testResetRankingRules(): void $this->assertIsValidPromise($promise); - $this->index->waitForTask($promise['uid']); + $this->index->waitForTask($promise['taskUid']); $rankingRules = $this->index->getRankingRules(); $this->assertEquals(self::DEFAULT_RANKING_RULES, $rankingRules); diff --git a/tests/Settings/SearchableAttributesTest.php b/tests/Settings/SearchableAttributesTest.php index 1bc541c0e..117856a29 100644 --- a/tests/Settings/SearchableAttributesTest.php +++ b/tests/Settings/SearchableAttributesTest.php @@ -32,7 +32,7 @@ public function testUpdateSearchableAttributes(): void $this->assertIsValidPromise($promise); - $indexA->waitForTask($promise['uid']); + $indexA->waitForTask($promise['taskUid']); $updatedAttributes = $indexA->getSearchableAttributes(); $this->assertEquals($searchableAttributes, $updatedAttributes); @@ -45,7 +45,7 @@ public function testResetSearchableAttributes(): void $this->assertIsValidPromise($promise); - $index->waitForTask($promise['uid']); + $index->waitForTask($promise['taskUid']); $searchableAttributes = $index->getSearchableAttributes(); $this->assertEquals(['*'], $searchableAttributes); diff --git a/tests/Settings/SettingsTest.php b/tests/Settings/SettingsTest.php index 1738c8c08..563e45d12 100644 --- a/tests/Settings/SettingsTest.php +++ b/tests/Settings/SettingsTest.php @@ -84,7 +84,7 @@ public function testUpdateSettings(): void 'stopWords' => ['the'], ]); $this->assertIsValidPromise($promise); - $index->waitForTask($promise['uid']); + $index->waitForTask($promise['taskUid']); $settings = $index->getSettings(); @@ -125,14 +125,14 @@ public function testUpdateSettingsWithoutOverwritingThem(): void ]); $this->assertIsValidPromise($promise); - $index->waitForTask($promise['uid']); + $index->waitForTask($promise['taskUid']); $promise = $index->updateSettings([ 'searchableAttributes' => ['title'], ]); $this->assertIsValidPromise($promise); - $index->waitForTask($promise['uid']); + $index->waitForTask($promise['taskUid']); $settings = $index->getSettings(); @@ -160,12 +160,12 @@ public function testResetSettings(): void 'stopWords' => ['the'], ]); $this->assertIsValidPromise($promise); - $index->waitForTask($promise['uid']); + $index->waitForTask($promise['taskUid']); $promise = $index->resetSettings(); $this->assertIsValidPromise($promise); - $index->waitForTask($promise['uid']); + $index->waitForTask($promise['taskUid']); $settings = $index->getSettings(); @@ -193,11 +193,11 @@ public function testGetThenUpdateSettings(): void $resetPromise = $index->resetSettings(); $this->assertIsValidPromise($resetPromise); - $index->waitForTask($resetPromise['uid']); + $index->waitForTask($resetPromise['taskUid']); $settings = $index->getSettings(); $promise = $index->updateSettings($settings); $this->assertIsValidPromise($promise); - $index->waitForTask($promise['uid']); + $index->waitForTask($promise['taskUid']); } } diff --git a/tests/Settings/SortableAttributesTest.php b/tests/Settings/SortableAttributesTest.php index d6897fe9f..abad653aa 100644 --- a/tests/Settings/SortableAttributesTest.php +++ b/tests/Settings/SortableAttributesTest.php @@ -25,7 +25,7 @@ public function testUpdateSortableAttributes(): void $promise = $index->updateSortableAttributes($newAttributes); $this->assertIsValidPromise($promise); - $index->waitForTask($promise['uid']); + $index->waitForTask($promise['taskUid']); $sortableAttributes = $index->getSortableAttributes(); @@ -38,13 +38,13 @@ public function testResetSortableAttributes(): void $newAttributes = ['title']; $promise = $index->updateSortableAttributes($newAttributes); - $index->waitForTask($promise['uid']); + $index->waitForTask($promise['taskUid']); $promise = $index->resetSortableAttributes(); $this->assertIsValidPromise($promise); - $index->waitForTask($promise['uid']); + $index->waitForTask($promise['taskUid']); $sortableAttributes = $index->getSortableAttributes(); $this->assertEmpty($sortableAttributes); diff --git a/tests/Settings/StopWordsTest.php b/tests/Settings/StopWordsTest.php index 082e27df5..89d78990b 100644 --- a/tests/Settings/StopWordsTest.php +++ b/tests/Settings/StopWordsTest.php @@ -31,7 +31,7 @@ public function testUpdateStopWords(): void $this->assertIsValidPromise($promise); - $this->index->waitForTask($promise['uid']); + $this->index->waitForTask($promise['taskUid']); $stopWords = $this->index->getStopWords(); $this->assertEquals($newStopWords, $stopWords); @@ -40,12 +40,12 @@ public function testUpdateStopWords(): void public function testResetStopWords(): void { $promise = $this->index->updateStopWords(['the']); - $this->index->waitForTask($promise['uid']); + $this->index->waitForTask($promise['taskUid']); $promise = $this->index->resetStopWords(); $this->assertIsValidPromise($promise); - $this->index->waitForTask($promise['uid']); + $this->index->waitForTask($promise['taskUid']); $stopWords = $this->index->getStopWords(); diff --git a/tests/Settings/SynonymsTest.php b/tests/Settings/SynonymsTest.php index 7bb37fd01..8b2249c62 100644 --- a/tests/Settings/SynonymsTest.php +++ b/tests/Settings/SynonymsTest.php @@ -34,7 +34,7 @@ public function testUpdateSynonyms(): void $this->assertIsValidPromise($promise); - $this->index->waitForTask($promise['uid']); + $this->index->waitForTask($promise['taskUid']); $synonyms = $this->index->getSynonyms(); $this->assertEquals($newSynonyms, $synonyms); @@ -47,7 +47,7 @@ public function testUpdateSynonymsWithEmptyArray(): void $this->assertIsValidPromise($promise); - $this->index->waitForTask($promise['uid']); + $this->index->waitForTask($promise['taskUid']); $synonyms = $this->index->getSynonyms(); $this->assertEquals($newSynonyms, $synonyms); @@ -58,12 +58,12 @@ public function testResetSynonyms(): void $promise = $this->index->updateSynonyms([ 'hp' => ['harry potter'], ]); - $this->index->waitForTask($promise['uid']); + $this->index->waitForTask($promise['taskUid']); $promise = $this->index->resetSynonyms(); $this->assertIsValidPromise($promise); - $this->index->waitForTask($promise['uid']); + $this->index->waitForTask($promise['taskUid']); $synonyms = $this->index->getSynonyms(); $this->assertEmpty($synonyms); diff --git a/tests/Settings/TypoToleranceTest.php b/tests/Settings/TypoToleranceTest.php index c39b55898..f6eb25883 100644 --- a/tests/Settings/TypoToleranceTest.php +++ b/tests/Settings/TypoToleranceTest.php @@ -46,7 +46,7 @@ public function testUpdateTypoTolerance(): void 'disableOnAttributes' => ['title'], ]; $promise = $this->index->updateTypoTolerance($newTypoTolerance); - $this->index->waitForTask($promise['uid']); + $this->index->waitForTask($promise['taskUid']); $typoTolerance = $this->index->getTypoTolerance(); $this->assertIsValidPromise($promise); @@ -56,7 +56,7 @@ public function testUpdateTypoTolerance(): void public function testResetTypoTolerance(): void { $promise = $this->index->resetTypoTolerance(); - $this->index->waitForTask($promise['uid']); + $this->index->waitForTask($promise['taskUid']); $typoTolerance = $this->index->getTypoTolerance(); $this->assertIsValidPromise($promise); diff --git a/tests/TestCase.php b/tests/TestCase.php index f22649567..74776ffda 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -55,20 +55,20 @@ protected function tearDown(): void { $res = $this->client->deleteAllIndexes(); $uids = array_map(function ($task) { - return $task['uid']; + return $task['uid'] ?? $task['taskUid']; }, $res); $this->client->waitForTasks($uids); } public function assertIsValidPromise(array $promise): void { - $this->assertArrayHasKey('uid', $promise); + $this->assertArrayHasKey('taskUid', $promise); } public function createEmptyIndex($indexName, $options = []): Indexes { $response = $this->client->createIndex($indexName, $options); - $this->client->waitForTask($response['uid']); + $this->client->waitForTask($response['taskUid']); return $this->client->getIndex($response['indexUid']); }