diff --git a/.php-cs-fixer.dist.php b/.php-cs-fixer.dist.php index 8fa21cb5..938669e3 100644 --- a/.php-cs-fixer.dist.php +++ b/.php-cs-fixer.dist.php @@ -12,6 +12,8 @@ 'declare_strict_types' => true, 'void_return' => true, 'native_function_invocation' => ['include' => ['@compiler_optimized'], 'scope' => 'namespaced'], + 'php_unit_test_case_static_method_calls' => ['call_type' => 'self'], + 'php_unit_strict' => true, ]; $config = new PhpCsFixer\Config(); diff --git a/phpstan.neon.dist b/phpstan.neon.dist index bcbac422..46b0f477 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -3,5 +3,3 @@ parameters: paths: - src - tests - ignoreErrors: - - '#Dynamic call to static method PHPUnit\\Framework\\.*#' diff --git a/tests/Contracts/CancelTasksQueryTest.php b/tests/Contracts/CancelTasksQueryTest.php index 1c6b54fb..b44e7f5f 100644 --- a/tests/Contracts/CancelTasksQueryTest.php +++ b/tests/Contracts/CancelTasksQueryTest.php @@ -13,7 +13,7 @@ public function testSetTypes(): void { $data = (new CancelTasksQuery())->setTypes(['abc', 'xyz']); - $this->assertEquals(['types' => 'abc,xyz'], $data->toArray()); + self::assertSame(['types' => 'abc,xyz'], $data->toArray()); } public function testSetAnyDateFilter(): void @@ -21,17 +21,13 @@ public function testSetAnyDateFilter(): void $date = new \DateTime(); $data = (new CancelTasksQuery())->setBeforeEnqueuedAt($date); - $this->assertEquals(['beforeEnqueuedAt' => $date->format(\DateTime::RFC3339)], $data->toArray()); + self::assertSame(['beforeEnqueuedAt' => $date->format(\DateTime::RFC3339)], $data->toArray()); } public function testToArrayWithDifferentSets(): void { $data = (new CancelTasksQuery())->setUids([1, 2, 3])->setStatuses(['enqueued']); - $this->assertEquals([ - 'uids' => '1,2,3', 'statuses' => 'enqueued', - ], - $data->toArray() - ); + self::assertSame(['statuses' => 'enqueued', 'uids' => '1,2,3'], $data->toArray()); } } diff --git a/tests/Contracts/DeleteTasksQueryTest.php b/tests/Contracts/DeleteTasksQueryTest.php index 5cd87484..38836eba 100644 --- a/tests/Contracts/DeleteTasksQueryTest.php +++ b/tests/Contracts/DeleteTasksQueryTest.php @@ -13,7 +13,7 @@ public function testSetTypes(): void { $data = (new DeleteTasksQuery())->setTypes(['abc', 'xyz']); - $this->assertEquals(['types' => 'abc,xyz'], $data->toArray()); + self::assertSame(['types' => 'abc,xyz'], $data->toArray()); } public function testSetAnyDateFilter(): void @@ -21,16 +21,13 @@ public function testSetAnyDateFilter(): void $date = new \DateTime(); $data = (new DeleteTasksQuery())->setCanceledBy([null])->setBeforeEnqueuedAt($date); - $this->assertEquals(['beforeEnqueuedAt' => $date->format(\DateTime::RFC3339)], $data->toArray()); + self::assertSame(['beforeEnqueuedAt' => $date->format(\DateTime::RFC3339)], $data->toArray()); } public function testToArrayWithDifferentSets(): void { $data = (new DeleteTasksQuery())->setCanceledBy([1, 2])->setStatuses(['enqueued']); - $this->assertEquals([ - 'canceledBy' => '1,2', 'statuses' => 'enqueued', - ], $data->toArray() - ); + self::assertSame(['statuses' => 'enqueued', 'canceledBy' => '1,2'], $data->toArray()); } } diff --git a/tests/Contracts/DocumentsQueryTest.php b/tests/Contracts/DocumentsQueryTest.php index 7d5cd0f2..465badd3 100644 --- a/tests/Contracts/DocumentsQueryTest.php +++ b/tests/Contracts/DocumentsQueryTest.php @@ -13,27 +13,27 @@ public function testSetFields(): void { $data = (new DocumentsQuery())->setLimit(10)->setFields(['abc', 'xyz']); - $this->assertEquals(['limit' => 10, 'fields' => 'abc,xyz'], $data->toArray()); + self::assertSame(['limit' => 10, 'fields' => 'abc,xyz'], $data->toArray()); } public function testToArrayWithoutSetFields(): void { $data = (new DocumentsQuery())->setLimit(10); - $this->assertEquals(['limit' => 10], $data->toArray()); + self::assertSame(['limit' => 10], $data->toArray()); } public function testToArrayWithoutSetOffset(): void { $data = (new DocumentsQuery())->setOffset(10); - $this->assertEquals(['offset' => 10], $data->toArray()); + self::assertSame(['offset' => 10], $data->toArray()); } public function testToArrayWithZeros(): void { $data = (new DocumentsQuery())->setLimit(0)->setOffset(0); - $this->assertEquals(['limit' => 0, 'offset' => 0], $data->toArray()); + self::assertSame(['offset' => 0, 'limit' => 0], $data->toArray()); } } diff --git a/tests/Contracts/IndexesQueryTest.php b/tests/Contracts/IndexesQueryTest.php index 239c83e4..d2112a2e 100644 --- a/tests/Contracts/IndexesQueryTest.php +++ b/tests/Contracts/IndexesQueryTest.php @@ -13,27 +13,27 @@ public function testToArrayWithSetOffsetAndSetLimit(): void { $data = (new IndexesQuery())->setLimit(10)->setOffset(18); - $this->assertEquals(['limit' => 10, 'offset' => 18], $data->toArray()); + self::assertSame(['offset' => 18, 'limit' => 10], $data->toArray()); } public function testToArrayWithSetOffset(): void { $data = (new IndexesQuery())->setOffset(5); - $this->assertEquals(['offset' => 5], $data->toArray()); + self::assertSame(['offset' => 5], $data->toArray()); } public function testToArrayWithoutSet(): void { $data = new IndexesQuery(); - $this->assertEmpty($data->toArray()); + self::assertEmpty($data->toArray()); } public function testToArrayWithZeros(): void { $data = (new IndexesQuery())->setLimit(0)->setOffset(0); - $this->assertEquals(['limit' => 0, 'offset' => 0], $data->toArray()); + self::assertSame(['offset' => 0, 'limit' => 0], $data->toArray()); } } diff --git a/tests/Contracts/KeysQueryTest.php b/tests/Contracts/KeysQueryTest.php index 5bccd311..b23cc757 100644 --- a/tests/Contracts/KeysQueryTest.php +++ b/tests/Contracts/KeysQueryTest.php @@ -13,27 +13,27 @@ public function testToArrayWithSetOffsetAndSetLimit(): void { $data = (new KeysQuery())->setLimit(10)->setOffset(18); - $this->assertEquals(['limit' => 10, 'offset' => 18], $data->toArray()); + self::assertSame(['offset' => 18, 'limit' => 10], $data->toArray()); } public function testToArrayWithSetOffset(): void { $data = (new KeysQuery())->setOffset(5); - $this->assertEquals(['offset' => 5], $data->toArray()); + self::assertSame(['offset' => 5], $data->toArray()); } public function testToArrayWithoutSet(): void { $data = new KeysQuery(); - $this->assertEmpty($data->toArray()); + self::assertEmpty($data->toArray()); } public function testToArrayWithZeros(): void { $data = (new KeysQuery())->setLimit(0)->setOffset(0); - $this->assertEquals(['limit' => 0, 'offset' => 0], $data->toArray()); + self::assertSame(['offset' => 0, 'limit' => 0], $data->toArray()); } } diff --git a/tests/Contracts/TasksQueryTest.php b/tests/Contracts/TasksQueryTest.php index 715d781a..6fd13d89 100644 --- a/tests/Contracts/TasksQueryTest.php +++ b/tests/Contracts/TasksQueryTest.php @@ -13,7 +13,7 @@ public function testSetTypes(): void { $data = (new TasksQuery())->setTypes(['abc', 'xyz']); - $this->assertEquals(['types' => 'abc,xyz'], $data->toArray()); + self::assertSame(['types' => 'abc,xyz'], $data->toArray()); } public function testSetAnyDateFilter(): void @@ -21,29 +21,27 @@ public function testSetAnyDateFilter(): void $date = new \DateTime(); $data = (new TasksQuery())->setBeforeEnqueuedAt($date); - $this->assertEquals($data->toArray(), ['beforeEnqueuedAt' => $date->format(\DateTime::RFC3339)]); + self::assertSame(['beforeEnqueuedAt' => $date->format(\DateTime::RFC3339)], $data->toArray()); } public function testToArrayWithSetLimit(): void { $data = (new TasksQuery())->setLimit(10); - $this->assertEquals(['limit' => 10], $data->toArray()); + self::assertSame(['limit' => 10], $data->toArray()); } public function testToArrayWithSetLimitWithZero(): void { $data = (new TasksQuery())->setLimit(0); - $this->assertEquals(['limit' => 0], $data->toArray()); + self::assertSame(['limit' => 0], $data->toArray()); } public function testToArrayWithDifferentSets(): void { $data = (new TasksQuery())->setFrom(10)->setLimit(9)->setCanceledBy([1, 4])->setStatuses(['enqueued']); - $this->assertEquals([ - 'limit' => 9, 'from' => 10, 'statuses' => 'enqueued', 'canceledBy' => '1,4', - ], $data->toArray()); + self::assertSame(['statuses' => 'enqueued', 'from' => 10, 'limit' => 9, 'canceledBy' => '1,4'], $data->toArray()); } } diff --git a/tests/Endpoints/ClientTest.php b/tests/Endpoints/ClientTest.php index 72748c8a..e5c8c714 100644 --- a/tests/Endpoints/ClientTest.php +++ b/tests/Endpoints/ClientTest.php @@ -16,32 +16,32 @@ public function testClientIndexMethodsAlwaysReturnArray(): void { $index = $this->createEmptyIndex($this->safeIndexName()); /* @phpstan-ignore-next-line */ - $this->assertIsIterable($this->client->getIndexes()); + self::assertIsIterable($this->client->getIndexes()); /* @phpstan-ignore-next-line */ - $this->assertIsArray($this->client->getRawIndex($index->getUid())); + self::assertIsArray($this->client->getRawIndex($index->getUid())); } public function testClientIndexMethodsAlwaysReturnsIndexesInstance(): void { $index = $this->createEmptyIndex($this->safeIndexName()); /* @phpstan-ignore-next-line */ - $this->assertInstanceOf(Indexes::class, $this->client->getIndex($index->getUid())); + self::assertInstanceOf(Indexes::class, $this->client->getIndex($index->getUid())); /* @phpstan-ignore-next-line */ - $this->assertInstanceOf(Indexes::class, $this->client->index($index->getUid())); + self::assertInstanceOf(Indexes::class, $this->client->index($index->getUid())); } public function testgetIndexesWhenEmpty(): void { $response = $this->client->getIndexes(); - $this->assertEmpty($response); + self::assertEmpty($response); } public function testgetIndexesWithPagination(): void { $response = $this->client->getIndexes((new IndexesQuery())->setLimit(1)->setOffset(99999)); - $this->assertEmpty($response); + self::assertEmpty($response); } public function testExceptionIsThrownOnGetRawIndexWhenIndexDoesNotExist(): void @@ -57,8 +57,8 @@ public function testCreateIndexWithOnlyUid(): void $indexName = $this->safeIndexName(); $index = $this->createEmptyIndex($indexName); - $this->assertSame($indexName, $index->getUid()); - $this->assertNull($index->getPrimaryKey()); + self::assertSame($indexName, $index->getUid()); + self::assertNull($index->getPrimaryKey()); } public function testCreateIndexWithUidAndPrimaryKey(): void @@ -69,8 +69,8 @@ public function testCreateIndexWithUidAndPrimaryKey(): void ['primaryKey' => 'ObjectId'] ); - $this->assertSame($indexName, $index->getUid()); - $this->assertSame('ObjectId', $index->getPrimaryKey()); + self::assertSame($indexName, $index->getUid()); + self::assertSame('ObjectId', $index->getPrimaryKey()); } public function testCreateIndexWithUidInOptions(): void @@ -84,8 +84,8 @@ public function testCreateIndexWithUidInOptions(): void ] ); - $this->assertSame($indexName, $index->getUid()); - $this->assertSame('ObjectId', $index->getPrimaryKey()); + self::assertSame($indexName, $index->getUid()); + self::assertSame('ObjectId', $index->getPrimaryKey()); } public function testgetIndexes(): void @@ -99,7 +99,7 @@ public function testgetIndexes(): void $indexes = $this->client->getIndexes(); - $this->assertCount(2, $indexes); + self::assertCount(2, $indexes); } public function testGetRawIndex(): void @@ -108,7 +108,7 @@ public function testGetRawIndex(): void $res = $this->client->getRawIndex('books-1'); - $this->assertArrayHasKey('uid', $res); + self::assertArrayHasKey('uid', $res); } public function testUpdateIndex(): void @@ -120,8 +120,8 @@ public function testUpdateIndex(): void $this->client->waitForTask($response['taskUid']); $index = $this->client->getIndex($response['indexUid']); - $this->assertSame($index->getPrimaryKey(), 'id'); - $this->assertSame($index->getUid(), $indexName); + self::assertSame('id', $index->getPrimaryKey()); + self::assertSame($indexName, $index->getUid()); } public function testDeleteIndex(): void @@ -129,7 +129,7 @@ public function testDeleteIndex(): void $this->createEmptyIndex($this->safeIndexName()); $response = $this->client->getIndexes(); - $this->assertCount(1, $response); + self::assertCount(1, $response); $response = $this->client->deleteIndex('index'); $this->client->waitForTask($response['taskUid']); @@ -137,10 +137,10 @@ public function testDeleteIndex(): void $this->expectException(ApiException::class); $index = $this->client->getIndex('index'); - $this->assertEmpty($index); + self::assertEmpty($index); $indexes = $this->client->getIndexes(); - $this->assertCount(0, $indexes); + self::assertCount(0, $indexes); } public function testGetIndex(): void @@ -149,8 +149,8 @@ public function testGetIndex(): void $this->createEmptyIndex($indexName); $index = $this->client->getIndex($indexName); - $this->assertSame($indexName, $index->getUid()); - $this->assertNull($index->getPrimaryKey()); + self::assertSame($indexName, $index->getUid()); + self::assertNull($index->getPrimaryKey()); } public function testIndex(): void @@ -158,8 +158,8 @@ public function testIndex(): void $this->createEmptyIndex($this->safeIndexName()); $index = $this->client->index('index'); - $this->assertSame('index', $index->getUid()); - $this->assertNull($index->getPrimaryKey()); + self::assertSame('index', $index->getUid()); + self::assertNull($index->getPrimaryKey()); } public function testExceptionIfUidIsNullWhenCreating(): void @@ -184,14 +184,14 @@ public function testHealth(): void { $response = $this->client->health(); - $this->assertEquals('available', $response['status']); + self::assertSame('available', $response['status']); } public function testIsHealthyIsTrue(): void { $response = $this->client->isHealthy(); - $this->assertTrue($response); + self::assertTrue($response); } public function testIsHealthyIsFalse(): void @@ -199,25 +199,25 @@ public function testIsHealthyIsFalse(): void $client = new Client('http://127.0.0.1.com:1234', 'masterKey'); $response = $client->isHealthy(); - $this->assertFalse($response); + self::assertFalse($response); } public function testVersion(): void { $response = $this->client->version(); - $this->assertArrayHasKey('commitSha', $response); - $this->assertArrayHasKey('commitDate', $response); - $this->assertArrayHasKey('pkgVersion', $response); + self::assertArrayHasKey('commitSha', $response); + self::assertArrayHasKey('commitDate', $response); + self::assertArrayHasKey('pkgVersion', $response); } public function testStats(): void { $response = $this->client->stats(); - $this->assertArrayHasKey('databaseSize', $response); - $this->assertArrayHasKey('lastUpdate', $response); - $this->assertArrayHasKey('indexes', $response); + self::assertArrayHasKey('databaseSize', $response); + self::assertArrayHasKey('lastUpdate', $response); + self::assertArrayHasKey('indexes', $response); } public function testBadClientUrl(): void @@ -233,7 +233,7 @@ public function testHeaderWithoutApiKey(): void $response = $client->health(); - $this->assertEquals('available', $response['status']); + self::assertSame('available', $response['status']); $this->expectException(ApiException::class); $response = $client->stats(); } diff --git a/tests/Endpoints/DocumentsTest.php b/tests/Endpoints/DocumentsTest.php index 651ebc92..b253bdb0 100644 --- a/tests/Endpoints/DocumentsTest.php +++ b/tests/Endpoints/DocumentsTest.php @@ -25,7 +25,7 @@ public function testAddDocuments(): void $index->waitForTask($promise['taskUid']); $response = $index->getDocuments(); - $this->assertCount(\count(self::DOCUMENTS), $response); + self::assertCount(\count(self::DOCUMENTS), $response); } public function testAddDocumentsInBatches(): void @@ -33,7 +33,7 @@ public function testAddDocumentsInBatches(): void $index = $this->createEmptyIndex($this->safeIndexName('movies')); $promises = $index->addDocumentsInBatches(self::DOCUMENTS, 2); - $this->assertCount(4, $promises); + self::assertCount(4, $promises); foreach ($promises as $promise) { $this->assertIsValidPromise($promise); @@ -41,7 +41,7 @@ public function testAddDocumentsInBatches(): void } $response = $index->getDocuments(); - $this->assertCount(\count(self::DOCUMENTS), $response); + self::assertCount(\count(self::DOCUMENTS), $response); } public function testAddDocumentWithSpecialChars(): void @@ -59,11 +59,11 @@ public function testAddDocumentWithSpecialChars(): void $index->waitForTask($promise['taskUid']); $response = $index->getDocuments(); - $this->assertCount(\count($documents), $response); + self::assertCount(\count($documents), $response); foreach ($documents as $k => $document) { - $this->assertSame($document['title'], $response[$k]['title']); - $this->assertSame($document['comment'], $response[$k]['comment']); + self::assertSame($document['title'], $response[$k]['title']); + self::assertSame($document['comment'], $response[$k]['comment']); } } @@ -81,11 +81,11 @@ public function testAddDocumentsCsv(): void $update = $index->waitForTask($promise['taskUid']); - $this->assertEquals('succeeded', $update['status']); - $this->assertNotEquals(0, $update['details']['receivedDocuments']); + self::assertSame('succeeded', $update['status']); + self::assertNotSame(0, $update['details']['receivedDocuments']); $response = $index->getDocuments(); - $this->assertCount(20, $response); + self::assertCount(20, $response); } public function testAddDocumentsCsvWithCustomSeparator(): void @@ -100,12 +100,12 @@ public function testAddDocumentsCsvWithCustomSeparator(): void $update = $index->waitForTask($promise['taskUid']); - $this->assertEquals($update['status'], 'succeeded'); - $this->assertEquals($update['details']['receivedDocuments'], 6); + self::assertSame('succeeded', $update['status']); + self::assertSame(6, $update['details']['receivedDocuments']); $documents = $index->getDocuments()->getResults(); - $this->assertEquals('Teenage Neon Jungle', $documents[4]['album']); - $this->assertEquals('631152000', $documents[5]['released-timestamp']); + self::assertSame('Teenage Neon Jungle', $documents[4]['album']); + self::assertSame('631152000', $documents[5]['released-timestamp']); } public function testAddDocumentsJson(): void @@ -122,11 +122,11 @@ public function testAddDocumentsJson(): void $update = $index->waitForTask($promise['taskUid']); - $this->assertEquals('succeeded', $update['status']); - $this->assertNotEquals(0, $update['details']['receivedDocuments']); + self::assertSame('succeeded', $update['status']); + self::assertNotSame(0, $update['details']['receivedDocuments']); $response = $index->getDocuments(); - $this->assertCount(20, $response); + self::assertCount(20, $response); } public function testAddDocumentsNdJson(): void @@ -143,11 +143,11 @@ public function testAddDocumentsNdJson(): void $update = $index->waitForTask($promise['taskUid']); - $this->assertEquals('succeeded', $update['status']); - $this->assertNotEquals(0, $update['details']['receivedDocuments']); + self::assertSame('succeeded', $update['status']); + self::assertNotSame(0, $update['details']['receivedDocuments']); $response = $index->getDocuments(); - $this->assertCount(20, $response); + self::assertCount(20, $response); } public function testCannotAddDocumentWhenJsonEncodingFails(): void @@ -169,9 +169,9 @@ public function testGetSingleDocumentWithIntegerDocumentId(): void $doc = $this->findDocumentWithId(self::DOCUMENTS, 4); $response = $index->getDocument($doc['id']); - $this->assertIsArray($response); - $this->assertSame($doc['id'], $response['id']); - $this->assertSame($doc['title'], $response['title']); + self::assertIsArray($response); + self::assertSame($doc['id'], $response['id']); + self::assertSame($doc['title'], $response['title']); } public function testGetSingleDocumentWithFields(): void @@ -182,9 +182,9 @@ public function testGetSingleDocumentWithFields(): void $doc = $this->findDocumentWithId(self::DOCUMENTS, 4); $response = $index->getDocument($doc['id'], ['title']); - $this->assertIsArray($response); - $this->assertSame($doc['title'], $response['title']); - $this->assertArrayNotHasKey('id', $response); + self::assertIsArray($response); + self::assertSame($doc['title'], $response['title']); + self::assertArrayNotHasKey('id', $response); } public function testGetSingleDocumentWithStringDocumentId(): void @@ -195,8 +195,8 @@ public function testGetSingleDocumentWithStringDocumentId(): void $index->waitForTask($addDocumentResponse['taskUid']); $response = $index->getDocument($stringDocumentId); - $this->assertIsArray($response); - $this->assertSame($stringDocumentId, $response['id']); + self::assertIsArray($response); + self::assertSame($stringDocumentId, $response['id']); } public function testReplaceDocuments(): void @@ -215,11 +215,11 @@ public function testReplaceDocuments(): void $index->waitForTask($response['taskUid']); $response = $index->getDocument($replacement['id']); - $this->assertSame($replacement['id'], $response['id']); - $this->assertSame($replacement['title'], $response['title']); - $this->assertFalse(array_search('comment', $response, true)); + self::assertSame($replacement['id'], $response['id']); + self::assertSame($replacement['title'], $response['title']); + self::assertFalse(array_search('comment', $response, true)); $response = $index->getDocuments(); - $this->assertCount(\count(self::DOCUMENTS), $response); + self::assertCount(\count(self::DOCUMENTS), $response); } public function testUpdateDocuments(): void @@ -238,13 +238,13 @@ public function testUpdateDocuments(): void $index->waitForTask($promise['taskUid']); $response = $index->getDocument($replacement['id']); - $this->assertSame($replacement['id'], $response['id']); - $this->assertSame($replacement['title'], $response['title']); - $this->assertArrayHasKey('comment', $response); + self::assertSame($replacement['id'], $response['id']); + self::assertSame($replacement['title'], $response['title']); + self::assertArrayHasKey('comment', $response); $response = $index->getDocuments(); - $this->assertCount(\count(self::DOCUMENTS), $response); + self::assertCount(\count(self::DOCUMENTS), $response); } public function testUpdateDocumentsInBatches(): void @@ -262,7 +262,7 @@ public function testUpdateDocumentsInBatches(): void ['id' => 456, 'title' => 'The Little Prince'], ]; $promises = $index->updateDocumentsInBatches($replacements, 4); - $this->assertCount(2, $promises); + self::assertCount(2, $promises); foreach ($promises as $promise) { $this->assertIsValidPromise($promise); @@ -271,13 +271,13 @@ public function testUpdateDocumentsInBatches(): void foreach ($replacements as $replacement) { $response = $index->getDocument($replacement['id']); - $this->assertSame($replacement['id'], $response['id']); - $this->assertSame($replacement['title'], $response['title']); - $this->assertArrayHasKey('comment', $response); + self::assertSame($replacement['id'], $response['id']); + self::assertSame($replacement['title'], $response['title']); + self::assertArrayHasKey('comment', $response); } $response = $index->getDocuments(); - $this->assertCount(\count(self::DOCUMENTS), $response); + self::assertCount(\count(self::DOCUMENTS), $response); } public function testAddDocumentsCsvInBatches(): void @@ -293,7 +293,7 @@ public function testAddDocumentsCsvInBatches(): void $promises = $index->addDocumentsCsvInBatches($documentCsv, 250); - $this->assertCount(2, $promises); + self::assertCount(2, $promises); foreach ($promises as $promise) { $this->assertIsValidPromise($promise); @@ -301,7 +301,7 @@ public function testAddDocumentsCsvInBatches(): void } $response = $index->getDocuments(); - $this->assertSame($total, $response->getTotal()); + self::assertSame($total, $response->getTotal()); } public function testAddDocumentsCsvInBatchesWithDelimiter(): void @@ -316,17 +316,17 @@ public function testAddDocumentsCsvInBatchesWithDelimiter(): void ->disableOriginalConstructor() ->getMock(); - $index->expects($this->exactly(2)) + $index->expects(self::exactly(2)) ->method('addDocumentsCsv') ->willReturnCallback(function (string $documents, $primaryKey, $delimiter): void { static $invocation = 0; // withConsecutive has no replacement https://github.com/sebastianbergmann/phpunit/issues/4026 switch (++$invocation) { case 1: - static::assertSame(["id;title\n888221515;Young folks", null, ';'], [$documents, $primaryKey, $delimiter]); + self::assertSame(["id;title\n888221515;Young folks", null, ';'], [$documents, $primaryKey, $delimiter]); break; case 2: - static::assertSame(["id;title\n235115704;Mister Klein", null, ';'], [$documents, $primaryKey, $delimiter]); + self::assertSame(["id;title\n235115704;Mister Klein", null, ';'], [$documents, $primaryKey, $delimiter]); break; default: self::fail(); @@ -348,7 +348,7 @@ public function testAddDocumentsNdjsonInBatches(): void $promises = $index->addDocumentsNdjsonInBatches($documentNdJson, 150); - $this->assertCount(2, $promises); + self::assertCount(2, $promises); foreach ($promises as $promise) { $this->assertIsValidPromise($promise); @@ -356,7 +356,7 @@ public function testAddDocumentsNdjsonInBatches(): void } $response = $index->getDocuments(); - $this->assertSame($total, $response->getTotal()); + self::assertSame($total, $response->getTotal()); } public function testAddWithUpdateDocuments(): void @@ -375,13 +375,13 @@ public function testAddWithUpdateDocuments(): void $index->waitForTask($promise['taskUid']); $response = $index->getDocument($document['id']); - $this->assertSame($document['id'], $response['id']); - $this->assertSame($document['title'], $response['title']); - $this->assertFalse(array_search('comment', $response, true)); + self::assertSame($document['id'], $response['id']); + self::assertSame($document['title'], $response['title']); + self::assertFalse(array_search('comment', $response, true)); $response = $index->getDocuments(); - $this->assertCount(\count(self::DOCUMENTS) + 1, $response); + self::assertCount(\count(self::DOCUMENTS) + 1, $response); } public function testDeleteNonExistingDocument(): void @@ -398,8 +398,8 @@ public function testDeleteNonExistingDocument(): void $index->waitForTask($promise['taskUid']); $response = $index->getDocuments(); - $this->assertCount(\count(self::DOCUMENTS), $response); - $this->assertNull($this->findDocumentWithId($response, $documentId)); + self::assertCount(\count(self::DOCUMENTS), $response); + self::assertNull($this->findDocumentWithId($response, $documentId)); } public function testDeleteSingleExistingDocumentWithDocumentIdAsInteger(): void @@ -416,8 +416,8 @@ public function testDeleteSingleExistingDocumentWithDocumentIdAsInteger(): void $index->waitForTask($promise['taskUid']); $response = $index->getDocuments(); - $this->assertCount(\count(self::DOCUMENTS) - 1, $response); - $this->assertNull($this->findDocumentWithId($response, $documentId)); + self::assertCount(\count(self::DOCUMENTS) - 1, $response); + self::assertNull($this->findDocumentWithId($response, $documentId)); } public function testDeleteSingleExistingDocumentWithDocumentIdAsString(): void @@ -432,7 +432,7 @@ public function testDeleteSingleExistingDocumentWithDocumentIdAsString(): void $response = $index->getDocuments(); - $this->assertEmpty($response); + self::assertEmpty($response); } public function testDeleteMultipleDocumentsWithDocumentIdAsInteger(): void @@ -448,9 +448,9 @@ public function testDeleteMultipleDocumentsWithDocumentIdAsInteger(): void $index->waitForTask($promise['taskUid']); $response = $index->getDocuments(); - $this->assertCount(\count(self::DOCUMENTS) - 2, $response); - $this->assertNull($this->findDocumentWithId($response, $documentIds[0])); - $this->assertNull($this->findDocumentWithId($response, $documentIds[1])); + self::assertCount(\count(self::DOCUMENTS) - 2, $response); + self::assertNull($this->findDocumentWithId($response, $documentIds[0])); + self::assertNull($this->findDocumentWithId($response, $documentIds[1])); } public function testDeleteMultipleDocumentsWithFilter(): void @@ -467,7 +467,7 @@ public function testDeleteMultipleDocumentsWithFilter(): void $index->waitForTask($promise['taskUid']); $response = $index->getDocuments(); - $this->assertEmpty($response); + self::assertEmpty($response); } public function testMessageHintException(): void @@ -487,8 +487,8 @@ public function testMessageHintException(): void } catch (\Exception $ex) { $rethrowed = ApiException::rethrowWithHint($mockedException, 'deleteDocuments'); - $this->assertSame($ex->getPrevious()->getMessage(), 'Invalid response'); - $this->assertSame($ex->getMessage(), $rethrowed->getMessage()); + self::assertSame('Invalid response', $ex->getPrevious()->getMessage()); + self::assertSame($rethrowed->getMessage(), $ex->getMessage()); } } @@ -507,8 +507,8 @@ public function testDeleteMultipleDocumentsWithDocumentIdAsString(): void $index->waitForTask($promise['taskUid']); $response = $index->getDocuments(); - $this->assertCount(1, $response); - $this->assertSame([['id' => 'myUniqueId2']], $response->getResults()); + self::assertCount(1, $response); + self::assertSame([['id' => 'myUniqueId2']], $response->getResults()); } public function testDeleteAllDocuments(): void @@ -523,7 +523,7 @@ public function testDeleteAllDocuments(): void $index->waitForTask($promise['taskUid']); $response = $index->getDocuments(); - $this->assertCount(0, $response); + self::assertCount(0, $response); } public function testExceptionIfNoDocumentIdWhenGetting(): void @@ -547,11 +547,11 @@ public function testAddDocumentWithPrimaryKey(): void $index = $this->createEmptyIndex($this->safeIndexName('movies-1')); $response = $index->addDocuments($documents, 'unique'); - $this->assertArrayHasKey('taskUid', $response); + self::assertArrayHasKey('taskUid', $response); $index->waitForTask($response['taskUid']); - $this->assertSame('unique', $index->fetchPrimaryKey()); - $this->assertCount(1, $index->getDocuments()); + self::assertSame('unique', $index->fetchPrimaryKey()); + self::assertCount(1, $index->getDocuments()); } public function testUpdateDocumentWithPrimaryKey(): void @@ -570,8 +570,8 @@ public function testUpdateDocumentWithPrimaryKey(): void $index->waitForTask($promise['taskUid']); - $this->assertSame('unique', $index->fetchPrimaryKey()); - $this->assertCount(1, $index->getDocuments()); + self::assertSame('unique', $index->fetchPrimaryKey()); + self::assertCount(1, $index->getDocuments()); } public function testGetDocumentsWithPagination(): void @@ -583,7 +583,7 @@ public function testGetDocumentsWithPagination(): void $response = $index->getDocuments((new DocumentsQuery())->setLimit(3)); - $this->assertCount(3, $response); + self::assertCount(3, $response); } public function testGetDocumentsWithFilter(): void @@ -595,7 +595,7 @@ public function testGetDocumentsWithFilter(): void $response = $index->getDocuments((new DocumentsQuery())->setFilter(['id > 100'])); - $this->assertCount(3, $response); + self::assertCount(3, $response); } public function testGetDocumentsWithFilterCorrectFieldFormat(): void @@ -607,7 +607,7 @@ public function testGetDocumentsWithFilterCorrectFieldFormat(): void ->setFilter(['id > 100']) ->toArray()['fields']; - $this->assertEquals($fields, $queryFields); + self::assertSame($fields, $queryFields); } public function testGetDocumentsWithoutFilterCorrectFieldsFormat(): void @@ -618,7 +618,7 @@ public function testGetDocumentsWithoutFilterCorrectFieldsFormat(): void ->setFields($fields) ->toArray()['fields']; - $this->assertEquals( + self::assertSame( implode(',', $fields), $queryFields ); @@ -641,8 +641,8 @@ public function testGetDocumentsMessageHintException(): void } catch (\Exception $ex) { $rethrowed = ApiException::rethrowWithHint($mockedException, 'getDocuments'); - $this->assertSame($ex->getPrevious()->getMessage(), 'Invalid response'); - $this->assertSame($ex->getMessage(), $rethrowed->getMessage()); + self::assertSame('Invalid response', $ex->getPrevious()->getMessage()); + self::assertSame($rethrowed->getMessage(), $ex->getMessage()); } } @@ -669,12 +669,12 @@ public function testUpdateDocumentsJson(): void $response = $index->getDocument($replacement[0]['id']); - $this->assertSame($replacement[0]['id'], $response['id']); - $this->assertSame($replacement[0]['title'], $response['title']); + self::assertSame($replacement[0]['id'], $response['id']); + self::assertSame($replacement[0]['title'], $response['title']); $documents = $index->getDocuments(); - $this->assertCount(20, $documents); + self::assertCount(20, $documents); } public function testUpdateDocumentsCsv(): void @@ -696,12 +696,12 @@ public function testUpdateDocumentsCsv(): void $response = $index->getDocument(888221515); - $this->assertSame(888221515, (int) $response['id']); - $this->assertSame('Young folks', $response['title']); + self::assertSame(888221515, (int) $response['id']); + self::assertSame('Young folks', $response['title']); $documents = $index->getDocuments(); - $this->assertSame(499, $documents->getTotal()); + self::assertSame(499, $documents->getTotal()); } public function testUpdateDocumentsCsvWithDelimiter(): void @@ -721,8 +721,8 @@ public function testUpdateDocumentsCsvWithDelimiter(): void $response = $index->getDocument(888221515); - $this->assertSame(888221515, (int) $response['id']); - $this->assertSame('Young folks', $response['title']); + self::assertSame(888221515, (int) $response['id']); + self::assertSame('Young folks', $response['title']); } public function testUpdateDocumentsNdjson(): void @@ -743,16 +743,16 @@ public function testUpdateDocumentsNdjson(): void $index->waitForTask($promise['taskUid']); $response = $index->getDocument(412559401); - $this->assertSame(412559401, (int) $response['id']); - $this->assertSame('WASPTHOVEN', $response['title']); + self::assertSame(412559401, (int) $response['id']); + self::assertSame('WASPTHOVEN', $response['title']); $response = $index->getDocument(70764404); - $this->assertSame(70764404, (int) $response['id']); - $this->assertSame('Ailitp', $response['artist']); + self::assertSame(70764404, (int) $response['id']); + self::assertSame('Ailitp', $response['artist']); $documents = $index->getDocuments(); - $this->assertSame(225, $documents->getTotal()); + self::assertSame(225, $documents->getTotal()); } public function testUpdateDocumentsCsvInBatches(): void @@ -769,24 +769,23 @@ public function testUpdateDocumentsCsvInBatches(): void $replacement .= '235115704,Mister Klein'.PHP_EOL; $promises = $index->updateDocumentsCsvInBatches($replacement, 1); - $this->assertCount(2, $promises); + self::assertCount(2, $promises); foreach ($promises as $promise) { $this->assertIsValidPromise($promise); $index->waitForTask($promise['taskUid']); } $response = $index->getDocument(888221515); - $this->assertSame(888221515, (int) $response['id']); - $this->assertSame('Young folks', $response['title']); + self::assertSame(888221515, (int) $response['id']); + self::assertSame('Young folks', $response['title']); $response = $index->getDocument(235115704); - $this->assertSame(235115704, (int) $response['id']); - $this->assertSame('Mister Klein', $response['title']); + self::assertSame(235115704, (int) $response['id']); + self::assertSame('Mister Klein', $response['title']); } public function testUpdateDocumentsCsvInBatchesWithDelimiter(): void { - $matcher = $this->atLeastOnce(); $replacement = 'id;title'.PHP_EOL; $replacement .= '888221515;Young folks'.PHP_EOL; $replacement .= '235115704;Mister Klein'.PHP_EOL; @@ -797,22 +796,22 @@ public function testUpdateDocumentsCsvInBatchesWithDelimiter(): void ->disableOriginalConstructor() ->getMock(); - $index->expects($matcher) + $index->expects(self::atLeastOnce()) ->method('updateDocumentsCsv') - ->willReturnCallback(function (string $param) use ($matcher): void { + ->willReturnCallback(function (string $documents, $primaryKey, $delimiter): void { + static $invocation = 0; // withConsecutive has no replacement https://github.com/sebastianbergmann/phpunit/issues/4026 - switch ($matcher->numberOfInvocations()) { + switch (++$invocation) { case 1: - $this->assertEquals($param, ["id;title\n888221515;Young folks", null, ';']); + self::assertSame(["id;title\n888221515;Young folks", null, ';'], [$documents, $primaryKey, $delimiter]); break; case 2: - $this->assertEquals($param, ["id;title\n235115704;Mister Klein", null, ';']); + self::assertSame(["id;title\n235115704;Mister Klein", null, ';'], [$documents, $primaryKey, $delimiter]); break; default: self::fail(); } - }) - ->willReturn([], []); + }); $index->updateDocumentsCsvInBatches($replacement, 1, null, ';'); } @@ -832,19 +831,19 @@ public function testUpdateDocumentsNdjsonInBatches(): void $replacement .= json_encode(['id' => 70764404, 'artist' => 'Ailitp']).PHP_EOL; $promises = $index->updateDocumentsNdjsonInBatches($replacement, 1); - $this->assertCount(2, $promises); + self::assertCount(2, $promises); foreach ($promises as $promise) { $this->assertIsValidPromise($promise); $index->waitForTask($promise['taskUid']); } $response = $index->getDocument(412559401); - $this->assertSame(412559401, (int) $response['id']); - $this->assertSame('WASPTHOVEN', $response['title']); + self::assertSame(412559401, (int) $response['id']); + self::assertSame('WASPTHOVEN', $response['title']); $response = $index->getDocument(70764404); - $this->assertSame(70764404, (int) $response['id']); - $this->assertSame('Ailitp', $response['artist']); + self::assertSame(70764404, (int) $response['id']); + self::assertSame('Ailitp', $response['artist']); } /** diff --git a/tests/Endpoints/DumpTest.php b/tests/Endpoints/DumpTest.php index b90dcfd5..ee18ff7c 100644 --- a/tests/Endpoints/DumpTest.php +++ b/tests/Endpoints/DumpTest.php @@ -14,6 +14,6 @@ public function testCreateDump(): void $task = $this->client->createDump(); - $this->assertEquals($expectedKeys, array_keys($task)); + self::assertSame($expectedKeys, array_keys($task)); } } diff --git a/tests/Endpoints/FacetSearchTest.php b/tests/Endpoints/FacetSearchTest.php index 8bef6ffa..21fdb8e0 100644 --- a/tests/Endpoints/FacetSearchTest.php +++ b/tests/Endpoints/FacetSearchTest.php @@ -26,9 +26,7 @@ public function testBasicSearchWithFilters(): void { $response = $this->index->search('prince', ['facets' => ['genre']]); - $this->assertSame(array_keys($response->getFacetDistribution()['genre']), [ - 'adventure', 'fantasy', - ]); + self::assertSame(['adventure', 'fantasy'], array_keys($response->getFacetDistribution()['genre'])); $response = $this->index->facetSearch( (new FacetSearchQuery()) @@ -37,6 +35,6 @@ public function testBasicSearchWithFilters(): void ->setQuery('prince') ); - $this->assertSame(array_column($response->getFacetHits(), 'value'), ['fantasy']); + self::assertSame(['fantasy'], array_column($response->getFacetHits(), 'value')); } } diff --git a/tests/Endpoints/IndexTest.php b/tests/Endpoints/IndexTest.php index faf2df63..0bc98960 100644 --- a/tests/Endpoints/IndexTest.php +++ b/tests/Endpoints/IndexTest.php @@ -24,24 +24,24 @@ protected function setUp(): void public function testIndexGetSettings(): void { - $this->assertSame([], $this->index->getSynonyms()); - $this->assertSame([], $this->index->getStopWords()); - $this->assertSame([], $this->index->getSortableAttributes()); - $this->assertSame(['*'], $this->index->getSearchableAttributes()); - $this->assertSame( + self::assertSame([], $this->index->getSynonyms()); + self::assertSame([], $this->index->getStopWords()); + self::assertSame([], $this->index->getSortableAttributes()); + self::assertSame(['*'], $this->index->getSearchableAttributes()); + self::assertSame( ['words', 'typo', 'proximity', 'attribute', 'sort', 'exactness'], $this->index->getRankingRules() ); - $this->assertSame([], $this->index->getFilterableAttributes()); - $this->assertSame(['*'], $this->index->getDisplayedAttributes()); - $this->assertSame([ + self::assertSame([], $this->index->getFilterableAttributes()); + self::assertSame(['*'], $this->index->getDisplayedAttributes()); + self::assertSame([ 'maxValuesPerFacet' => 100, 'sortFacetValuesBy' => [ '*' => 'alpha', ], ], $this->index->getFaceting()); - $this->assertSame(['maxTotalHits' => 1000], $this->index->getPagination()); - $this->assertSame( + self::assertSame(['maxTotalHits' => 1000], $this->index->getPagination()); + self::assertSame( [ 'enabled' => true, 'minWordSizeForTypos' => ['oneTypo' => 5, 'twoTypos' => 9], @@ -50,7 +50,7 @@ public function testIndexGetSettings(): void ], $this->index->getTypoTolerance(), ); - $this->assertSame([], $this->index->getDictionary()); + self::assertSame([], $this->index->getDictionary()); } public function testGetPrimaryKey(): void @@ -60,8 +60,8 @@ public function testGetPrimaryKey(): void ['primaryKey' => 'objectId'] ); - $this->assertNull($this->index->getPrimaryKey()); - $this->assertSame('objectId', $index->getPrimaryKey()); + self::assertNull($this->index->getPrimaryKey()); + self::assertSame('objectId', $index->getPrimaryKey()); } public function testGetUid(): void @@ -71,24 +71,24 @@ public function testGetUid(): void $indexName, ['primaryKey' => 'objectId'] ); - $this->assertSame($this->indexName, $this->index->getUid()); - $this->assertSame($indexName, $index->getUid()); + self::assertSame($this->indexName, $this->index->getUid()); + self::assertSame($indexName, $index->getUid()); } public function testGetCreatedAt(): void { $indexB = $this->client->index('indexB'); - $this->assertNull($indexB->getCreatedAt()); - $this->assertInstanceOf(\DateTimeInterface::class, $this->index->getCreatedAt()); + self::assertNull($indexB->getCreatedAt()); + self::assertInstanceOf(\DateTimeInterface::class, $this->index->getCreatedAt()); } public function testGetUpdatedAt(): void { $indexB = $this->client->index('indexB'); - $this->assertNull($indexB->getUpdatedAt()); - $this->assertInstanceOf(\DateTimeInterface::class, $this->index->getUpdatedAt()); + self::assertNull($indexB->getUpdatedAt()); + self::assertInstanceOf(\DateTimeInterface::class, $this->index->getUpdatedAt()); } public function testFetchRawInfo(): void @@ -101,12 +101,12 @@ public function testFetchRawInfo(): void $response = $index->fetchRawInfo(); - $this->assertArrayHasKey('primaryKey', $response); - $this->assertArrayHasKey('uid', $response); - $this->assertArrayHasKey('createdAt', $response); - $this->assertArrayHasKey('updatedAt', $response); - $this->assertSame($response['primaryKey'], 'objectId'); - $this->assertSame($response['uid'], $indexName); + self::assertArrayHasKey('primaryKey', $response); + self::assertArrayHasKey('uid', $response); + self::assertArrayHasKey('createdAt', $response); + self::assertArrayHasKey('updatedAt', $response); + self::assertSame('objectId', $response['primaryKey']); + self::assertSame($indexName, $response['uid']); } public function testPrimaryKeyUpdate(): void @@ -117,20 +117,19 @@ public function testPrimaryKeyUpdate(): void $this->client->waitForTask($response['taskUid']); $index = $this->client->getIndex($response['indexUid']); - $this->assertSame($index->getPrimaryKey(), $primaryKey); - $this->assertSame($index->getUid(), $this->indexName); - $this->assertSame($index->getPrimaryKey(), $primaryKey); - $this->assertSame($this->index->getUid(), $this->indexName); + self::assertSame($primaryKey, $index->getPrimaryKey()); + self::assertSame($this->indexName, $index->getUid()); + self::assertSame($this->indexName, $this->index->getUid()); } public function testIndexStats(): void { $stats = $this->index->stats(); - $this->assertArrayHasKey('numberOfDocuments', $stats); - $this->assertEquals(0, $stats['numberOfDocuments']); - $this->assertArrayHasKey('isIndexing', $stats); - $this->assertArrayHasKey('fieldDistribution', $stats); + self::assertArrayHasKey('numberOfDocuments', $stats); + self::assertSame(0, $stats['numberOfDocuments']); + self::assertArrayHasKey('isIndexing', $stats); + self::assertArrayHasKey('fieldDistribution', $stats); } public function testFetchInfo(): void @@ -142,13 +141,13 @@ public function testFetchInfo(): void ); $index = $this->client->index($indexName); - $this->assertNull($index->getPrimaryKey()); + self::assertNull($index->getPrimaryKey()); $index = $index->fetchInfo(); - $this->assertSame('objectID', $index->getPrimaryKey()); - $this->assertSame($indexName, $index->getUid()); - $this->assertInstanceOf(\DateTimeInterface::class, $index->getCreatedAt()); - $this->assertInstanceOf(\DateTimeInterface::class, $index->getUpdatedAt()); + self::assertSame('objectID', $index->getPrimaryKey()); + self::assertSame($indexName, $index->getUid()); + self::assertInstanceOf(\DateTimeInterface::class, $index->getCreatedAt()); + self::assertInstanceOf(\DateTimeInterface::class, $index->getUpdatedAt()); } public function testGetAndFetchPrimaryKey(): void @@ -160,9 +159,9 @@ public function testGetAndFetchPrimaryKey(): void ); $index = $this->client->index($indexName); - $this->assertNull($index->getPrimaryKey()); - $this->assertSame('objectID', $index->fetchPrimaryKey()); - $this->assertSame('objectID', $index->getPrimaryKey()); + self::assertNull($index->getPrimaryKey()); + self::assertSame('objectID', $index->fetchPrimaryKey()); + self::assertSame('objectID', $index->getPrimaryKey()); } public function testGetTasks(): void @@ -180,7 +179,7 @@ public function testGetTasks(): void $results = array_unique($allIndexUids); $expected = [$this->index->getUid(), 'other-index']; - $this->assertSame($expected, $results); + self::assertSame($expected, $results); } public function testWaitForTaskDefault(): void @@ -190,14 +189,14 @@ public function testWaitForTaskDefault(): void $response = $this->index->waitForTask($promise['taskUid']); /* @phpstan-ignore-next-line */ - $this->assertIsArray($response); - $this->assertSame($response['status'], 'succeeded'); - $this->assertSame($response['uid'], $promise['taskUid']); - $this->assertArrayHasKey('type', $response); - $this->assertSame($response['type'], 'documentAdditionOrUpdate'); - $this->assertArrayHasKey('duration', $response); - $this->assertArrayHasKey('startedAt', $response); - $this->assertArrayHasKey('finishedAt', $response); + self::assertIsArray($response); + self::assertSame('succeeded', $response['status']); + self::assertSame($response['uid'], $promise['taskUid']); + self::assertArrayHasKey('type', $response); + self::assertSame('documentAdditionOrUpdate', $response['type']); + self::assertArrayHasKey('duration', $response); + self::assertArrayHasKey('startedAt', $response); + self::assertArrayHasKey('finishedAt', $response); } public function testWaitForTaskWithTimeoutAndInterval(): void @@ -205,14 +204,14 @@ public function testWaitForTaskWithTimeoutAndInterval(): void $promise = $this->index->addDocuments([['id' => 1, 'title' => 'Pride and Prejudice']]); $response = $this->index->waitForTask($promise['taskUid'], 100, 20); - $this->assertSame($response['status'], 'succeeded'); - $this->assertSame($response['uid'], $promise['taskUid']); - $this->assertArrayHasKey('type', $response); - $this->assertSame($response['type'], 'documentAdditionOrUpdate'); - $this->assertArrayHasKey('duration', $response); - $this->assertArrayHasKey('enqueuedAt', $response); - $this->assertArrayHasKey('startedAt', $response); - $this->assertArrayHasKey('finishedAt', $response); + self::assertSame('succeeded', $response['status']); + self::assertSame($response['uid'], $promise['taskUid']); + self::assertArrayHasKey('type', $response); + self::assertSame('documentAdditionOrUpdate', $response['type']); + self::assertArrayHasKey('duration', $response); + self::assertArrayHasKey('enqueuedAt', $response); + self::assertArrayHasKey('startedAt', $response); + self::assertArrayHasKey('finishedAt', $response); } public function testWaitForTaskWithTimeout(): void @@ -220,14 +219,14 @@ public function testWaitForTaskWithTimeout(): void $promise = $this->index->addDocuments([['id' => 1, 'title' => 'Pride and Prejudice']]); $response = $this->index->waitForTask($promise['taskUid'], 100); - $this->assertSame($response['status'], 'succeeded'); - $this->assertSame($response['uid'], $promise['taskUid']); - $this->assertArrayHasKey('type', $response); - $this->assertSame($response['type'], 'documentAdditionOrUpdate'); - $this->assertArrayHasKey('duration', $response); - $this->assertArrayHasKey('enqueuedAt', $response); - $this->assertArrayHasKey('startedAt', $response); - $this->assertArrayHasKey('finishedAt', $response); + self::assertSame('succeeded', $response['status']); + self::assertSame($response['uid'], $promise['taskUid']); + self::assertArrayHasKey('type', $response); + self::assertSame('documentAdditionOrUpdate', $response['type']); + self::assertArrayHasKey('duration', $response); + self::assertArrayHasKey('enqueuedAt', $response); + self::assertArrayHasKey('startedAt', $response); + self::assertArrayHasKey('finishedAt', $response); } public function testExceptionWhenTaskTimeOut(): void @@ -245,16 +244,16 @@ public function testDeleteIndexes(): void $index = $this->createEmptyIndex($indexName2); $res = $this->index->delete(); - $this->assertSame($res['indexUid'], $indexName1); - $this->assertArrayHasKey('type', $res); - $this->assertSame($res['type'], 'indexDeletion'); - $this->assertArrayHasKey('enqueuedAt', $res); + self::assertSame($indexName1, $res['indexUid']); + self::assertArrayHasKey('type', $res); + self::assertSame('indexDeletion', $res['type']); + self::assertArrayHasKey('enqueuedAt', $res); $res = $index->delete(); - $this->assertSame($res['indexUid'], $indexName2); - $this->assertArrayHasKey('type', $res); - $this->assertSame($res['type'], 'indexDeletion'); - $this->assertArrayHasKey('enqueuedAt', $res); + self::assertSame($indexName2, $res['indexUid']); + self::assertArrayHasKey('type', $res); + self::assertSame('indexDeletion', $res['type']); + self::assertArrayHasKey('enqueuedAt', $res); } public function testSwapIndexes(): void @@ -262,7 +261,7 @@ public function testSwapIndexes(): void $promise = $this->client->swapIndexes([['indexA', 'indexB'], ['indexC', 'indexD']]); $response = $this->client->waitForTask($promise['taskUid']); - $this->assertSame($response['details']['swaps'], [['indexes' => ['indexA', 'indexB']], ['indexes' => ['indexC', 'indexD']]]); + self::assertSame([['indexes' => ['indexA', 'indexB']], ['indexes' => ['indexC', 'indexD']]], $response['details']['swaps']); } public function testDeleteTasks(): void @@ -270,8 +269,8 @@ public function testDeleteTasks(): void $promise = $this->client->deleteTasks((new DeleteTasksQuery())->setUids([1, 2])); $response = $this->client->waitForTask($promise['taskUid']); - $this->assertSame($response['details']['originalFilter'], '?uids=1%2C2'); - $this->assertIsNumeric($response['details']['matchedTasks']); + self::assertSame('?uids=1%2C2', $response['details']['originalFilter']); + self::assertIsNumeric($response['details']['matchedTasks']); } public function testParseDate(): void @@ -280,8 +279,8 @@ public function testParseDate(): void $dateTime = Indexes::parseDate($date); $formattedDate = '2021-01-01T01:23:45.123456+00:00'; - $this->assertInstanceOf(\DateTimeInterface::class, $dateTime); - $this->assertSame($formattedDate, $dateTime->format('Y-m-d\TH:i:s.uP')); + self::assertInstanceOf(\DateTimeInterface::class, $dateTime); + self::assertSame($formattedDate, $dateTime->format('Y-m-d\TH:i:s.uP')); } public function testParseDateWithExtraFractionalSeconds(): void @@ -290,14 +289,14 @@ public function testParseDateWithExtraFractionalSeconds(): void $dateTime = Indexes::parseDate($date); $formattedDate = '2021-01-01T01:23:45.123456+00:00'; - $this->assertInstanceOf(\DateTimeInterface::class, $dateTime); - $this->assertSame($formattedDate, $dateTime->format('Y-m-d\TH:i:s.uP')); + self::assertInstanceOf(\DateTimeInterface::class, $dateTime); + self::assertSame($formattedDate, $dateTime->format('Y-m-d\TH:i:s.uP')); } public function testParseDateWhenNull(): void { $dateTime = Indexes::parseDate(null); - $this->assertNull($dateTime); + self::assertNull($dateTime); } } diff --git a/tests/Endpoints/KeysAndPermissionsTest.php b/tests/Endpoints/KeysAndPermissionsTest.php index 89f4e85b..f596de7e 100644 --- a/tests/Endpoints/KeysAndPermissionsTest.php +++ b/tests/Endpoints/KeysAndPermissionsTest.php @@ -14,37 +14,37 @@ final class KeysAndPermissionsTest extends TestCase public function testGetRawKeysAlwaysReturnsArray(): void { /* @phpstan-ignore-next-line */ - $this->assertIsArray($this->client->getRawKeys()); + self::assertIsArray($this->client->getRawKeys()); } public function testGetKeysAlwaysReturnsArray(): void { /* @phpstan-ignore-next-line */ - $this->assertIsIterable($this->client->getKeys()); + self::assertIsIterable($this->client->getKeys()); } public function testGetKeysDefault(): void { $response = $this->client->getKeys(); - $this->assertGreaterThan(0, $response->count()); - $this->assertIsArray($response[0]->getActions()); - $this->assertIsArray($response[0]->getIndexes()); - $this->assertNull($response[0]->getExpiresAt()); - $this->assertNotNull($response[0]->getCreatedAt()); - $this->assertNotNull($response[0]->getUpdatedAt()); + self::assertGreaterThan(0, $response->count()); + self::assertIsArray($response[0]->getActions()); + self::assertIsArray($response[0]->getIndexes()); + self::assertNull($response[0]->getExpiresAt()); + self::assertNotNull($response[0]->getCreatedAt()); + self::assertNotNull($response[0]->getUpdatedAt()); } public function testGetRawKeysDefault(): void { $response = $this->client->getRawKeys(); - $this->assertGreaterThan(2, $response['results']); - $this->assertArrayHasKey('actions', $response['results'][0]); - $this->assertArrayHasKey('indexes', $response['results'][0]); - $this->assertArrayHasKey('createdAt', $response['results'][0]); - $this->assertArrayHasKey('expiresAt', $response['results'][0]); - $this->assertArrayHasKey('updatedAt', $response['results'][0]); + self::assertGreaterThan(2, $response['results']); + self::assertArrayHasKey('actions', $response['results'][0]); + self::assertArrayHasKey('indexes', $response['results'][0]); + self::assertArrayHasKey('createdAt', $response['results'][0]); + self::assertArrayHasKey('expiresAt', $response['results'][0]); + self::assertArrayHasKey('updatedAt', $response['results'][0]); } public function testExceptionIfNoMasterKeyProvided(): void @@ -60,7 +60,7 @@ public function testExceptionIfBadKeyProvidedToGetSettings(): void $index = $this->safeIndexName(); $this->createEmptyIndex($index); $response = $this->client->index($index)->getSettings(); - $this->assertEquals(['*'], $response['searchableAttributes']); + self::assertSame(['*'], $response['searchableAttributes']); $newClient = new Client($this->host, 'bad-key'); @@ -79,14 +79,14 @@ public function testGetKeysWithLimit(): void { $response = $this->client->getKeys((new KeysQuery())->setLimit(1)); - $this->assertCount(1, $response); + self::assertCount(1, $response); } public function testGetKeysWithOffset(): void { $response = $this->client->getKeys((new KeysQuery())->setOffset(100)); - $this->assertCount(0, $response); + self::assertCount(0, $response); } public function testGetKey(): void @@ -94,13 +94,13 @@ public function testGetKey(): void $key = $this->client->createKey(self::INFO_KEY); $response = $this->client->getKey($key->getKey()); - $this->assertNotNull($response->getKey()); - $this->assertNull($response->getDescription()); - $this->assertIsArray($response->getActions()); - $this->assertIsArray($response->getIndexes()); - $this->assertNull($response->getExpiresAt()); - $this->assertNotNull($response->getCreatedAt()); - $this->assertNotNull($response->getUpdatedAt()); + self::assertNotNull($response->getKey()); + self::assertNull($response->getDescription()); + self::assertIsArray($response->getActions()); + self::assertIsArray($response->getIndexes()); + self::assertNull($response->getExpiresAt()); + self::assertNotNull($response->getCreatedAt()); + self::assertNotNull($response->getUpdatedAt()); $this->client->deleteKey($key->getKey()); } @@ -115,15 +115,15 @@ public function testCreateKey(): void { $key = $this->client->createKey(self::INFO_KEY); - $this->assertNotNull($key->getKey()); - $this->assertNull($key->getDescription()); - $this->assertIsArray($key->getActions()); - $this->assertSame($key->getActions(), self::INFO_KEY['actions']); - $this->assertIsArray($key->getIndexes()); - $this->assertSame($key->getIndexes(), self::INFO_KEY['indexes']); - $this->assertNull($key->getExpiresAt()); - $this->assertNotNull($key->getCreatedAt()); - $this->assertNotNull($key->getUpdatedAt()); + self::assertNotNull($key->getKey()); + self::assertNull($key->getDescription()); + self::assertIsArray($key->getActions()); + self::assertSame(self::INFO_KEY['actions'], $key->getActions()); + self::assertIsArray($key->getIndexes()); + self::assertSame(self::INFO_KEY['indexes'], $key->getIndexes()); + self::assertNull($key->getExpiresAt()); + self::assertNotNull($key->getCreatedAt()); + self::assertNotNull($key->getUpdatedAt()); $this->client->deleteKey($key->getKey()); } @@ -136,8 +136,8 @@ public function testCreateKeyWithWildcard(): void 'expiresAt' => null, ]); - $this->assertIsArray($key->getActions()); - $this->assertSame($key->getActions(), ['tasks.*', 'indexes.get']); + self::assertIsArray($key->getActions()); + self::assertSame(['tasks.*', 'indexes.get'], $key->getActions()); $this->client->deleteKey($key->getKey()); } @@ -152,16 +152,16 @@ public function testCreateKeyWithExpInString(): void ]; $response = $this->client->createKey($key); - $this->assertNotNull($response->getKey()); - $this->assertNotNull($response->getDescription()); - $this->assertSame($response->getDescription(), 'test create'); - $this->assertIsArray($response->getActions()); - $this->assertSame($response->getActions(), ['search']); - $this->assertIsArray($response->getIndexes()); - $this->assertSame($response->getIndexes(), ['index']); - $this->assertNotNull($response->getExpiresAt()); - $this->assertNotNull($response->getCreatedAt()); - $this->assertNotNull($response->getUpdatedAt()); + self::assertNotNull($response->getKey()); + self::assertNotNull($response->getDescription()); + self::assertSame('test create', $response->getDescription()); + self::assertIsArray($response->getActions()); + self::assertSame(['search'], $response->getActions()); + self::assertIsArray($response->getIndexes()); + self::assertSame(['index'], $response->getIndexes()); + self::assertNotNull($response->getExpiresAt()); + self::assertNotNull($response->getCreatedAt()); + self::assertNotNull($response->getUpdatedAt()); $this->client->deleteKey($response->getKey()); } @@ -176,16 +176,16 @@ public function testCreateKeyWithExpInDate(): void ]; $response = $this->client->createKey($key); - $this->assertNotNull($response->getKey()); - $this->assertNotNull($response->getDescription()); - $this->assertSame($response->getDescription(), 'test create'); - $this->assertIsArray($response->getActions()); - $this->assertSame($response->getActions(), ['search']); - $this->assertIsArray($response->getIndexes()); - $this->assertSame($response->getIndexes(), ['index']); - $this->assertNotNull($response->getExpiresAt()); - $this->assertNotNull($response->getCreatedAt()); - $this->assertNotNull($response->getUpdatedAt()); + self::assertNotNull($response->getKey()); + self::assertNotNull($response->getDescription()); + self::assertSame('test create', $response->getDescription()); + self::assertIsArray($response->getActions()); + self::assertSame(['search'], $response->getActions()); + self::assertIsArray($response->getIndexes()); + self::assertSame(['index'], $response->getIndexes()); + self::assertNotNull($response->getExpiresAt()); + self::assertNotNull($response->getCreatedAt()); + self::assertNotNull($response->getUpdatedAt()); $this->client->deleteKey($response->getKey()); } @@ -207,16 +207,16 @@ public function testUpdateKeyWithExpInString(): void 'description' => 'test update', ]); - $this->assertNotNull($response->getKey()); - $this->assertNotNull($response->getDescription()); - $this->assertSame($response->getDescription(), 'test update'); - $this->assertIsArray($response->getActions()); - $this->assertSame($response->getActions(), self::INFO_KEY['actions']); - $this->assertIsArray($response->getIndexes()); - $this->assertSame($response->getIndexes(), ['index']); - $this->assertNull($response->getExpiresAt()); - $this->assertNotNull($response->getCreatedAt()); - $this->assertNotNull($response->getUpdatedAt()); + self::assertNotNull($response->getKey()); + self::assertNotNull($response->getDescription()); + self::assertSame('test update', $response->getDescription()); + self::assertIsArray($response->getActions()); + self::assertSame(self::INFO_KEY['actions'], $response->getActions()); + self::assertIsArray($response->getIndexes()); + self::assertSame(['index'], $response->getIndexes()); + self::assertNull($response->getExpiresAt()); + self::assertNotNull($response->getCreatedAt()); + self::assertNotNull($response->getUpdatedAt()); $this->client->deleteKey($response->getKey()); } @@ -230,8 +230,8 @@ public function testCreateKeyWithUid(): void 'expiresAt' => null, ]); - $this->assertNotNull($key->getKey()); - $this->assertEquals('acab6d06-5385-47a2-a534-1ed4fd7f6402', $key->getUid()); + self::assertNotNull($key->getKey()); + self::assertSame('acab6d06-5385-47a2-a534-1ed4fd7f6402', $key->getUid()); $this->client->deleteKey($key->getKey()); } @@ -245,16 +245,16 @@ public function testUpdateKeyWithExpInDate(): void 'expiresAt' => date_create_from_format('Y-m-d', date('Y-m-d', strtotime('+1 day'))), ]); - $this->assertNotNull($response->getKey()); - $this->assertNotNull($response->getDescription()); - $this->assertSame($response->getDescription(), 'test update'); - $this->assertIsArray($response->getActions()); - $this->assertSame($response->getActions(), self::INFO_KEY['actions']); - $this->assertIsArray($response->getIndexes()); - $this->assertSame($response->getIndexes(), ['index']); - $this->assertNull($response->getExpiresAt()); - $this->assertNotNull($response->getCreatedAt()); - $this->assertNotNull($response->getUpdatedAt()); + self::assertNotNull($response->getKey()); + self::assertNotNull($response->getDescription()); + self::assertSame('test update', $response->getDescription()); + self::assertIsArray($response->getActions()); + self::assertSame(self::INFO_KEY['actions'], $response->getActions()); + self::assertIsArray($response->getIndexes()); + self::assertSame(['index'], $response->getIndexes()); + self::assertNull($response->getExpiresAt()); + self::assertNotNull($response->getCreatedAt()); + self::assertNotNull($response->getUpdatedAt()); $this->client->deleteKey($response->getKey()); } @@ -322,12 +322,12 @@ public function testDateParsing(): void $response = $newClient->getKeys(); - $this->assertCount(3, $response); + self::assertCount(3, $response); for ($i = 0; $i < 3; ++$i) { - $this->assertNotNull($response[$i]->getExpiresAt(), (string) $i); - $this->assertNotNull($response[$i]->getCreatedAt(), (string) $i); - $this->assertNotNull($response[$i]->getUpdatedAt(), (string) $i); + self::assertNotNull($response[$i]->getExpiresAt(), (string) $i); + self::assertNotNull($response[$i]->getCreatedAt(), (string) $i); + self::assertNotNull($response[$i]->getUpdatedAt(), (string) $i); } } } diff --git a/tests/Endpoints/MultiSearchTest.php b/tests/Endpoints/MultiSearchTest.php index 2b261a04..402d2b59 100644 --- a/tests/Endpoints/MultiSearchTest.php +++ b/tests/Endpoints/MultiSearchTest.php @@ -35,7 +35,7 @@ public function testSearchQueryData(): void { $data = (new SearchQuery())->setIndexUid($this->booksIndex->getUid())->setQuery('butler')->setSort(['author:desc']); - $this->assertEquals([ + self::assertSame([ 'indexUid' => $this->booksIndex->getUid(), 'q' => 'butler', 'sort' => ['author:desc'], @@ -54,24 +54,24 @@ public function testMultiSearch(): void ->setFilter(['duration-float > 3']), ]); - $this->assertCount(2, $response['results']); - - $this->assertArrayHasKey('indexUid', $response['results'][0]); - $this->assertArrayHasKey('hits', $response['results'][0]); - $this->assertArrayHasKey('query', $response['results'][0]); - $this->assertArrayHasKey('limit', $response['results'][0]); - $this->assertArrayHasKey('offset', $response['results'][0]); - $this->assertArrayHasKey('estimatedTotalHits', $response['results'][0]); - $this->assertCount(2, $response['results'][0]['hits']); - - $this->assertArrayHasKey('indexUid', $response['results'][0]); - $this->assertArrayHasKey('hits', $response['results'][1]); - $this->assertArrayHasKey('query', $response['results'][1]); - $this->assertArrayHasKey('page', $response['results'][1]); - $this->assertArrayHasKey('hitsPerPage', $response['results'][1]); - $this->assertArrayHasKey('totalHits', $response['results'][1]); - $this->assertArrayHasKey('totalPages', $response['results'][1]); - $this->assertCount(1, $response['results'][1]['hits']); + self::assertCount(2, $response['results']); + + self::assertArrayHasKey('indexUid', $response['results'][0]); + self::assertArrayHasKey('hits', $response['results'][0]); + self::assertArrayHasKey('query', $response['results'][0]); + self::assertArrayHasKey('limit', $response['results'][0]); + self::assertArrayHasKey('offset', $response['results'][0]); + self::assertArrayHasKey('estimatedTotalHits', $response['results'][0]); + self::assertCount(2, $response['results'][0]['hits']); + + self::assertArrayHasKey('indexUid', $response['results'][0]); + self::assertArrayHasKey('hits', $response['results'][1]); + self::assertArrayHasKey('query', $response['results'][1]); + self::assertArrayHasKey('page', $response['results'][1]); + self::assertArrayHasKey('hitsPerPage', $response['results'][1]); + self::assertArrayHasKey('totalHits', $response['results'][1]); + self::assertArrayHasKey('totalPages', $response['results'][1]); + self::assertCount(1, $response['results'][1]['hits']); } public function testSupportedQueryParams(): void @@ -85,9 +85,9 @@ public function testSupportedQueryParams(): void $result = $query->toArray(); - $this->assertEquals([1, 0.9, [0.9874]], $result['vector']); - $this->assertEquals(['comment'], $result['attributesToSearchOn']); - $this->assertEquals(true, $result['showRankingScore']); - $this->assertEquals(true, $result['showRankingScoreDetails']); + self::assertSame([1, 0.9, [0.9874]], $result['vector']); + self::assertSame(['comment'], $result['attributesToSearchOn']); + self::assertTrue($result['showRankingScore']); + self::assertTrue($result['showRankingScoreDetails']); } } diff --git a/tests/Endpoints/SearchTest.php b/tests/Endpoints/SearchTest.php index de962d60..04ece4bd 100644 --- a/tests/Endpoints/SearchTest.php +++ b/tests/Endpoints/SearchTest.php @@ -26,15 +26,15 @@ public function testBasicSearch(): void $response = $this->index->search('prince'); $this->assertEstimatedPagination($response->toArray()); - $this->assertSame(2, $response->getEstimatedTotalHits()); - $this->assertCount(2, $response->getHits()); + self::assertSame(2, $response->getEstimatedTotalHits()); + self::assertCount(2, $response->getHits()); $response = $this->index->search('prince', [], [ 'raw' => true, ]); $this->assertEstimatedPagination($response); - $this->assertSame(2, $response['estimatedTotalHits']); + self::assertSame(2, $response['estimatedTotalHits']); } public function testBasicSearchWithFinitePagination(): void @@ -42,7 +42,7 @@ public function testBasicSearchWithFinitePagination(): void $response = $this->index->search('prince', ['hitsPerPage' => 2]); $this->assertFinitePagination($response->toArray()); - $this->assertCount(2, $response->getHits()); + self::assertCount(2, $response->getHits()); $response = $this->index->search('prince', ['hitsPerPage' => 2], [ 'raw' => true, @@ -56,14 +56,14 @@ public function testBasicEmptySearch(): void $response = $this->index->search(''); $this->assertEstimatedPagination($response->toArray()); - $this->assertCount(7, $response->getHits()); + self::assertCount(7, $response->getHits()); $response = $this->index->search('', [], [ 'raw' => true, ]); $this->assertEstimatedPagination($response); - $this->assertSame(7, $response['estimatedTotalHits']); + self::assertSame(7, $response['estimatedTotalHits']); } public function testBasicPlaceholderSearch(): void @@ -71,27 +71,27 @@ public function testBasicPlaceholderSearch(): void $response = $this->index->search(null); $this->assertEstimatedPagination($response->toArray()); - $this->assertCount(\count(self::DOCUMENTS), $response->getHits()); + self::assertCount(\count(self::DOCUMENTS), $response->getHits()); $response = $this->index->search(null, [], [ 'raw' => true, ]); $this->assertEstimatedPagination($response); - $this->assertSame(\count(self::DOCUMENTS), $response['estimatedTotalHits']); + self::assertSame(\count(self::DOCUMENTS), $response['estimatedTotalHits']); } public function testSearchWithOptions(): void { $response = $this->index->search('prince', ['limit' => 1]); - $this->assertCount(1, $response->getHits()); + self::assertCount(1, $response->getHits()); $response = $this->index->search('prince', ['limit' => 1], [ 'raw' => true, ]); - $this->assertCount(1, $response['hits']); + self::assertCount(1, $response['hits']); } public function testBasicSearchIfNoPrimaryKeyAndDocumentProvided(): void @@ -101,14 +101,14 @@ public function testBasicSearchIfNoPrimaryKeyAndDocumentProvided(): void $res = $emptyIndex->search('prince'); $this->assertEstimatedPagination($res->toArray()); - $this->assertCount(0, $res->getHits()); + self::assertCount(0, $res->getHits()); $res = $emptyIndex->search('prince', [], [ 'raw' => true, ]); $this->assertEstimatedPagination($res); - $this->assertSame(0, $res['estimatedTotalHits']); + self::assertSame(0, $res['estimatedTotalHits']); } public function testExceptionIfNoIndexWhenSearching(): void @@ -130,8 +130,8 @@ public function testParametersCropMarker(): void 'cropLength' => 2, ]); - $this->assertArrayHasKey('_formatted', $response->getHit(0)); - $this->assertSame('…Half-Blood…', $response->getHit(0)['_formatted']['title']); + self::assertArrayHasKey('_formatted', $response->getHit(0)); + self::assertSame('…Half-Blood…', $response->getHit(0)['_formatted']['title']); $response = $this->index->search('blood', [ 'limit' => 1, @@ -141,8 +141,8 @@ public function testParametersCropMarker(): void 'raw' => true, ]); - $this->assertArrayHasKey('_formatted', $response['hits'][0]); - $this->assertSame('…Half-Blood…', $response['hits'][0]['_formatted']['title']); + self::assertArrayHasKey('_formatted', $response['hits'][0]); + self::assertSame('…Half-Blood…', $response['hits'][0]['_formatted']['title']); } public function testParametersWithCustomizedCropMarker(): void @@ -154,8 +154,8 @@ public function testParametersWithCustomizedCropMarker(): void 'cropMarker' => '(ꈍᴗꈍ)', ]); - $this->assertArrayHasKey('_formatted', $response->getHit(0)); - $this->assertSame('(ꈍᴗꈍ)Half-Blood Prince', $response->getHit(0)['_formatted']['title']); + self::assertArrayHasKey('_formatted', $response->getHit(0)); + self::assertSame('(ꈍᴗꈍ)Half-Blood Prince', $response->getHit(0)['_formatted']['title']); $response = $this->index->search('blood', [ 'limit' => 1, @@ -166,8 +166,8 @@ public function testParametersWithCustomizedCropMarker(): void 'raw' => true, ]); - $this->assertArrayHasKey('_formatted', $response['hits'][0]); - $this->assertSame('(ꈍᴗꈍ)Half-Blood Prince', $response['hits'][0]['_formatted']['title']); + self::assertArrayHasKey('_formatted', $response['hits'][0]); + self::assertSame('(ꈍᴗꈍ)Half-Blood Prince', $response['hits'][0]['_formatted']['title']); } public function testSearchWithMatchingStrategyALL(): void @@ -179,7 +179,7 @@ public function testSearchWithMatchingStrategyALL(): void 'matchingStrategy' => 'all', ]); - $this->assertCount(1, $response->getHits()); + self::assertCount(1, $response->getHits()); } public function testSearchWithMatchingStrategyLAST(): void @@ -191,7 +191,7 @@ public function testSearchWithMatchingStrategyLAST(): void 'matchingStrategy' => 'last', ]); - $this->assertCount(2, $response->getHits()); + self::assertCount(2, $response->getHits()); } public function testParametersWithHighlightTag(): void @@ -201,8 +201,8 @@ public function testParametersWithHighlightTag(): void 'attributesToHighlight' => ['*'], ]); - $this->assertArrayHasKey('_formatted', $response->getHit(0)); - $this->assertSame('Pride and Prejudice', $response->getHit(0)['_formatted']['title']); + self::assertArrayHasKey('_formatted', $response->getHit(0)); + self::assertSame('Pride and Prejudice', $response->getHit(0)['_formatted']['title']); $response = $this->index->search('and', [ 'limit' => 1, @@ -211,8 +211,8 @@ public function testParametersWithHighlightTag(): void 'raw' => true, ]); - $this->assertArrayHasKey('_formatted', $response['hits'][0]); - $this->assertSame('Pride and Prejudice', $response['hits'][0]['_formatted']['title']); + self::assertArrayHasKey('_formatted', $response['hits'][0]); + self::assertSame('Pride and Prejudice', $response['hits'][0]['_formatted']['title']); } public function testParametersWithCustomizedHighlightTag(): void @@ -224,8 +224,8 @@ public function testParametersWithCustomizedHighlightTag(): void 'highlightPostTag' => ' ⊂(´• ω •`⊂)', ]); - $this->assertArrayHasKey('_formatted', $response->getHit(0)); - $this->assertSame('Pride (⊃。•́‿•̀。)⊃ and ⊂(´• ω •`⊂) Prejudice', $response->getHit(0)['_formatted']['title']); + self::assertArrayHasKey('_formatted', $response->getHit(0)); + self::assertSame('Pride (⊃。•́‿•̀。)⊃ and ⊂(´• ω •`⊂) Prejudice', $response->getHit(0)['_formatted']['title']); $response = $this->index->search('and', [ 'limit' => 1, @@ -236,8 +236,8 @@ public function testParametersWithCustomizedHighlightTag(): void 'raw' => true, ]); - $this->assertArrayHasKey('_formatted', $response['hits'][0]); - $this->assertSame('Pride (⊃。•́‿•̀。)⊃ and ⊂(´• ω •`⊂) Prejudice', $response['hits'][0]['_formatted']['title']); + self::assertArrayHasKey('_formatted', $response['hits'][0]); + self::assertSame('Pride (⊃。•́‿•̀。)⊃ and ⊂(´• ω •`⊂) Prejudice', $response['hits'][0]['_formatted']['title']); } public function testParametersArray(): void @@ -256,12 +256,12 @@ public function testParametersArray(): void 'showMatchesPosition' => true, ]); - $this->assertArrayHasKey('_matchesPosition', $response->getHit(0)); - $this->assertArrayHasKey('title', $response->getHit(0)['_matchesPosition']); - $this->assertArrayHasKey('_formatted', $response->getHit(0)); - $this->assertArrayNotHasKey('comment', $response->getHit(0)); - $this->assertArrayNotHasKey('comment', $response->getHit(0)['_matchesPosition']); - $this->assertSame('Le Petit Prince', $response->getHit(0)['_formatted']['title']); + self::assertArrayHasKey('_matchesPosition', $response->getHit(0)); + self::assertArrayHasKey('title', $response->getHit(0)['_matchesPosition']); + self::assertArrayHasKey('_formatted', $response->getHit(0)); + self::assertArrayNotHasKey('comment', $response->getHit(0)); + self::assertArrayNotHasKey('comment', $response->getHit(0)['_matchesPosition']); + self::assertSame('Le Petit Prince', $response->getHit(0)['_formatted']['title']); $response = $this->index->search('prince', [ 'limit' => 5, @@ -276,12 +276,12 @@ public function testParametersArray(): void 'raw' => true, ]); - $this->assertArrayHasKey('_matchesPosition', $response['hits'][0]); - $this->assertArrayHasKey('title', $response['hits'][0]['_matchesPosition']); - $this->assertArrayHasKey('_formatted', $response['hits'][0]); - $this->assertArrayNotHasKey('comment', $response['hits'][0]); - $this->assertArrayNotHasKey('comment', $response['hits'][0]['_matchesPosition']); - $this->assertSame('Le Petit Prince', $response['hits'][0]['_formatted']['title']); + self::assertArrayHasKey('_matchesPosition', $response['hits'][0]); + self::assertArrayHasKey('title', $response['hits'][0]['_matchesPosition']); + self::assertArrayHasKey('_formatted', $response['hits'][0]); + self::assertArrayNotHasKey('comment', $response['hits'][0]); + self::assertArrayNotHasKey('comment', $response['hits'][0]['_matchesPosition']); + self::assertSame('Le Petit Prince', $response['hits'][0]['_formatted']['title']); } public function testParametersCanBeAStar(): void @@ -300,12 +300,12 @@ public function testParametersCanBeAStar(): void 'showMatchesPosition' => true, ]); - $this->assertArrayHasKey('_matchesPosition', $response->getHit(0)); - $this->assertArrayHasKey('title', $response->getHit(0)['_matchesPosition']); - $this->assertArrayHasKey('_formatted', $response->getHit(0)); - $this->assertArrayHasKey('comment', $response->getHit(0)); - $this->assertArrayNotHasKey('comment', $response->getHit(0)['_matchesPosition']); - $this->assertSame('Le Petit Prince', $response->getHit(0)['_formatted']['title']); + self::assertArrayHasKey('_matchesPosition', $response->getHit(0)); + self::assertArrayHasKey('title', $response->getHit(0)['_matchesPosition']); + self::assertArrayHasKey('_formatted', $response->getHit(0)); + self::assertArrayHasKey('comment', $response->getHit(0)); + self::assertArrayNotHasKey('comment', $response->getHit(0)['_matchesPosition']); + self::assertSame('Le Petit Prince', $response->getHit(0)['_formatted']['title']); $response = $this->index->search('prince', [ 'limit' => 5, @@ -320,12 +320,12 @@ public function testParametersCanBeAStar(): void 'raw' => true, ]); - $this->assertArrayHasKey('_matchesPosition', $response['hits'][0]); - $this->assertArrayHasKey('title', $response['hits'][0]['_matchesPosition']); - $this->assertArrayHasKey('_formatted', $response['hits'][0]); - $this->assertArrayHasKey('comment', $response['hits'][0]); - $this->assertArrayNotHasKey('comment', $response['hits'][0]['_matchesPosition']); - $this->assertSame('Le Petit Prince', $response['hits'][0]['_formatted']['title']); + self::assertArrayHasKey('_matchesPosition', $response['hits'][0]); + self::assertArrayHasKey('title', $response['hits'][0]['_matchesPosition']); + self::assertArrayHasKey('_formatted', $response['hits'][0]); + self::assertArrayHasKey('comment', $response['hits'][0]); + self::assertArrayNotHasKey('comment', $response['hits'][0]['_matchesPosition']); + self::assertSame('Le Petit Prince', $response['hits'][0]['_formatted']['title']); } public function testSearchWithFilterCanBeInt(): void @@ -337,18 +337,18 @@ public function testSearchWithFilterCanBeInt(): void 'filter' => 'id < 12', ]); - $this->assertSame(1, $response->getEstimatedTotalHits()); - $this->assertCount(1, $response->getHits()); - $this->assertSame(4, $response->getHit(0)['id']); + self::assertSame(1, $response->getEstimatedTotalHits()); + self::assertCount(1, $response->getHits()); + self::assertSame(4, $response->getHit(0)['id']); $response = $this->index->search('', [ 'filter' => 'genre = fantasy AND id < 12', ]); - $this->assertSame(2, $response->getEstimatedTotalHits()); - $this->assertCount(2, $response->getHits()); - $this->assertSame(1, $response->getHit(0)['id']); - $this->assertSame(4, $response->getHit(1)['id']); + self::assertSame(2, $response->getEstimatedTotalHits()); + self::assertCount(2, $response->getHits()); + self::assertSame(1, $response->getHit(0)['id']); + self::assertSame(4, $response->getHit(1)['id']); } public function testBasicSearchWithFacetDistribution(): void @@ -359,22 +359,22 @@ public function testBasicSearchWithFacetDistribution(): void $response = $this->index->search('prince', [ 'facets' => ['genre'], ]); - $this->assertSame(2, $response->getHitsCount()); - $this->assertArrayHasKey('facetDistribution', $response->toArray()); - $this->assertArrayHasKey('genre', $response->getFacetDistribution()); - $this->assertSame($response->getFacetDistribution()['genre']['fantasy'], 1); - $this->assertSame($response->getFacetDistribution()['genre']['adventure'], 1); + self::assertSame(2, $response->getHitsCount()); + self::assertArrayHasKey('facetDistribution', $response->toArray()); + self::assertArrayHasKey('genre', $response->getFacetDistribution()); + self::assertSame($response->getFacetDistribution()['genre']['fantasy'], 1); + self::assertSame($response->getFacetDistribution()['genre']['adventure'], 1); $response = $this->index->search('prince', [ 'facets' => ['genre'], ], [ 'raw' => true, ]); - $this->assertSame(2, $response['estimatedTotalHits']); - $this->assertArrayHasKey('facetDistribution', $response); - $this->assertArrayHasKey('genre', $response['facetDistribution']); - $this->assertSame($response['facetDistribution']['genre']['fantasy'], 1); - $this->assertSame($response['facetDistribution']['genre']['adventure'], 1); + self::assertSame(2, $response['estimatedTotalHits']); + self::assertArrayHasKey('facetDistribution', $response); + self::assertArrayHasKey('genre', $response['facetDistribution']); + self::assertSame($response['facetDistribution']['genre']['fantasy'], 1); + self::assertSame($response['facetDistribution']['genre']['adventure'], 1); } public function testBasicSearchWithFilters(): void @@ -385,18 +385,18 @@ public function testBasicSearchWithFilters(): void $response = $this->index->search('prince', [ 'filter' => [['genre = fantasy']], ]); - $this->assertSame(1, $response->getHitsCount()); - $this->assertArrayNotHasKey('facetDistribution', $response->getRaw()); - $this->assertSame(4, $response->getHit(0)['id']); + self::assertSame(1, $response->getHitsCount()); + self::assertArrayNotHasKey('facetDistribution', $response->getRaw()); + self::assertSame(4, $response->getHit(0)['id']); $response = $this->index->search('prince', [ 'filter' => [['genre = fantasy']], ], [ 'raw' => true, ]); - $this->assertSame(1, $response['estimatedTotalHits']); - $this->assertArrayNotHasKey('facetDistribution', $response); - $this->assertSame(4, $response['hits'][0]['id']); + self::assertSame(1, $response['estimatedTotalHits']); + self::assertArrayNotHasKey('facetDistribution', $response); + self::assertSame(4, $response['hits'][0]['id']); } public function testBasicSearchWithMultipleFilter(): void @@ -407,18 +407,18 @@ public function testBasicSearchWithMultipleFilter(): void $response = $this->index->search('prince', [ 'filter' => ['genre = fantasy', ['genre = fantasy', 'genre = fantasy']], ]); - $this->assertSame(1, $response->getHitsCount()); - $this->assertArrayNotHasKey('facetDistribution', $response->getRaw()); - $this->assertSame(4, $response->getHit(0)['id']); + self::assertSame(1, $response->getHitsCount()); + self::assertArrayNotHasKey('facetDistribution', $response->getRaw()); + self::assertSame(4, $response->getHit(0)['id']); $response = $this->index->search('prince', [ 'filter' => ['genre = fantasy', ['genre = fantasy', 'genre = fantasy']], ], [ 'raw' => true, ]); - $this->assertSame(1, $response['estimatedTotalHits']); - $this->assertArrayNotHasKey('facetDistribution', $response); - $this->assertSame(4, $response['hits'][0]['id']); + self::assertSame(1, $response['estimatedTotalHits']); + self::assertArrayNotHasKey('facetDistribution', $response); + self::assertSame(4, $response['hits'][0]['id']); } public function testCustomSearchWithFilterAndAttributesToRetrieve(): void @@ -430,12 +430,12 @@ public function testCustomSearchWithFilterAndAttributesToRetrieve(): void 'filter' => [['genre = fantasy']], 'attributesToRetrieve' => ['id', 'title'], ]); - $this->assertSame(1, $response->getHitsCount()); - $this->assertArrayNotHasKey('facetDistribution', $response->getRaw()); - $this->assertSame(4, $response->getHit(0)['id']); - $this->assertArrayHasKey('id', $response->getHit(0)); - $this->assertArrayHasKey('title', $response->getHit(0)); - $this->assertArrayNotHasKey('comment', $response->getHit(0)); + self::assertSame(1, $response->getHitsCount()); + self::assertArrayNotHasKey('facetDistribution', $response->getRaw()); + self::assertSame(4, $response->getHit(0)['id']); + self::assertArrayHasKey('id', $response->getHit(0)); + self::assertArrayHasKey('title', $response->getHit(0)); + self::assertArrayNotHasKey('comment', $response->getHit(0)); $response = $this->index->search('prince', [ 'filter' => [['genre = fantasy']], @@ -443,12 +443,12 @@ public function testCustomSearchWithFilterAndAttributesToRetrieve(): void ], [ 'raw' => true, ]); - $this->assertSame(1, $response['estimatedTotalHits']); - $this->assertArrayNotHasKey('facetDistribution', $response); - $this->assertSame(4, $response['hits'][0]['id']); - $this->assertArrayHasKey('id', $response['hits'][0]); - $this->assertArrayHasKey('title', $response['hits'][0]); - $this->assertArrayNotHasKey('comment', $response['hits'][0]); + self::assertSame(1, $response['estimatedTotalHits']); + self::assertArrayNotHasKey('facetDistribution', $response); + self::assertSame(4, $response['hits'][0]['id']); + self::assertArrayHasKey('id', $response['hits'][0]); + self::assertArrayHasKey('title', $response['hits'][0]); + self::assertArrayNotHasKey('comment', $response['hits'][0]); } public function testSearchSortWithString(): void @@ -468,18 +468,18 @@ public function testSearchSortWithString(): void $response = $this->index->search('prince', [ 'sort' => ['genre:asc'], ]); - $this->assertSame(2, $response->getHitsCount()); - $this->assertArrayNotHasKey('facetDistribution', $response->getRaw()); - $this->assertSame(456, $response->getHit(0)['id']); + self::assertSame(2, $response->getHitsCount()); + self::assertArrayNotHasKey('facetDistribution', $response->getRaw()); + self::assertSame(456, $response->getHit(0)['id']); $response = $this->index->search('prince', [ 'sort' => ['genre:asc'], ], [ 'raw' => true, ]); - $this->assertSame(2, $response['estimatedTotalHits']); - $this->assertArrayNotHasKey('facetDistribution', $response); - $this->assertSame(456, $response['hits'][0]['id']); + self::assertSame(2, $response['estimatedTotalHits']); + self::assertArrayNotHasKey('facetDistribution', $response); + self::assertSame(456, $response['hits'][0]['id']); } public function testSearchSortWithInt(): void @@ -499,18 +499,18 @@ public function testSearchSortWithInt(): void $response = $this->index->search('prince', [ 'sort' => ['id:asc'], ]); - $this->assertSame(2, $response->getHitsCount()); - $this->assertArrayNotHasKey('facetDistribution', $response->getRaw()); - $this->assertSame(4, $response->getHit(0)['id']); + self::assertSame(2, $response->getHitsCount()); + self::assertArrayNotHasKey('facetDistribution', $response->getRaw()); + self::assertSame(4, $response->getHit(0)['id']); $response = $this->index->search('prince', [ 'sort' => ['id:asc'], ], [ 'raw' => true, ]); - $this->assertSame(2, $response['estimatedTotalHits']); - $this->assertArrayNotHasKey('facetDistribution', $response); - $this->assertSame(4, $response['hits'][0]['id']); + self::assertSame(2, $response['estimatedTotalHits']); + self::assertArrayNotHasKey('facetDistribution', $response); + self::assertSame(4, $response['hits'][0]['id']); } public function testSearchSortWithMultipleParameter(): void @@ -530,27 +530,27 @@ public function testSearchSortWithMultipleParameter(): void $response = $this->index->search('prince', [ 'sort' => ['id:asc', 'title:asc'], ]); - $this->assertSame(2, $response->getHitsCount()); - $this->assertArrayNotHasKey('facetDistribution', $response->getRaw()); - $this->assertSame(4, $response->getHit(0)['id']); + self::assertSame(2, $response->getHitsCount()); + self::assertArrayNotHasKey('facetDistribution', $response->getRaw()); + self::assertSame(4, $response->getHit(0)['id']); $response = $this->index->search('prince', [ 'sort' => ['id:asc', 'title:asc'], ], [ 'raw' => true, ]); - $this->assertSame(2, $response['estimatedTotalHits']); - $this->assertArrayNotHasKey('facetDistribution', $response); - $this->assertSame(4, $response['hits'][0]['id']); + self::assertSame(2, $response['estimatedTotalHits']); + self::assertArrayNotHasKey('facetDistribution', $response); + self::assertSame(4, $response['hits'][0]['id']); } public function testSearchWithPhraseSearch(): void { $response = $this->index->rawSearch('coco "harry"'); - $this->assertCount(1, $response['hits']); - $this->assertEquals(4, $response['hits'][0]['id']); - $this->assertEquals('Harry Potter and the Half-Blood Prince', $response['hits'][0]['title']); + self::assertCount(1, $response['hits']); + self::assertSame(4, $response['hits'][0]['id']); + self::assertSame('Harry Potter and the Half-Blood Prince', $response['hits'][0]['title']); } public function testBasicSearchWithRawSearch(): void @@ -558,9 +558,9 @@ public function testBasicSearchWithRawSearch(): void $response = $this->index->rawSearch('prince'); $this->assertEstimatedPagination($response); - $this->assertSame(2, $response['estimatedTotalHits']); - $this->assertCount(2, $response['hits']); - $this->assertEquals('Le Petit Prince', $response['hits'][0]['title']); + self::assertSame(2, $response['estimatedTotalHits']); + self::assertCount(2, $response['hits']); + self::assertSame('Le Petit Prince', $response['hits'][0]['title']); } public function testBasicSearchWithRawOption(): void @@ -568,8 +568,8 @@ public function testBasicSearchWithRawOption(): void $response = $this->index->search('prince', [], ['raw' => true]); $this->assertEstimatedPagination($response); - $this->assertSame(2, $response['estimatedTotalHits']); - $this->assertCount(2, $response['hits']); + self::assertSame(2, $response['estimatedTotalHits']); + self::assertCount(2, $response['hits']); } public function testBasicSearchWithTransformHitsOptionToFilter(): void @@ -584,10 +584,10 @@ function (array $hit): bool { return 'Le Petit Prince' === $hit['title']; } $response = $this->index->search('prince', [], $options = ['transformHits' => $keepLePetitPrinceFunc]); $this->assertEstimatedPagination($response->toArray()); - $this->assertSame('Le Petit Prince', $response->getHit(0)['title']); - $this->assertSame(2, $response->getEstimatedTotalHits()); - $this->assertSame(1, $response->getHitsCount()); - $this->assertCount(1, $response); + self::assertSame('Le Petit Prince', $response->getHit(0)['title']); + self::assertSame(2, $response->getEstimatedTotalHits()); + self::assertSame(1, $response->getHitsCount()); + self::assertCount(1, $response); } public function testBasicSearchWithTransformHitsOptionToMap(): void @@ -606,10 +606,10 @@ function (array $hit) { $response = $this->index->search('prince', [], ['transformHits' => $titlesToUpperCaseFunc]); $this->assertEstimatedPagination($response->toArray()); - $this->assertSame(2, $response->getEstimatedTotalHits()); - $this->assertSame(2, $response->getHitsCount()); - $this->assertCount(2, $response->getHits()); - $this->assertSame('LE PETIT PRINCE', $response->getHits()[0]['title']); + self::assertSame(2, $response->getEstimatedTotalHits()); + self::assertSame(2, $response->getHitsCount()); + self::assertCount(2, $response->getHits()); + self::assertSame('LE PETIT PRINCE', $response->getHits()[0]['title']); } public function testBasicSearchCannotBeFilteredOnRawResult(): void @@ -627,8 +627,8 @@ function (array $hit): bool { return 'Le Petit Prince' === $hit['title']; } ]); $this->assertEstimatedPagination($response); - $this->assertSame(2, $response['estimatedTotalHits']); - $this->assertCount(2, $response['hits']); + self::assertSame(2, $response['estimatedTotalHits']); + self::assertCount(2, $response['hits']); } public function testBasicSearchCanBeFilteredOnRawResultIfUsingToArray(): void @@ -643,9 +643,9 @@ function (array $hit): bool { return 'Le Petit Prince' === $hit['title']; } $response = $this->index->search('prince', [], ['transformHits' => $keepLePetitPrinceFunc])->toArray(); $this->assertEstimatedPagination($response); - $this->assertSame(2, $response['estimatedTotalHits']); - $this->assertCount(1, $response['hits']); - $this->assertEquals('Le Petit Prince', $response['hits'][0]['title']); + self::assertSame(2, $response['estimatedTotalHits']); + self::assertCount(1, $response['hits']); + self::assertSame('Le Petit Prince', $response['hits'][0]['title']); } public function testBasicSearchWithFacetsOption(): void @@ -658,12 +658,12 @@ public function testBasicSearchWithFacetsOption(): void ['facets' => ['genre']] ); - $this->assertCount(2, $response->getFacetDistribution()['genre']); - $this->assertEquals(1, $response->getFacetDistribution()['genre']['adventure']); - $this->assertEquals(1, $response->getFacetDistribution()['genre']['fantasy']); - $this->assertCount(2, $response->getRaw()['facetDistribution']['genre']); - $this->assertEquals($response->getRaw()['hits'], $response->getHits()); - $this->assertEquals($response->getRaw()['facetDistribution'], $response->getFacetDistribution()); + self::assertCount(2, $response->getFacetDistribution()['genre']); + self::assertSame(1, $response->getFacetDistribution()['genre']['adventure']); + self::assertSame(1, $response->getFacetDistribution()['genre']['fantasy']); + self::assertCount(2, $response->getRaw()['facetDistribution']['genre']); + self::assertSame($response->getRaw()['hits'], $response->getHits()); + self::assertSame($response->getRaw()['facetDistribution'], $response->getFacetDistribution()); } public function testBasicSearchWithFacetsOptionAndMultipleFacets(): void @@ -678,14 +678,14 @@ public function testBasicSearchWithFacetsOptionAndMultipleFacets(): void ['facets' => ['genre', 'adaptation']] ); - $this->assertCount(1, $response->getFacetDistribution()['genre']); - $this->assertEquals(1, $response->getFacetDistribution()['genre']['adventure']); - $this->assertCount(1, $response->getFacetDistribution()['adaptation']); - $this->assertEquals(1, $response->getFacetDistribution()['adaptation']['video game']); - $this->assertCount(1, $response->getRaw()['facetDistribution']['adaptation']); - $this->assertCount(1, $response->getRaw()['facetDistribution']['genre']); - $this->assertEquals($response->getRaw()['hits'], $response->getHits()); - $this->assertEquals($response->getRaw()['facetDistribution'], $response->getFacetDistribution()); + self::assertCount(1, $response->getFacetDistribution()['genre']); + self::assertSame(1, $response->getFacetDistribution()['genre']['adventure']); + self::assertCount(1, $response->getFacetDistribution()['adaptation']); + self::assertSame(1, $response->getFacetDistribution()['adaptation']['video game']); + self::assertCount(1, $response->getRaw()['facetDistribution']['adaptation']); + self::assertCount(1, $response->getRaw()['facetDistribution']['genre']); + self::assertSame($response->getRaw()['hits'], $response->getHits()); + self::assertSame($response->getRaw()['facetDistribution'], $response->getFacetDistribution()); } public function testVectorSearch(): void @@ -700,7 +700,7 @@ public function testVectorSearch(): void $response = $index->search('', ['vector' => [1], 'hybrid' => ['semanticRatio' => 1.0]]); - $this->assertEmpty($response->getHits()); + self::assertEmpty($response->getHits()); } public function testShowRankingScoreDetails(): void @@ -711,7 +711,7 @@ public function testShowRankingScoreDetails(): void $response = $this->index->search('the', ['showRankingScoreDetails' => true]); $hit = $response->getHits()[0]; - $this->assertArrayHasKey('_rankingScoreDetails', $hit); + self::assertArrayHasKey('_rankingScoreDetails', $hit); } public function testBasicSearchWithTransformFacetsDritributionOptionToFilter(): void @@ -738,12 +738,12 @@ function (int $facetValue): bool { return 1 < $facetValue; }, ); $this->assertEstimatedPagination($response->toArray()); - $this->assertEquals($response->getRaw()['hits'], $response->getHits()); - $this->assertNotEquals($response->getRaw()['facetDistribution'], $response->getFacetDistribution()); - $this->assertCount(3, $response->getRaw()['facetDistribution']['genre']); - $this->assertCount(2, $response->getFacetDistribution()['genre']); - $this->assertEquals(3, $response->getFacetDistribution()['genre']['romance']); - $this->assertEquals(2, $response->getFacetDistribution()['genre']['fantasy']); + self::assertSame($response->getRaw()['hits'], $response->getHits()); + self::assertNotSame($response->getRaw()['facetDistribution'], $response->getFacetDistribution()); + self::assertCount(3, $response->getRaw()['facetDistribution']['genre']); + self::assertCount(2, $response->getFacetDistribution()['genre']); + self::assertSame(3, $response->getFacetDistribution()['genre']['romance']); + self::assertSame(2, $response->getFacetDistribution()['genre']['fantasy']); } public function testSearchWithAttributesToSearchOn(): void @@ -753,14 +753,14 @@ public function testSearchWithAttributesToSearchOn(): void $response = $this->index->search('the', ['attributesToSearchOn' => ['comment']]); - $this->assertEquals('The best book', $response->getHits()[0]['comment']); + self::assertSame('The best book', $response->getHits()[0]['comment']); } public function testSearchWithShowRankingScore(): void { $response = $this->index->search('the', ['showRankingScore' => true]); - $this->assertArrayHasKey('_rankingScore', $response->getHits()[0]); + self::assertArrayHasKey('_rankingScore', $response->getHits()[0]); } public function testBasicSearchWithTransformFacetsDritributionOptionToMap(): void @@ -788,12 +788,12 @@ public function testBasicSearchWithTransformFacetsDritributionOptionToMap(): voi ); $this->assertEstimatedPagination($response->toArray()); - $this->assertEquals($response->getRaw()['hits'], $response->getHits()); - $this->assertNotEquals($response->getRaw()['facetDistribution'], $response->getFacetDistribution()); - $this->assertCount(3, $response->getFacetDistribution()['genre']); - $this->assertEquals(3, $response->getFacetDistribution()['genre']['ROMANCE']); - $this->assertEquals(2, $response->getFacetDistribution()['genre']['FANTASY']); - $this->assertEquals(1, $response->getFacetDistribution()['genre']['ADVENTURE']); + self::assertSame($response->getRaw()['hits'], $response->getHits()); + self::assertNotSame($response->getRaw()['facetDistribution'], $response->getFacetDistribution()); + self::assertCount(3, $response->getFacetDistribution()['genre']); + self::assertSame(3, $response->getFacetDistribution()['genre']['ROMANCE']); + self::assertSame(2, $response->getFacetDistribution()['genre']['FANTASY']); + self::assertSame(1, $response->getFacetDistribution()['genre']['ADVENTURE']); } public function testBasicSearchWithTransformFacetsDritributionOptionToOder(): void @@ -818,13 +818,13 @@ public function testBasicSearchWithTransformFacetsDritributionOptionToOder(): vo ); $this->assertEstimatedPagination($response->toArray()); - $this->assertEquals($response->getRaw()['hits'], $response->getHits()); - $this->assertEquals('adventure', array_key_first($response->getFacetDistribution()['genre'])); - $this->assertEquals('romance', array_key_last($response->getFacetDistribution()['genre'])); - $this->assertCount(3, $response->getFacetDistribution()['genre']); - $this->assertEquals(3, $response->getFacetDistribution()['genre']['romance']); - $this->assertEquals(2, $response->getFacetDistribution()['genre']['fantasy']); - $this->assertEquals(1, $response->getFacetDistribution()['genre']['adventure']); + self::assertSame($response->getRaw()['hits'], $response->getHits()); + self::assertSame('adventure', array_key_first($response->getFacetDistribution()['genre'])); + self::assertSame('romance', array_key_last($response->getFacetDistribution()['genre'])); + self::assertCount(3, $response->getFacetDistribution()['genre']); + self::assertSame(3, $response->getFacetDistribution()['genre']['romance']); + self::assertSame(2, $response->getFacetDistribution()['genre']['fantasy']); + self::assertSame(1, $response->getFacetDistribution()['genre']['adventure']); } public function testSearchAndRetrieveFacetStats(): void @@ -840,6 +840,6 @@ public function testSearchAndRetrieveFacetStats(): void ['facets' => ['info.reviewNb']], ); - $this->assertEquals(['info.reviewNb' => ['min' => 50, 'max' => 1000]], $response->getFacetStats()); + self::assertSame(['info.reviewNb' => ['min' => 50.0, 'max' => 1000.0]], $response->getFacetStats()); } } diff --git a/tests/Endpoints/SearchTestNestedFields.php b/tests/Endpoints/SearchTestNestedFields.php index 4f9e5ed2..11b3af9b 100644 --- a/tests/Endpoints/SearchTestNestedFields.php +++ b/tests/Endpoints/SearchTestNestedFields.php @@ -23,46 +23,46 @@ public function testBasicSearchOnNestedFields(): void { $response = $this->index->search('An awesome'); - $this->assertArrayHasKey('hits', $response->toArray()); - $this->assertCount(1, $response->getHits()); + self::assertArrayHasKey('hits', $response->toArray()); + self::assertCount(1, $response->getHits()); $response = $this->index->search('An awesome', [], [ 'raw' => true, ]); - $this->assertArrayHasKey('hits', $response); - $this->assertSame(1, $response['estimatedTotalHits']); - $this->assertSame(5, $response['hits'][0]['id']); + self::assertArrayHasKey('hits', $response); + self::assertSame(1, $response['estimatedTotalHits']); + self::assertSame(5, $response['hits'][0]['id']); } public function testSearchOnNestedFieldWithMultiplesResultsOnNestedFields(): void { $response = $this->index->search('book'); - $this->assertArrayHasKey('hits', $response->toArray()); - $this->assertCount(6, $response->getHits()); + self::assertArrayHasKey('hits', $response->toArray()); + self::assertCount(6, $response->getHits()); $response = $this->index->search('book', [], [ 'raw' => true, ]); - $this->assertArrayHasKey('hits', $response); - $this->assertSame(6, $response['estimatedTotalHits']); - $this->assertSame(4, $response['hits'][0]['id']); + self::assertArrayHasKey('hits', $response); + self::assertSame(6, $response['estimatedTotalHits']); + self::assertSame(4, $response['hits'][0]['id']); } public function testSearchOnNestedFieldWithOptions(): void { $response = $this->index->search('book', ['limit' => 1]); - $this->assertCount(1, $response->getHits()); + self::assertCount(1, $response->getHits()); $response = $this->index->search('book', ['limit' => 1], [ 'raw' => true, ]); - $this->assertCount(1, $response['hits']); - $this->assertSame(4, $response['hits'][0]['id']); + self::assertCount(1, $response['hits']); + self::assertSame(4, $response['hits'][0]['id']); } public function testSearchOnNestedFieldWithSearchableAtributes(): void @@ -72,16 +72,16 @@ public function testSearchOnNestedFieldWithSearchableAtributes(): void $response = $this->index->search('An awesome'); - $this->assertArrayHasKey('hits', $response->toArray()); - $this->assertCount(1, $response->getHits()); + self::assertArrayHasKey('hits', $response->toArray()); + self::assertCount(1, $response->getHits()); $response = $this->index->search('An awesome', [], [ 'raw' => true, ]); - $this->assertArrayHasKey('hits', $response); - $this->assertSame(1, $response['estimatedTotalHits']); - $this->assertSame(5, $response['hits'][0]['id']); + self::assertArrayHasKey('hits', $response); + self::assertSame(1, $response['estimatedTotalHits']); + self::assertSame(5, $response['hits'][0]['id']); } public function testSearchOnNestedFieldWithSortableAtributes(): void @@ -91,8 +91,8 @@ public function testSearchOnNestedFieldWithSortableAtributes(): void $response = $this->index->search('An awesome'); - $this->assertArrayHasKey('hits', $response->toArray()); - $this->assertCount(1, $response->getHits()); + self::assertArrayHasKey('hits', $response->toArray()); + self::assertCount(1, $response->getHits()); $response = $this->index->search('An awesome', [ 'sort' => ['info.reviewNb:desc'], @@ -100,9 +100,9 @@ public function testSearchOnNestedFieldWithSortableAtributes(): void 'raw' => true, ]); - $this->assertArrayHasKey('hits', $response); - $this->assertSame(1, $response['estimatedTotalHits']); - $this->assertSame(5, $response['hits'][0]['id']); + self::assertArrayHasKey('hits', $response); + self::assertSame(1, $response['estimatedTotalHits']); + self::assertSame(5, $response['hits'][0]['id']); } public function testSearchOnNestedFieldWithSortableAtributesAndSearchableAttributes(): void @@ -115,8 +115,8 @@ public function testSearchOnNestedFieldWithSortableAtributesAndSearchableAttribu $response = $this->index->search('An awesome'); - $this->assertArrayHasKey('hits', $response->toArray()); - $this->assertCount(1, $response->getHits()); + self::assertArrayHasKey('hits', $response->toArray()); + self::assertCount(1, $response->getHits()); $response = $this->index->search('An awesome', [ 'sort' => ['info.reviewNb:desc'], @@ -124,8 +124,8 @@ public function testSearchOnNestedFieldWithSortableAtributesAndSearchableAttribu 'raw' => true, ]); - $this->assertArrayHasKey('hits', $response); - $this->assertSame(1, $response['estimatedTotalHits']); - $this->assertSame(5, $response['hits'][0]['id']); + self::assertArrayHasKey('hits', $response); + self::assertSame(1, $response['estimatedTotalHits']); + self::assertSame(5, $response['hits'][0]['id']); } } diff --git a/tests/Endpoints/SnapshotsTest.php b/tests/Endpoints/SnapshotsTest.php index 17da04ae..509100af 100644 --- a/tests/Endpoints/SnapshotsTest.php +++ b/tests/Endpoints/SnapshotsTest.php @@ -14,7 +14,7 @@ public function testCreateSnapshots(): void $task = $this->client->createSnapshot(); - $this->assertSame($expectedKeys, array_keys($task)); - $this->assertSame($task['type'], 'snapshotCreation'); + self::assertSame($expectedKeys, array_keys($task)); + self::assertSame('snapshotCreation', $task['type']); } } diff --git a/tests/Endpoints/TasksTest.php b/tests/Endpoints/TasksTest.php index 22a803a2..edd9e39d 100644 --- a/tests/Endpoints/TasksTest.php +++ b/tests/Endpoints/TasksTest.php @@ -26,35 +26,35 @@ public function testGetOneTaskFromWaitTask(): void { [$promise, $response] = $this->seedIndex(); - $this->assertIsArray($response); - $this->assertArrayHasKey('status', $response); - $this->assertSame($response['uid'], $promise['taskUid']); - $this->assertArrayHasKey('type', $response); - $this->assertSame($response['type'], 'documentAdditionOrUpdate'); - $this->assertArrayHasKey('indexUid', $response); - $this->assertSame($response['indexUid'], $this->indexName); - $this->assertArrayHasKey('enqueuedAt', $response); - $this->assertArrayHasKey('startedAt', $response); - $this->assertArrayHasKey('finishedAt', $response); - $this->assertIsArray($response['details']); + self::assertIsArray($response); + self::assertArrayHasKey('status', $response); + self::assertSame($response['uid'], $promise['taskUid']); + self::assertArrayHasKey('type', $response); + self::assertSame('documentAdditionOrUpdate', $response['type']); + self::assertArrayHasKey('indexUid', $response); + self::assertSame($this->indexName, $response['indexUid']); + self::assertArrayHasKey('enqueuedAt', $response); + self::assertArrayHasKey('startedAt', $response); + self::assertArrayHasKey('finishedAt', $response); + self::assertIsArray($response['details']); } public function testGetOneTaskClient(): void { [$promise, $response] = $this->seedIndex(); - $this->assertIsArray($promise); + self::assertIsArray($promise); $response = $this->client->getTask($promise['taskUid']); - $this->assertArrayHasKey('status', $response); - $this->assertSame($response['uid'], $promise['taskUid']); - $this->assertArrayHasKey('type', $response); - $this->assertSame($response['type'], 'documentAdditionOrUpdate'); - $this->assertArrayHasKey('indexUid', $response); - $this->assertSame($response['indexUid'], $this->indexName); - $this->assertArrayHasKey('enqueuedAt', $response); - $this->assertArrayHasKey('startedAt', $response); - $this->assertArrayHasKey('finishedAt', $response); - $this->assertIsArray($response['details']); + self::assertArrayHasKey('status', $response); + self::assertSame($response['uid'], $promise['taskUid']); + self::assertArrayHasKey('type', $response); + self::assertSame('documentAdditionOrUpdate', $response['type']); + self::assertArrayHasKey('indexUid', $response); + self::assertSame($this->indexName, $response['indexUid']); + self::assertArrayHasKey('enqueuedAt', $response); + self::assertArrayHasKey('startedAt', $response); + self::assertArrayHasKey('finishedAt', $response); + self::assertIsArray($response['details']); } public function testGetAllTasksClient(): void @@ -66,32 +66,32 @@ public function testGetAllTasksClient(): void $response = $this->client->getTasks(); $newFirstIndex = $response->getResults()[0]['uid']; - $this->assertNotEquals($firstIndex, $newFirstIndex); + self::assertNotSame($firstIndex, $newFirstIndex); } public function testGetAllTasksClientWithPagination(): void { $response = $this->client->getTasks((new TasksQuery())->setLimit(0)); - $this->assertEmpty($response->getResults()); + self::assertEmpty($response->getResults()); } public function testGetOneTaskIndex(): void { [$promise, $response] = $this->seedIndex(); - $this->assertIsArray($promise); + self::assertIsArray($promise); $response = $this->index->getTask($promise['taskUid']); - $this->assertArrayHasKey('status', $response); - $this->assertSame($response['uid'], $promise['taskUid']); - $this->assertArrayHasKey('type', $response); - $this->assertSame($response['type'], 'documentAdditionOrUpdate'); - $this->assertArrayHasKey('indexUid', $response); - $this->assertSame($response['indexUid'], $this->indexName); - $this->assertArrayHasKey('enqueuedAt', $response); - $this->assertArrayHasKey('startedAt', $response); - $this->assertArrayHasKey('finishedAt', $response); - $this->assertIsArray($response['details']); + self::assertArrayHasKey('status', $response); + self::assertSame($response['uid'], $promise['taskUid']); + self::assertArrayHasKey('type', $response); + self::assertSame('documentAdditionOrUpdate', $response['type']); + self::assertArrayHasKey('indexUid', $response); + self::assertSame($this->indexName, $response['indexUid']); + self::assertArrayHasKey('enqueuedAt', $response); + self::assertArrayHasKey('startedAt', $response); + self::assertArrayHasKey('finishedAt', $response); + self::assertIsArray($response['details']); } public function testGetAllTasksByIndex(): void @@ -105,7 +105,7 @@ public function testGetAllTasksByIndex(): void $response = $this->index->getTasks(); $newFirstIndex = $response->getResults()[0]['uid']; - $this->assertEquals($firstIndex, $newFirstIndex); + self::assertSame($firstIndex, $newFirstIndex); } public function testGetAllTasksByIndexWithFilter(): void @@ -114,7 +114,7 @@ public function testGetAllTasksByIndexWithFilter(): void ->setAfterEnqueuedAt(new \DateTime('yesterday'))->setStatuses(['succeeded'])->setLimit(2)); $firstIndex = $response->getResults()[0]['uid']; - $this->assertEquals('succeeded', $response->getResults()[0]['status']); + self::assertSame('succeeded', $response->getResults()[0]['status']); $newIndex = $this->createEmptyIndex($this->safeIndexName('movie-1')); $newIndex->updateDocuments(self::DOCUMENTS); @@ -122,8 +122,8 @@ public function testGetAllTasksByIndexWithFilter(): void $response = $this->index->getTasks(); $newFirstIndex = $response->getResults()[0]['uid']; - $this->assertEquals($firstIndex, $newFirstIndex); - $this->assertGreaterThan(0, $response->getTotal()); + self::assertSame($firstIndex, $newFirstIndex); + self::assertGreaterThan(0, $response->getTotal()); } public function testCancelTasksWithFilter(): void @@ -132,12 +132,12 @@ public function testCancelTasksWithFilter(): void $query = http_build_query(['afterEnqueuedAt' => $date->format(\DateTime::RFC3339)]); $promise = $this->client->cancelTasks((new CancelTasksQuery())->setAfterEnqueuedAt($date)); - $this->assertEquals('taskCancelation', $promise['type']); + self::assertSame('taskCancelation', $promise['type']); $response = $this->client->waitForTask($promise['taskUid']); - $this->assertEquals($response['details']['originalFilter'], '?'.$query); - $this->assertEquals('taskCancelation', $response['type']); - $this->assertEquals('succeeded', $response['status']); + self::assertSame('?'.$query, $response['details']['originalFilter']); + self::assertSame('taskCancelation', $response['type']); + self::assertSame('succeeded', $response['status']); } public function testExceptionIfNoTaskIdWhenGetting(): void diff --git a/tests/Endpoints/TenantTokenTest.php b/tests/Endpoints/TenantTokenTest.php index 5d758e26..6c8f942f 100644 --- a/tests/Endpoints/TenantTokenTest.php +++ b/tests/Endpoints/TenantTokenTest.php @@ -49,8 +49,8 @@ public function testGenerateTenantTokenWithSearchRulesOnly(): void $tokenClient = new Client($this->host, $token); $response = $tokenClient->index('tenantToken')->search(''); - $this->assertArrayHasKey('hits', $response->toArray()); - $this->assertCount(7, $response->getHits()); + self::assertArrayHasKey('hits', $response->toArray()); + self::assertCount(7, $response->getHits()); } public function testGenerateTenantTokenWithSearchRulesAsObject(): void @@ -62,8 +62,8 @@ public function testGenerateTenantTokenWithSearchRulesAsObject(): void $tokenClient = new Client($this->host, $token); $response = $tokenClient->index('tenantToken')->search(''); - $this->assertArrayHasKey('hits', $response->toArray()); - $this->assertCount(7, $response->getHits()); + self::assertArrayHasKey('hits', $response->toArray()); + self::assertCount(7, $response->getHits()); } public function testGenerateTenantTokenWithFilter(): void @@ -79,8 +79,8 @@ public function testGenerateTenantTokenWithFilter(): void $tokenClient = new Client($this->host, $token); $response = $tokenClient->index('tenantToken')->search(''); - $this->assertArrayHasKey('hits', $response->toArray()); - $this->assertCount(4, $response->getHits()); + self::assertArrayHasKey('hits', $response->toArray()); + self::assertCount(4, $response->getHits()); } public function testGenerateTenantTokenWithSearchRulesOnOneIndex(): void @@ -92,8 +92,8 @@ public function testGenerateTenantTokenWithSearchRulesOnOneIndex(): void $tokenClient = new Client($this->host, $token); $response = $tokenClient->index($this->indexName)->search(''); - $this->assertArrayHasKey('hits', $response->toArray()); - $this->assertArrayHasKey('query', $response->toArray()); + self::assertArrayHasKey('hits', $response->toArray()); + self::assertArrayHasKey('query', $response->toArray()); $this->expectException(ApiException::class); $tokenClient->index($indexName)->search(''); } @@ -108,7 +108,7 @@ public function testGenerateTenantTokenWithApiKey(): void $tokenClient = new Client($this->host, $token); $response = $tokenClient->index($this->indexName)->search(''); - $this->assertArrayHasKey('hits', $response->toArray()); + self::assertArrayHasKey('hits', $response->toArray()); } public function testGenerateTenantTokenWithExpiresAt(): void @@ -123,7 +123,7 @@ public function testGenerateTenantTokenWithExpiresAt(): void $tokenClient = new Client($this->host, $token); $response = $tokenClient->index($this->indexName)->search(''); - $this->assertArrayHasKey('hits', $response->toArray()); + self::assertArrayHasKey('hits', $response->toArray()); } public function testGenerateTenantTokenWithSearchRulesEmptyArray(): void diff --git a/tests/Exceptions/ApiExceptionTest.php b/tests/Exceptions/ApiExceptionTest.php index af43a08b..2e2c4fd3 100644 --- a/tests/Exceptions/ApiExceptionTest.php +++ b/tests/Exceptions/ApiExceptionTest.php @@ -29,14 +29,14 @@ public function testException(): void throw new ApiException($response, $httpBodyExample); } catch (ApiException $apiException) { - $this->assertEquals($statusCode, $apiException->httpStatus); - $this->assertEquals($httpBodyExample['message'], $apiException->message); - $this->assertEquals($httpBodyExample['code'], $apiException->errorCode); - $this->assertEquals($httpBodyExample['type'], $apiException->errorType); - $this->assertEquals($httpBodyExample['link'], $apiException->errorLink); + self::assertSame($statusCode, $apiException->httpStatus); + self::assertSame($httpBodyExample['message'], $apiException->message); + self::assertSame($httpBodyExample['code'], $apiException->errorCode); + self::assertSame($httpBodyExample['type'], $apiException->errorType); + self::assertSame($httpBodyExample['link'], $apiException->errorLink); $expectedExceptionToString = "Meilisearch ApiException: Http Status: {$statusCode} - Message: {$httpBodyExample['message']} - Code: {$httpBodyExample['code']} - Type: {$httpBodyExample['type']} - Link: {$httpBodyExample['link']}"; - $this->assertEquals($expectedExceptionToString, (string) $apiException); + self::assertSame($expectedExceptionToString, (string) $apiException); } } @@ -49,14 +49,14 @@ public function testExceptionWithNoHttpBody(): void try { throw new ApiException($response, null); } catch (ApiException $apiException) { - $this->assertEquals($statusCode, $apiException->httpStatus); - $this->assertEquals($response->getReasonPhrase(), $apiException->message); - $this->assertNull($apiException->errorCode); - $this->assertNull($apiException->errorType); - $this->assertNull($apiException->errorLink); + self::assertSame($statusCode, $apiException->httpStatus); + self::assertSame($response->getReasonPhrase(), $apiException->message); + self::assertNull($apiException->errorCode); + self::assertNull($apiException->errorType); + self::assertNull($apiException->errorLink); $expectedExceptionToString = "Meilisearch ApiException: Http Status: {$statusCode} - Message: {$response->getReasonPhrase()}"; - $this->assertEquals($expectedExceptionToString, (string) $apiException); + self::assertSame($expectedExceptionToString, (string) $apiException); } } @@ -65,12 +65,12 @@ public function testRethrowWithHintException(): void $e = new \Exception('Any error message that caused the root problem should be shown'); $apiException = ApiException::rethrowWithHint($e, 'deleteDocuments'); - $this->assertStringContainsString( + self::assertStringContainsString( 'with the Meilisearch version that `deleteDocuments` call', $apiException->getMessage() ); - $this->assertStringContainsString( + self::assertStringContainsString( 'Any error message that caused the root problem should be shown', $apiException->getPrevious()->getMessage() ); diff --git a/tests/Exceptions/CommunicationExceptionTest.php b/tests/Exceptions/CommunicationExceptionTest.php index 3faca3b1..a8f8db27 100644 --- a/tests/Exceptions/CommunicationExceptionTest.php +++ b/tests/Exceptions/CommunicationExceptionTest.php @@ -14,10 +14,10 @@ public function testException(): void try { throw new CommunicationException('Connection refused'); } catch (CommunicationException $CommunicationException) { - $this->assertEquals('Connection refused', $CommunicationException->getMessage()); + self::assertSame('Connection refused', $CommunicationException->getMessage()); $expectedExceptionToString = 'Meilisearch CommunicationException: Connection refused'; - $this->assertEquals($expectedExceptionToString, (string) $CommunicationException); + self::assertSame($expectedExceptionToString, (string) $CommunicationException); } } } diff --git a/tests/Exceptions/InvalidResponseBodyExceptionTest.php b/tests/Exceptions/InvalidResponseBodyExceptionTest.php index 102242c1..526c85ea 100644 --- a/tests/Exceptions/InvalidResponseBodyExceptionTest.php +++ b/tests/Exceptions/InvalidResponseBodyExceptionTest.php @@ -24,11 +24,11 @@ public function testException(): void throw new InvalidResponseBodyException($response, $httpBodyExample); } catch (InvalidResponseBodyException $invalidResponseBodyException) { - $this->assertEquals($statusCode, $invalidResponseBodyException->httpStatus); - $this->assertEquals('Gateway Timeout', $invalidResponseBodyException->message); + self::assertSame($statusCode, $invalidResponseBodyException->httpStatus); + self::assertSame('Gateway Timeout', $invalidResponseBodyException->message); $expectedExceptionToString = "Meilisearch InvalidResponseBodyException: Http Status: {$statusCode} - Message: Gateway Timeout"; - $this->assertEquals($expectedExceptionToString, (string) $invalidResponseBodyException); + self::assertSame($expectedExceptionToString, (string) $invalidResponseBodyException); } } @@ -41,11 +41,11 @@ public function testExceptionWithNoHttpBody(): void try { throw new InvalidResponseBodyException($response, null); } catch (InvalidResponseBodyException $invalidResponseBodyException) { - $this->assertEquals($statusCode, $invalidResponseBodyException->httpStatus); - $this->assertEquals($response->getReasonPhrase(), $invalidResponseBodyException->message); + self::assertSame($statusCode, $invalidResponseBodyException->httpStatus); + self::assertSame($response->getReasonPhrase(), $invalidResponseBodyException->message); $expectedExceptionToString = "Meilisearch InvalidResponseBodyException: Http Status: {$statusCode} - Message: {$response->getReasonPhrase()}"; - $this->assertEquals($expectedExceptionToString, (string) $invalidResponseBodyException); + self::assertSame($expectedExceptionToString, (string) $invalidResponseBodyException); } } } diff --git a/tests/Exceptions/TimeOutExceptionTest.php b/tests/Exceptions/TimeOutExceptionTest.php index f00e67c9..0a18ebbf 100644 --- a/tests/Exceptions/TimeOutExceptionTest.php +++ b/tests/Exceptions/TimeOutExceptionTest.php @@ -17,11 +17,11 @@ public function testException(): void try { throw new TimeOutException($message, $code); } catch (TimeOutException $timeOutException) { - $this->assertEquals($message, $timeOutException->getMessage()); - $this->assertEquals($code, $timeOutException->getCode()); + self::assertSame($message, $timeOutException->getMessage()); + self::assertSame($code, $timeOutException->getCode()); $expectedExceptionToString = "Meilisearch TimeOutException: Code: {$code} - Message: {$message}"; - $this->assertEquals($expectedExceptionToString, (string) $timeOutException); + self::assertSame($expectedExceptionToString, (string) $timeOutException); } } @@ -33,11 +33,11 @@ public function testExceptionWithNullMessageAndCode(): void try { throw new TimeOutException(); } catch (TimeOutException $timeOutException) { - $this->assertEquals($message, $timeOutException->getMessage()); - $this->assertEquals($code, $timeOutException->getCode()); + self::assertSame($message, $timeOutException->getMessage()); + self::assertSame($code, $timeOutException->getCode()); $expectedExceptionToString = "Meilisearch TimeOutException: Code: {$code} - Message: {$message}"; - $this->assertEquals($expectedExceptionToString, (string) $timeOutException); + self::assertSame($expectedExceptionToString, (string) $timeOutException); } } @@ -46,10 +46,10 @@ public function testExceptionWithEmptyMessage(): void try { throw new TimeOutException(''); } catch (TimeOutException $timeOutException) { - $this->assertEquals('', $timeOutException->getMessage()); + self::assertSame('', $timeOutException->getMessage()); $expectedExceptionToString = 'Meilisearch TimeOutException: Code: 408'; - $this->assertEquals($expectedExceptionToString, (string) $timeOutException); + self::assertSame($expectedExceptionToString, (string) $timeOutException); } } } diff --git a/tests/Http/ClientTest.php b/tests/Http/ClientTest.php index 55e2f124..18511263 100644 --- a/tests/Http/ClientTest.php +++ b/tests/Http/ClientTest.php @@ -28,7 +28,7 @@ public function testGetExecutesRequest(): void $client = new Client('https://localhost', null, $httpClient); $result = $client->get('/'); - $this->assertSame([], $result); + self::assertSame([], $result); } public function testPostExecutesRequest(): void @@ -38,7 +38,7 @@ public function testPostExecutesRequest(): void $client = new Client('https://localhost', null, $httpClient); $result = $client->post('/'); - $this->assertSame([], $result); + self::assertSame([], $result); } public function testPostExecutesRequestWithCustomStreamFactory(): void @@ -50,7 +50,7 @@ public function testPostExecutesRequestWithCustomStreamFactory(): void $client = new Client('https://localhost', null, $httpClient, null, [], $streamFactory); $result = $client->post('/'); - $this->assertSame([], $result); + self::assertSame([], $result); } public function testPostThrowsWithInvalidBody(): void @@ -84,9 +84,9 @@ public function testPostThrowsApiException(): void $httpClient = $this->createHttpClientMock(300, '{"message":"internal error","code":"internal"}'); $client = new Client('https://localhost', null, $httpClient); $client->post('/', ''); - $this->fail('ApiException not raised.'); + self::fail('ApiException not raised.'); } catch (ApiException $e) { - $this->assertEquals('internal', $e->errorCode); + self::assertSame('internal', $e->errorCode); } } @@ -97,7 +97,7 @@ public function testPutExecutesRequest(): void $client = new Client('https://localhost', null, $httpClient); $result = $client->put('/'); - $this->assertSame([], $result); + self::assertSame([], $result); } public function testPutThrowsWithInvalidBody(): void @@ -131,9 +131,9 @@ public function testPutThrowsApiException(): void $httpClient = $this->createHttpClientMock(300, '{"message":"internal error","code":"internal"}'); $client = new Client('https://localhost', null, $httpClient); $client->put('/', ''); - $this->fail('ApiException not raised.'); + self::fail('ApiException not raised.'); } catch (ApiException $e) { - $this->assertEquals('internal', $e->errorCode); + self::assertSame('internal', $e->errorCode); } } @@ -144,7 +144,7 @@ public function testPatchExecutesRequest(): void $client = new Client('https://localhost', null, $httpClient); $result = $client->patch('/'); - $this->assertSame([], $result); + self::assertSame([], $result); } public function testPatchThrowsWithInvalidBody(): void @@ -178,9 +178,9 @@ public function testPatchThrowsApiException(): void $httpClient = $this->createHttpClientMock(300, '{"message":"internal error","code":"internal"}'); $client = new Client('https://localhost', null, $httpClient); $client->patch('/', ''); - $this->fail('ApiException not raised.'); + self::fail('ApiException not raised.'); } catch (ApiException $e) { - $this->assertEquals('internal', $e->errorCode); + self::assertSame('internal', $e->errorCode); } } @@ -191,7 +191,7 @@ public function testDeleteExecutesRequest(): void $client = new Client('https://localhost', null, $httpClient); $result = $client->delete('/'); - $this->assertSame([], $result); + self::assertSame([], $result); } public function testInvalidResponseContentTypeThrowsException(): void @@ -211,24 +211,24 @@ public function testClientHasDefaultUserAgent(): void $httpClient = $this->createHttpClientMock(200, '{}'); $reqFactory = $this->createMock(RequestFactoryInterface::class); $requestStub = $this->createMock(RequestInterface::class); - $requestStub->expects($this->exactly(2)) + $requestStub->expects(self::exactly(2)) ->method('withAddedHeader') ->willReturnCallback(function ($name, $value) use ($requestStub) { if ('User-Agent' === $name) { - $this->assertSame(Meilisearch::qualifiedVersion(), $value); + self::assertSame(Meilisearch::qualifiedVersion(), $value); } elseif ('Authorization' === $name) { - $this->assertSame('Bearer masterKey', $value); + self::assertSame('Bearer masterKey', $value); } return $requestStub; }); - $reqFactory->expects($this->once()) + $reqFactory->expects(self::once()) ->method('createRequest') ->willReturn($requestStub); $client = new \Meilisearch\Client('http://localhost:7070', 'masterKey', $httpClient, $reqFactory); - $this->assertTrue($client->isHealthy()); + self::assertTrue($client->isHealthy()); } public function testEmptyMasterkeyRemovesAuthHeader(): void @@ -236,21 +236,21 @@ public function testEmptyMasterkeyRemovesAuthHeader(): void $httpClient = $this->createHttpClientMock(200, '{}'); $reqFactory = $this->createMock(RequestFactoryInterface::class); $requestStub = $this->createMock(RequestInterface::class); - $requestStub->expects($this->once()) + $requestStub->expects(self::once()) ->method('withAddedHeader') ->willReturnCallback(function ($name, $value) use ($requestStub) { - $this->assertSame('User-Agent', $name); - $this->assertSame(Meilisearch::qualifiedVersion(), $value); + self::assertSame('User-Agent', $name); + self::assertSame(Meilisearch::qualifiedVersion(), $value); return $requestStub; }); - $reqFactory->expects($this->once()) + $reqFactory->expects(self::once()) ->method('createRequest') ->willReturn($requestStub); $client = new \Meilisearch\Client('http://localhost:7070', '', $httpClient, $reqFactory); - $this->assertTrue($client->isHealthy()); + self::assertTrue($client->isHealthy()); } public function testClientHasCustomUserAgent(): void @@ -259,24 +259,24 @@ public function testClientHasCustomUserAgent(): void $httpClient = $this->createHttpClientMock(200, '{}'); $reqFactory = $this->createMock(RequestFactoryInterface::class); $requestStub = $this->createMock(RequestInterface::class); - $requestStub->expects($this->exactly(2)) + $requestStub->expects(self::exactly(2)) ->method('withAddedHeader') ->willReturnCallback(function ($name, $value) use ($requestStub, $customAgent) { if ('User-Agent' === $name) { - $this->assertSame($customAgent.';'.Meilisearch::qualifiedVersion(), $value); + self::assertSame($customAgent.';'.Meilisearch::qualifiedVersion(), $value); } elseif ('Authorization' === $name) { - $this->assertSame('Bearer masterKey', $value); + self::assertSame('Bearer masterKey', $value); } return $requestStub; }); - $reqFactory->expects($this->once()) + $reqFactory->expects(self::once()) ->method('createRequest') ->willReturn($requestStub); $client = new \Meilisearch\Client('http://localhost:7070', 'masterKey', $httpClient, $reqFactory, [$customAgent]); - $this->assertTrue($client->isHealthy()); + self::assertTrue($client->isHealthy()); } public function testParseResponseReturnsNullForNoContent(): void @@ -297,7 +297,7 @@ public function testParseResponseReturnsNullForNoContent(): void $result = $client->get('/'); - $this->assertNull($result); + self::assertNull($result); } public static function provideStatusCodes(): iterable diff --git a/tests/Http/Serialize/JsonTest.php b/tests/Http/Serialize/JsonTest.php index c963c519..b0fde989 100644 --- a/tests/Http/Serialize/JsonTest.php +++ b/tests/Http/Serialize/JsonTest.php @@ -15,7 +15,7 @@ public function testSerialize(): void { $data = ['id' => 287947, 'title' => 'Some ID']; $json = new Json(); - $this->assertEquals(json_encode($data), $json->serialize($data)); + self::assertSame(json_encode($data), $json->serialize($data)); } public function testSerializeWithInvalidData(): void @@ -24,14 +24,14 @@ public function testSerializeWithInvalidData(): void $json = new Json(); $this->expectException(JsonEncodingException::class); $this->expectExceptionMessage('Encoding payload to json failed: "Inf and NaN cannot be JSON encoded".'); - $this->assertEquals(json_encode($data), $json->serialize($data)); + self::assertSame(json_encode($data), $json->serialize($data)); } public function testUnserialize(): void { $data = '{"id":287947,"title":"Some ID"}'; $json = new Json(); - $this->assertEquals(['id' => 287947, 'title' => 'Some ID'], $json->unserialize($data)); + self::assertSame(['id' => 287947, 'title' => 'Some ID'], $json->unserialize($data)); } public function testUnserializeWithInvalidData(): void @@ -40,6 +40,6 @@ public function testUnserializeWithInvalidData(): void $json = new Json(); $this->expectException(JsonDecodingException::class); $this->expectExceptionMessage('Decoding payload to json failed: "Syntax error"'); - $this->assertEquals(['id' => 287947, 'title' => 'Some ID'], $json->unserialize($data)); + self::assertSame(['id' => 287947, 'title' => 'Some ID'], $json->unserialize($data)); } } diff --git a/tests/Search/SearchResultTest.php b/tests/Search/SearchResultTest.php index 4a4eb84f..038b4824 100644 --- a/tests/Search/SearchResultTest.php +++ b/tests/Search/SearchResultTest.php @@ -73,41 +73,41 @@ protected function setUp(): void public function testResultCanBeBuilt(): void { - $this->assertCount(2, $this->basicResult); - $this->assertNotEmpty($this->basicResult->getHits()); + self::assertCount(2, $this->basicResult); + self::assertNotEmpty($this->basicResult->getHits()); - $this->assertEquals([ + self::assertSame([ 'id' => '1', 'title' => 'American Pie 2', 'poster' => 'https://image.tmdb.org/t/p/w1280/q4LNgUnRfltxzp3gf1MAGiK5LhV.jpg', 'overview' => 'The whole gang are back and as close as ever. They decide to get even closer by spending the summer together at a beach house. They decide to hold the biggest...', 'release_date' => 997405200, ], $this->basicResult->getHit(0)); - $this->assertEquals([ + self::assertSame([ 'id' => '190859', 'title' => 'American Sniper', 'poster' => 'https://image.tmdb.org/t/p/w1280/svPHnYE7N5NAGO49dBmRhq0vDQ3.jpg', 'overview' => 'U.S. Navy SEAL Chris Kyle takes his sole mission—protect his comrades—to heart and becomes one of the most lethal snipers in American history. His pinpoint accuracy not only saves countless lives but also makes him a prime...', 'release_date' => 1418256000, ], $this->basicResult->getHit(1)); - $this->assertNull($this->basicResult->getHit(2)); - $this->assertSame(0, $this->basicResult->getOffset()); - $this->assertSame(20, $this->basicResult->getLimit()); - $this->assertSame(2, $this->basicResult->getHitsCount()); - $this->assertSame(976, $this->basicResult->getEstimatedTotalHits()); - $this->assertSame(35, $this->basicResult->getProcessingTimeMs()); - $this->assertSame('american', $this->basicResult->getQuery()); - $this->assertEmpty($this->basicResult->getFacetDistribution()); - $this->assertCount(2, $this->basicResult); - - $this->assertArrayHasKey('hits', $this->basicResult->toArray()); - $this->assertArrayHasKey('offset', $this->basicResult->toArray()); - $this->assertArrayHasKey('limit', $this->basicResult->toArray()); - $this->assertArrayHasKey('estimatedTotalHits', $this->basicResult->toArray()); - $this->assertArrayHasKey('hitsCount', $this->basicResult->toArray()); - $this->assertArrayHasKey('processingTimeMs', $this->basicResult->toArray()); - $this->assertArrayHasKey('query', $this->basicResult->toArray()); - $this->assertArrayHasKey('facetDistribution', $this->basicResult->toArray()); + self::assertNull($this->basicResult->getHit(2)); + self::assertSame(0, $this->basicResult->getOffset()); + self::assertSame(20, $this->basicResult->getLimit()); + self::assertSame(2, $this->basicResult->getHitsCount()); + self::assertSame(976, $this->basicResult->getEstimatedTotalHits()); + self::assertSame(35, $this->basicResult->getProcessingTimeMs()); + self::assertSame('american', $this->basicResult->getQuery()); + self::assertEmpty($this->basicResult->getFacetDistribution()); + self::assertCount(2, $this->basicResult); + + self::assertArrayHasKey('hits', $this->basicResult->toArray()); + self::assertArrayHasKey('offset', $this->basicResult->toArray()); + self::assertArrayHasKey('limit', $this->basicResult->toArray()); + self::assertArrayHasKey('estimatedTotalHits', $this->basicResult->toArray()); + self::assertArrayHasKey('hitsCount', $this->basicResult->toArray()); + self::assertArrayHasKey('processingTimeMs', $this->basicResult->toArray()); + self::assertArrayHasKey('query', $this->basicResult->toArray()); + self::assertArrayHasKey('facetDistribution', $this->basicResult->toArray()); } public function testSearchResultCanBeFiltered(): void @@ -123,10 +123,10 @@ function (array $hit): bool { return 'American Sniper' === $hit['title']; } $filteredResults = $this->basicResult->applyOptions($options); - $this->assertCount(1, $filteredResults); - $this->assertSame(1, $filteredResults->getHitsCount()); - $this->assertSame(976, $filteredResults->getEstimatedTotalHits()); - $this->assertEquals([ + self::assertCount(1, $filteredResults); + self::assertSame(1, $filteredResults->getHitsCount()); + self::assertSame(976, $filteredResults->getEstimatedTotalHits()); + self::assertSame([ 'id' => '190859', 'title' => 'American Sniper', 'poster' => 'https://image.tmdb.org/t/p/w1280/svPHnYE7N5NAGO49dBmRhq0vDQ3.jpg', @@ -137,7 +137,7 @@ function (array $hit): bool { return 'American Sniper' === $hit['title']; } public function testResultCanBeReturnedAsJson(): void { - $this->assertJsonStringEqualsJsonString( + self::assertJsonStringEqualsJsonString( '{"hits":[{"id":"1","title":"American Pie 2","poster":"https:\/\/image.tmdb.org\/t\/p\/w1280\/q4LNgUnRfltxzp3gf1MAGiK5LhV.jpg","overview":"The whole gang are back and as close as ever. They decide to get even closer by spending the summer together at a beach house. They decide to hold the biggest...","release_date":997405200},{"id":"190859","title":"American Sniper","poster":"https:\/\/image.tmdb.org\/t\/p\/w1280\/svPHnYE7N5NAGO49dBmRhq0vDQ3.jpg","overview":"U.S. Navy SEAL Chris Kyle takes his sole mission\u2014protect his comrades\u2014to heart and becomes one of the most lethal snipers in American history. His pinpoint accuracy not only saves countless lives but also makes him a prime...","release_date":1418256000}],"offset":0,"limit":20,"estimatedTotalHits":976,"hitsCount":2,"processingTimeMs":35,"query":"american","facetDistribution":[]}', $this->basicResult->toJSON() ); @@ -148,10 +148,10 @@ public function testResultCanBeReturnedAsAnIterator(): void $iterator = $this->basicResult->getIterator(); /* @phpstan-ignore-next-line */ - $this->assertIsIterable($this->basicResult); - $this->assertCount(2, $iterator); + self::assertIsIterable($this->basicResult); + self::assertCount(2, $iterator); - $this->assertEquals([ + self::assertSame([ 'id' => '1', 'title' => 'American Pie 2', 'poster' => 'https://image.tmdb.org/t/p/w1280/q4LNgUnRfltxzp3gf1MAGiK5LhV.jpg', @@ -161,7 +161,7 @@ public function testResultCanBeReturnedAsAnIterator(): void $iterator->next(); - $this->assertEquals([ + self::assertSame([ 'id' => '190859', 'title' => 'American Sniper', 'poster' => 'https://image.tmdb.org/t/p/w1280/svPHnYE7N5NAGO49dBmRhq0vDQ3.jpg', @@ -172,7 +172,7 @@ public function testResultCanBeReturnedAsAnIterator(): void public function testGetRaw(): void { - $this->assertEquals($this->basicServerResponse, $this->basicResult->getRaw()); + self::assertSame($this->basicServerResponse, $this->basicResult->getRaw()); } public function testTransformHitsMethod(): void @@ -186,15 +186,15 @@ function (array $hit): bool { return 'American Sniper' === $hit['title']; } $response = $this->basicResult->transformHits($keepAmericanSniperFunc); - $this->assertArrayHasKey('hits', $response->toArray()); - $this->assertArrayHasKey('offset', $response->toArray()); - $this->assertArrayHasKey('limit', $response->toArray()); - $this->assertArrayHasKey('processingTimeMs', $response->toArray()); - $this->assertArrayHasKey('query', $response->toArray()); - $this->assertSame('American Sniper', $response->getHit(1)['title']); // Not getHits(0) because array_filter() does not reorder the indexes after filtering. - $this->assertSame(976, $response->getEstimatedTotalHits()); - $this->assertSame(1, $response->getHitsCount()); - $this->assertCount(1, $response); + self::assertArrayHasKey('hits', $response->toArray()); + self::assertArrayHasKey('offset', $response->toArray()); + self::assertArrayHasKey('limit', $response->toArray()); + self::assertArrayHasKey('processingTimeMs', $response->toArray()); + self::assertArrayHasKey('query', $response->toArray()); + self::assertSame('American Sniper', $response->getHit(1)['title']); // Not getHits(0) because array_filter() does not reorder the indexes after filtering. + self::assertSame(976, $response->getEstimatedTotalHits()); + self::assertSame(1, $response->getHitsCount()); + self::assertCount(1, $response); } public function testTransformFacetsDistributionMethod(): void @@ -214,17 +214,17 @@ public function testTransformFacetsDistributionMethod(): void $response = $this->resultWithFacets->transformFacetDistribution($facetsToUpperFunc); - $this->assertArrayHasKey('hits', $response->toArray()); - $this->assertArrayHasKey('facetDistribution', $response->toArray()); - $this->assertArrayHasKey('offset', $response->toArray()); - $this->assertArrayHasKey('limit', $response->toArray()); - $this->assertArrayHasKey('processingTimeMs', $response->toArray()); - $this->assertArrayHasKey('query', $response->toArray()); - $this->assertEquals($response->getRaw()['hits'], $response->getHits()); - $this->assertNotEquals($response->getRaw()['facetDistribution'], $response->getFacetDistribution()); - $this->assertCount(3, $response->getFacetDistribution()['genre']); - $this->assertEquals(0, $response->getFacetDistribution()['genre']['ROMANCE']); - $this->assertEquals(1, $response->getFacetDistribution()['genre']['FANTASY']); - $this->assertEquals(1, $response->getFacetDistribution()['genre']['ADVENTURE']); + self::assertArrayHasKey('hits', $response->toArray()); + self::assertArrayHasKey('facetDistribution', $response->toArray()); + self::assertArrayHasKey('offset', $response->toArray()); + self::assertArrayHasKey('limit', $response->toArray()); + self::assertArrayHasKey('processingTimeMs', $response->toArray()); + self::assertArrayHasKey('query', $response->toArray()); + self::assertSame($response->getRaw()['hits'], $response->getHits()); + self::assertNotSame($response->getRaw()['facetDistribution'], $response->getFacetDistribution()); + self::assertCount(3, $response->getFacetDistribution()['genre']); + self::assertSame(0, $response->getFacetDistribution()['genre']['ROMANCE']); + self::assertSame(1, $response->getFacetDistribution()['genre']['FANTASY']); + self::assertSame(1, $response->getFacetDistribution()['genre']['ADVENTURE']); } } diff --git a/tests/Settings/DisplayedAttributesTest.php b/tests/Settings/DisplayedAttributesTest.php index f04abb8f..0283b59f 100644 --- a/tests/Settings/DisplayedAttributesTest.php +++ b/tests/Settings/DisplayedAttributesTest.php @@ -16,8 +16,8 @@ public function testGetDefaultDisplayedAttributes(): void $attributesA = $indexA->getDisplayedAttributes(); $attributesB = $indexB->getDisplayedAttributes(); - $this->assertEquals(['*'], $attributesA); - $this->assertEquals(['*'], $attributesB); + self::assertSame(['*'], $attributesA); + self::assertSame(['*'], $attributesB); } public function testUpdateDisplayedAttributes(): void @@ -32,7 +32,7 @@ public function testUpdateDisplayedAttributes(): void $displayedAttributes = $index->getDisplayedAttributes(); - $this->assertEquals($newAttributes, $displayedAttributes); + self::assertSame($newAttributes, $displayedAttributes); } public function testResetDisplayedAttributes(): void @@ -50,6 +50,6 @@ public function testResetDisplayedAttributes(): void $index->waitForTask($promise['taskUid']); $displayedAttributes = $index->getDisplayedAttributes(); - $this->assertEquals(['*'], $displayedAttributes); + self::assertSame(['*'], $displayedAttributes); } } diff --git a/tests/Settings/DistinctAttributeTest.php b/tests/Settings/DistinctAttributeTest.php index f6c0bddc..8afed197 100644 --- a/tests/Settings/DistinctAttributeTest.php +++ b/tests/Settings/DistinctAttributeTest.php @@ -20,7 +20,7 @@ protected function setUp(): void public function testGetDefaultDistinctAttribute(): void { $response = $this->index->getDistinctAttribute(); - $this->assertNull($response); + self::assertNull($response); } public function testUpdateDistinctAttribute(): void @@ -31,7 +31,7 @@ public function testUpdateDistinctAttribute(): void $this->assertIsValidPromise($promise); $this->index->waitForTask($promise['taskUid']); - $this->assertEquals($distinctAttribute, $this->index->getDistinctAttribute()); + self::assertSame($distinctAttribute, $this->index->getDistinctAttribute()); } public function testResetDistinctAttribute(): void @@ -44,6 +44,6 @@ public function testResetDistinctAttribute(): void $this->assertIsValidPromise($promise); $this->index->waitForTask($promise['taskUid']); - $this->assertNull($this->index->getDistinctAttribute()); + self::assertNull($this->index->getDistinctAttribute()); } } diff --git a/tests/Settings/EmbeddersTest.php b/tests/Settings/EmbeddersTest.php index b16feb20..cccdc1e0 100644 --- a/tests/Settings/EmbeddersTest.php +++ b/tests/Settings/EmbeddersTest.php @@ -22,15 +22,15 @@ public function testGetEmbedders(): void $index = $this->createEmptyIndex($this->safeIndexName('books-1')); $embedders = $index->getEmbedders(); - $this->assertEmpty($embedders); + self::assertEmpty($embedders); } public function testUpdateEmbeddersWithOpenAi(): void { $embedderConfig = [ 'source' => 'openAi', - 'apiKey' => '', 'model' => 'text-embedding-ada-002', + 'apiKey' => '', 'documentTemplate' => "A movie titled '{{doc.title}}' whose description starts with {{doc.overview|truncatewords: 20}}", ]; $index = $this->createEmptyIndex($this->safeIndexName()); @@ -42,7 +42,7 @@ public function testUpdateEmbeddersWithOpenAi(): void $embedders = $index->getEmbedders(); - $this->assertEquals($embedderConfig, $embedders['myEmbedder']); + self::assertSame($embedderConfig, $embedders['myEmbedder']); } public function testUpdateEmbeddersWithUserProvided(): void @@ -60,7 +60,7 @@ public function testUpdateEmbeddersWithUserProvided(): void $embedders = $index->getEmbedders(); - $this->assertEquals($embedderConfig, $embedders['myEmbedder']); + self::assertSame($embedderConfig, $embedders['myEmbedder']); } public function testUpdateEmbeddersWithHuggingFace(): void @@ -79,7 +79,7 @@ public function testUpdateEmbeddersWithHuggingFace(): void $embedders = $index->getEmbedders(); - $this->assertEquals($embedderConfig, $embedders['myEmbedder']); + self::assertSame($embedderConfig, $embedders['myEmbedder']); } public function testResetEmbedders(): void @@ -98,6 +98,6 @@ public function testResetEmbedders(): void $this->assertIsValidPromise($promise); $index->waitForTask($promise['taskUid']); - $this->assertEmpty($index->getEmbedders()); + self::assertEmpty($index->getEmbedders()); } } diff --git a/tests/Settings/FacetingAttributesTest.php b/tests/Settings/FacetingAttributesTest.php index e4b772cb..9c4e0fb2 100644 --- a/tests/Settings/FacetingAttributesTest.php +++ b/tests/Settings/FacetingAttributesTest.php @@ -14,7 +14,7 @@ public function testGetDefaultFaceting(): void $attributes = $index->getFaceting(); - $this->assertEquals([ + self::assertSame([ 'maxValuesPerFacet' => 100, 'sortFacetValuesBy' => [ '*' => 'alpha', @@ -32,7 +32,7 @@ public function testUpdateFacetingAttributes(): void $faceting = $index->getFaceting(); - $this->assertEquals([ + self::assertSame([ 'maxValuesPerFacet' => 100, 'sortFacetValuesBy' => ['*' => 'count'], ], $faceting); @@ -50,7 +50,7 @@ public function testResetFaceting(): void $index->waitForTask($promise['taskUid']); $faceting = $index->getFaceting(); - $this->assertEquals([ + self::assertSame([ 'maxValuesPerFacet' => 100, 'sortFacetValuesBy' => ['*' => 'alpha'], ], $faceting); diff --git a/tests/Settings/FilterableAttributesTest.php b/tests/Settings/FilterableAttributesTest.php index 8a2faae4..cec40c4c 100644 --- a/tests/Settings/FilterableAttributesTest.php +++ b/tests/Settings/FilterableAttributesTest.php @@ -14,7 +14,7 @@ public function testGetDefaultFilterableAttributes(): void $attributes = $index->getFilterableAttributes(); - $this->assertEmpty($attributes); + self::assertEmpty($attributes); } public function testUpdateFilterableAttributes(): void @@ -29,7 +29,7 @@ public function testUpdateFilterableAttributes(): void $filterableAttributes = $index->getFilterableAttributes(); - $this->assertEquals($newAttributes, $filterableAttributes); + self::assertSame($newAttributes, $filterableAttributes); } public function testResetFilterableAttributes(): void @@ -47,6 +47,6 @@ public function testResetFilterableAttributes(): void $index->waitForTask($promise['taskUid']); $filterableAttributes = $index->getFilterableAttributes(); - $this->assertEmpty($filterableAttributes); + self::assertEmpty($filterableAttributes); } } diff --git a/tests/Settings/NonSeparatorTokensTest.php b/tests/Settings/NonSeparatorTokensTest.php index a729f5d9..5838e2d6 100644 --- a/tests/Settings/NonSeparatorTokensTest.php +++ b/tests/Settings/NonSeparatorTokensTest.php @@ -23,7 +23,7 @@ public function testGetDefaultNonSeparatorTokens(): void { $response = $this->index->getNonSeparatorTokens(); - $this->assertEquals(self::DEFAULT_NON_SEPARATOR_TOKENS, $response); + self::assertSame(self::DEFAULT_NON_SEPARATOR_TOKENS, $response); } public function testUpdateNonSeparatorTokens(): void @@ -40,7 +40,7 @@ public function testUpdateNonSeparatorTokens(): void $nonSeparatorTokens = $this->index->getNonSeparatorTokens(); - $this->assertEquals($newNonSeparatorTokens, $nonSeparatorTokens); + self::assertSame($newNonSeparatorTokens, $nonSeparatorTokens); } public function testResetNonSeparatorTokens(): void @@ -50,6 +50,6 @@ public function testResetNonSeparatorTokens(): void $this->index->waitForTask($promise['taskUid']); $nonSeparatorTokens = $this->index->getNonSeparatorTokens(); - $this->assertEquals(self::DEFAULT_NON_SEPARATOR_TOKENS, $nonSeparatorTokens); + self::assertSame(self::DEFAULT_NON_SEPARATOR_TOKENS, $nonSeparatorTokens); } } diff --git a/tests/Settings/ProximityPrecisionTest.php b/tests/Settings/ProximityPrecisionTest.php index 1d690572..6372238b 100644 --- a/tests/Settings/ProximityPrecisionTest.php +++ b/tests/Settings/ProximityPrecisionTest.php @@ -21,7 +21,7 @@ public function testGetDefaultProximityPrecision(): void { $default = $this->index->getProximityPrecision(); - $this->assertSame('byWord', $default); + self::assertSame('byWord', $default); } public function testUpdateProximityPrecision(): void @@ -30,7 +30,7 @@ public function testUpdateProximityPrecision(): void $this->assertIsValidPromise($promise); $this->index->waitForTask($promise['taskUid']); - $this->assertSame('byAttribute', $this->index->getProximityPrecision()); + self::assertSame('byAttribute', $this->index->getProximityPrecision()); } public function testResetProximityPrecision(): void @@ -44,6 +44,6 @@ public function testResetProximityPrecision(): void $this->assertIsValidPromise($promise); $this->index->waitForTask($promise['taskUid']); - $this->assertSame('byWord', $this->index->getProximityPrecision()); + self::assertSame('byWord', $this->index->getProximityPrecision()); } } diff --git a/tests/Settings/RankingRulesTest.php b/tests/Settings/RankingRulesTest.php index dea7d90f..fc98790f 100644 --- a/tests/Settings/RankingRulesTest.php +++ b/tests/Settings/RankingRulesTest.php @@ -30,7 +30,7 @@ public function testGetDefaultRankingRules(): void { $response = $this->index->getRankingRules(); - $this->assertEquals(self::DEFAULT_RANKING_RULES, $response); + self::assertSame(self::DEFAULT_RANKING_RULES, $response); } public function testUpdateRankingRules(): void @@ -48,7 +48,7 @@ public function testUpdateRankingRules(): void $rankingRules = $this->index->getRankingRules(); - $this->assertEquals($newRankingRules, $rankingRules); + self::assertSame($newRankingRules, $rankingRules); } public function testResetRankingRules(): void @@ -60,6 +60,6 @@ public function testResetRankingRules(): void $this->index->waitForTask($promise['taskUid']); $rankingRules = $this->index->getRankingRules(); - $this->assertEquals(self::DEFAULT_RANKING_RULES, $rankingRules); + self::assertSame(self::DEFAULT_RANKING_RULES, $rankingRules); } } diff --git a/tests/Settings/SearchableAttributesTest.php b/tests/Settings/SearchableAttributesTest.php index 031c7eb5..1515d232 100644 --- a/tests/Settings/SearchableAttributesTest.php +++ b/tests/Settings/SearchableAttributesTest.php @@ -16,8 +16,8 @@ public function testGetDefaultSearchableAttributes(): void $searchableAttributesA = $indexA->getSearchableAttributes(); $searchableAttributesB = $indexB->getSearchableAttributes(); - $this->assertEquals(['*'], $searchableAttributesA); - $this->assertEquals(['*'], $searchableAttributesB); + self::assertSame(['*'], $searchableAttributesA); + self::assertSame(['*'], $searchableAttributesB); } public function testUpdateSearchableAttributes(): void @@ -35,7 +35,7 @@ public function testUpdateSearchableAttributes(): void $indexA->waitForTask($promise['taskUid']); $updatedAttributes = $indexA->getSearchableAttributes(); - $this->assertEquals($searchableAttributes, $updatedAttributes); + self::assertSame($searchableAttributes, $updatedAttributes); } public function testResetSearchableAttributes(): void @@ -48,6 +48,6 @@ public function testResetSearchableAttributes(): void $index->waitForTask($promise['taskUid']); $searchableAttributes = $index->getSearchableAttributes(); - $this->assertEquals(['*'], $searchableAttributes); + self::assertSame(['*'], $searchableAttributes); } } diff --git a/tests/Settings/SeparatorTokensTest.php b/tests/Settings/SeparatorTokensTest.php index e935bfe0..bbf1de54 100644 --- a/tests/Settings/SeparatorTokensTest.php +++ b/tests/Settings/SeparatorTokensTest.php @@ -23,7 +23,7 @@ public function testGetDefaultSeparatorTokens(): void { $response = $this->index->getSeparatorTokens(); - $this->assertSame(self::DEFAULT_SEPARATOR_TOKENS, $response); + self::assertSame(self::DEFAULT_SEPARATOR_TOKENS, $response); } public function testUpdateSeparatorTokens(): void @@ -40,7 +40,7 @@ public function testUpdateSeparatorTokens(): void $separatorTokens = $this->index->getSeparatorTokens(); - $this->assertSame($newSeparatorTokens, $separatorTokens); + self::assertSame($newSeparatorTokens, $separatorTokens); } public function testResetSeparatorTokens(): void @@ -50,6 +50,6 @@ public function testResetSeparatorTokens(): void $this->index->waitForTask($promise['taskUid']); $separatorTokens = $this->index->getSeparatorTokens(); - $this->assertSame(self::DEFAULT_SEPARATOR_TOKENS, $separatorTokens); + self::assertSame(self::DEFAULT_SEPARATOR_TOKENS, $separatorTokens); } } diff --git a/tests/Settings/SettingsTest.php b/tests/Settings/SettingsTest.php index ccb0454e..95c5bf6f 100644 --- a/tests/Settings/SettingsTest.php +++ b/tests/Settings/SettingsTest.php @@ -42,37 +42,37 @@ public function testGetDefaultSettings(): void ['primaryKey' => $primaryKey] )->getSettings(); - $this->assertEquals(self::DEFAULT_RANKING_RULES, $settingA['rankingRules']); - $this->assertNull($settingA['distinctAttribute']); - $this->assertIsArray($settingA['searchableAttributes']); - $this->assertEquals(self::DEFAULT_SEARCHABLE_ATTRIBUTES, $settingA['searchableAttributes']); - $this->assertIsArray($settingA['displayedAttributes']); - $this->assertEquals(self::DEFAULT_DISPLAYED_ATTRIBUTES, $settingA['displayedAttributes']); - $this->assertIsArray($settingA['stopWords']); - $this->assertEmpty($settingA['stopWords']); - $this->assertIsIterable($settingA['synonyms']); - $this->assertEmpty($settingA['synonyms']); - $this->assertIsArray($settingA['filterableAttributes']); - $this->assertEmpty($settingA['filterableAttributes']); - $this->assertIsArray($settingA['sortableAttributes']); - $this->assertEmpty($settingA['sortableAttributes']); - $this->assertIsIterable($settingA['typoTolerance']); - $this->assertEquals(self::DEFAULT_TYPO_TOLERANCE, iterator_to_array($settingA['typoTolerance'])); - - $this->assertEquals(self::DEFAULT_RANKING_RULES, $settingB['rankingRules']); - $this->assertNull($settingB['distinctAttribute']); - $this->assertEquals(self::DEFAULT_SEARCHABLE_ATTRIBUTES, $settingB['searchableAttributes']); - $this->assertEquals(self::DEFAULT_DISPLAYED_ATTRIBUTES, $settingB['displayedAttributes']); - $this->assertIsArray($settingB['stopWords']); - $this->assertEmpty($settingB['stopWords']); - $this->assertIsIterable($settingB['synonyms']); - $this->assertEmpty($settingB['synonyms']); - $this->assertIsArray($settingB['filterableAttributes']); - $this->assertEmpty($settingB['filterableAttributes']); - $this->assertIsArray($settingB['sortableAttributes']); - $this->assertEmpty($settingB['sortableAttributes']); - $this->assertIsIterable($settingB['typoTolerance']); - $this->assertEquals(self::DEFAULT_TYPO_TOLERANCE, iterator_to_array($settingB['typoTolerance'])); + self::assertSame(self::DEFAULT_RANKING_RULES, $settingA['rankingRules']); + self::assertNull($settingA['distinctAttribute']); + self::assertIsArray($settingA['searchableAttributes']); + self::assertSame(self::DEFAULT_SEARCHABLE_ATTRIBUTES, $settingA['searchableAttributes']); + self::assertIsArray($settingA['displayedAttributes']); + self::assertSame(self::DEFAULT_DISPLAYED_ATTRIBUTES, $settingA['displayedAttributes']); + self::assertIsArray($settingA['stopWords']); + self::assertEmpty($settingA['stopWords']); + self::assertIsIterable($settingA['synonyms']); + self::assertEmpty($settingA['synonyms']); + self::assertIsArray($settingA['filterableAttributes']); + self::assertEmpty($settingA['filterableAttributes']); + self::assertIsArray($settingA['sortableAttributes']); + self::assertEmpty($settingA['sortableAttributes']); + self::assertIsIterable($settingA['typoTolerance']); + self::assertSame(self::DEFAULT_TYPO_TOLERANCE, iterator_to_array($settingA['typoTolerance'])); + + self::assertSame(self::DEFAULT_RANKING_RULES, $settingB['rankingRules']); + self::assertNull($settingB['distinctAttribute']); + self::assertSame(self::DEFAULT_SEARCHABLE_ATTRIBUTES, $settingB['searchableAttributes']); + self::assertSame(self::DEFAULT_DISPLAYED_ATTRIBUTES, $settingB['displayedAttributes']); + self::assertIsArray($settingB['stopWords']); + self::assertEmpty($settingB['stopWords']); + self::assertIsIterable($settingB['synonyms']); + self::assertEmpty($settingB['synonyms']); + self::assertIsArray($settingB['filterableAttributes']); + self::assertEmpty($settingB['filterableAttributes']); + self::assertIsArray($settingB['sortableAttributes']); + self::assertEmpty($settingB['sortableAttributes']); + self::assertIsIterable($settingB['typoTolerance']); + self::assertSame(self::DEFAULT_TYPO_TOLERANCE, iterator_to_array($settingB['typoTolerance'])); } public function testUpdateSettings(): void @@ -88,20 +88,20 @@ public function testUpdateSettings(): void $settings = $index->getSettings(); - $this->assertEquals(['title:asc', 'typo'], $settings['rankingRules']); - $this->assertEquals('title', $settings['distinctAttribute']); - $this->assertIsArray($settings['searchableAttributes']); - $this->assertEquals(self::DEFAULT_SEARCHABLE_ATTRIBUTES, $settings['searchableAttributes']); - $this->assertIsArray($settings['displayedAttributes']); - $this->assertEquals(self::DEFAULT_DISPLAYED_ATTRIBUTES, $settings['displayedAttributes']); - $this->assertEquals(['the'], $settings['stopWords']); - $this->assertIsIterable($settings['synonyms']); - $this->assertEmpty($settings['synonyms']); - $this->assertIsArray($settings['filterableAttributes']); - $this->assertEmpty($settings['filterableAttributes']); - $this->assertIsArray($settings['sortableAttributes']); - $this->assertEmpty($settings['sortableAttributes']); - $this->assertEquals(self::DEFAULT_TYPO_TOLERANCE, iterator_to_array($settings['typoTolerance'])); + self::assertSame(['title:asc', 'typo'], $settings['rankingRules']); + self::assertSame('title', $settings['distinctAttribute']); + self::assertIsArray($settings['searchableAttributes']); + self::assertSame(self::DEFAULT_SEARCHABLE_ATTRIBUTES, $settings['searchableAttributes']); + self::assertIsArray($settings['displayedAttributes']); + self::assertSame(self::DEFAULT_DISPLAYED_ATTRIBUTES, $settings['displayedAttributes']); + self::assertSame(['the'], $settings['stopWords']); + self::assertIsIterable($settings['synonyms']); + self::assertEmpty($settings['synonyms']); + self::assertIsArray($settings['filterableAttributes']); + self::assertEmpty($settings['filterableAttributes']); + self::assertIsArray($settings['sortableAttributes']); + self::assertEmpty($settings['sortableAttributes']); + self::assertSame(self::DEFAULT_TYPO_TOLERANCE, iterator_to_array($settings['typoTolerance'])); } public function testUpdateSettingsWithoutOverwritingThem(): void @@ -136,19 +136,19 @@ public function testUpdateSettingsWithoutOverwritingThem(): void $settings = $index->getSettings(); - $this->assertEquals(['title:asc', 'typo'], $settings['rankingRules']); - $this->assertEquals('title', $settings['distinctAttribute']); - $this->assertEquals(['title'], $settings['searchableAttributes']); - $this->assertIsArray($settings['displayedAttributes']); - $this->assertEquals(self::DEFAULT_SEARCHABLE_ATTRIBUTES, $settings['displayedAttributes']); - $this->assertEquals(['the'], $settings['stopWords']); - $this->assertIsIterable($settings['synonyms']); - $this->assertEmpty($settings['synonyms']); - $this->assertIsArray($settings['filterableAttributes']); - $this->assertEmpty($settings['filterableAttributes']); - $this->assertIsArray($settings['sortableAttributes']); - $this->assertEmpty($settings['sortableAttributes']); - $this->assertEquals($new_typo_tolerance, iterator_to_array($settings['typoTolerance'])); + self::assertSame(['title:asc', 'typo'], $settings['rankingRules']); + self::assertSame('title', $settings['distinctAttribute']); + self::assertSame(['title'], $settings['searchableAttributes']); + self::assertIsArray($settings['displayedAttributes']); + self::assertSame(self::DEFAULT_SEARCHABLE_ATTRIBUTES, $settings['displayedAttributes']); + self::assertSame(['the'], $settings['stopWords']); + self::assertIsIterable($settings['synonyms']); + self::assertEmpty($settings['synonyms']); + self::assertIsArray($settings['filterableAttributes']); + self::assertEmpty($settings['filterableAttributes']); + self::assertIsArray($settings['sortableAttributes']); + self::assertEmpty($settings['sortableAttributes']); + self::assertSame($new_typo_tolerance, iterator_to_array($settings['typoTolerance'])); } public function testResetSettings(): void @@ -169,21 +169,21 @@ public function testResetSettings(): void $settings = $index->getSettings(); - $this->assertEquals(self::DEFAULT_RANKING_RULES, $settings['rankingRules']); - $this->assertNull($settings['distinctAttribute']); - $this->assertIsArray($settings['searchableAttributes']); - $this->assertEquals(self::DEFAULT_SEARCHABLE_ATTRIBUTES, $settings['searchableAttributes']); - $this->assertIsArray($settings['displayedAttributes']); - $this->assertEquals(self::DEFAULT_SEARCHABLE_ATTRIBUTES, $settings['displayedAttributes']); - $this->assertIsArray($settings['stopWords']); - $this->assertEmpty($settings['stopWords']); - $this->assertIsIterable($settings['synonyms']); - $this->assertEmpty($settings['synonyms']); - $this->assertIsArray($settings['filterableAttributes']); - $this->assertEmpty($settings['filterableAttributes']); - $this->assertIsArray($settings['sortableAttributes']); - $this->assertEmpty($settings['sortableAttributes']); - $this->assertEquals(self::DEFAULT_TYPO_TOLERANCE, iterator_to_array($settings['typoTolerance'])); + self::assertSame(self::DEFAULT_RANKING_RULES, $settings['rankingRules']); + self::assertNull($settings['distinctAttribute']); + self::assertIsArray($settings['searchableAttributes']); + self::assertSame(self::DEFAULT_SEARCHABLE_ATTRIBUTES, $settings['searchableAttributes']); + self::assertIsArray($settings['displayedAttributes']); + self::assertSame(self::DEFAULT_SEARCHABLE_ATTRIBUTES, $settings['displayedAttributes']); + self::assertIsArray($settings['stopWords']); + self::assertEmpty($settings['stopWords']); + self::assertIsIterable($settings['synonyms']); + self::assertEmpty($settings['synonyms']); + self::assertIsArray($settings['filterableAttributes']); + self::assertEmpty($settings['filterableAttributes']); + self::assertIsArray($settings['sortableAttributes']); + self::assertEmpty($settings['sortableAttributes']); + self::assertSame(self::DEFAULT_TYPO_TOLERANCE, iterator_to_array($settings['typoTolerance'])); } // Here the test to prevent https://github.com/meilisearch/meilisearch-php/issues/204. diff --git a/tests/Settings/SortableAttributesTest.php b/tests/Settings/SortableAttributesTest.php index 3450f8d9..02698a26 100644 --- a/tests/Settings/SortableAttributesTest.php +++ b/tests/Settings/SortableAttributesTest.php @@ -14,7 +14,7 @@ public function testGetDefaultSortableAttributes(): void $attributes = $index->getSortableAttributes(); - $this->assertEmpty($attributes); + self::assertEmpty($attributes); } public function testUpdateSortableAttributes(): void @@ -29,7 +29,7 @@ public function testUpdateSortableAttributes(): void $sortableAttributes = $index->getSortableAttributes(); - $this->assertEquals($newAttributes, $sortableAttributes); + self::assertSame($newAttributes, $sortableAttributes); } public function testResetSortableAttributes(): void @@ -47,6 +47,6 @@ public function testResetSortableAttributes(): void $index->waitForTask($promise['taskUid']); $sortableAttributes = $index->getSortableAttributes(); - $this->assertEmpty($sortableAttributes); + self::assertEmpty($sortableAttributes); } } diff --git a/tests/Settings/StopWordsTest.php b/tests/Settings/StopWordsTest.php index 13c2dae3..4a7148a6 100644 --- a/tests/Settings/StopWordsTest.php +++ b/tests/Settings/StopWordsTest.php @@ -21,7 +21,7 @@ public function testGetDefaultStopWords(): void { $response = $this->index->getStopWords(); - $this->assertEmpty($response); + self::assertEmpty($response); } public function testUpdateStopWords(): void @@ -34,7 +34,7 @@ public function testUpdateStopWords(): void $this->index->waitForTask($promise['taskUid']); $stopWords = $this->index->getStopWords(); - $this->assertEquals($newStopWords, $stopWords); + self::assertSame($newStopWords, $stopWords); } public function testResetStopWords(): void @@ -49,6 +49,6 @@ public function testResetStopWords(): void $stopWords = $this->index->getStopWords(); - $this->assertEmpty($stopWords); + self::assertEmpty($stopWords); } } diff --git a/tests/Settings/SynonymsTest.php b/tests/Settings/SynonymsTest.php index 3606d4b2..121dbda5 100644 --- a/tests/Settings/SynonymsTest.php +++ b/tests/Settings/SynonymsTest.php @@ -19,7 +19,7 @@ protected function setUp(): void public function testGetDefaultSynonyms(): void { - $this->assertEmpty($this->index->getSynonyms()); + self::assertEmpty($this->index->getSynonyms()); } public function testUpdateSynonyms(): void @@ -34,7 +34,7 @@ public function testUpdateSynonyms(): void $this->index->waitForTask($promise['taskUid']); $synonyms = $this->index->getSynonyms(); - $this->assertEquals($newSynonyms, $synonyms); + self::assertSame($newSynonyms, $synonyms); } public function testUpdateSynonymsWithEmptyArray(): void @@ -47,7 +47,7 @@ public function testUpdateSynonymsWithEmptyArray(): void $this->index->waitForTask($promise['taskUid']); $synonyms = $this->index->getSynonyms(); - $this->assertEquals($newSynonyms, $synonyms); + self::assertSame($newSynonyms, $synonyms); } public function testResetSynonyms(): void @@ -63,6 +63,6 @@ public function testResetSynonyms(): void $this->index->waitForTask($promise['taskUid']); $synonyms = $this->index->getSynonyms(); - $this->assertEmpty($synonyms); + self::assertEmpty($synonyms); } } diff --git a/tests/Settings/TypoToleranceTest.php b/tests/Settings/TypoToleranceTest.php index 0567c1e7..9676ece3 100644 --- a/tests/Settings/TypoToleranceTest.php +++ b/tests/Settings/TypoToleranceTest.php @@ -31,7 +31,7 @@ public function testGetDefaultTypoTolerance(): void { $response = $this->index->getTypoTolerance(); - $this->assertEquals(self::DEFAULT_TYPO_TOLERANCE, $response); + self::assertSame(self::DEFAULT_TYPO_TOLERANCE, $response); } public function testUpdateTypoTolerance(): void @@ -50,7 +50,7 @@ public function testUpdateTypoTolerance(): void $typoTolerance = $this->index->getTypoTolerance(); $this->assertIsValidPromise($promise); - $this->assertEquals($newTypoTolerance, $typoTolerance); + self::assertSame($newTypoTolerance, $typoTolerance); } public function testResetTypoTolerance(): void @@ -60,6 +60,6 @@ public function testResetTypoTolerance(): void $typoTolerance = $this->index->getTypoTolerance(); $this->assertIsValidPromise($promise); - $this->assertEquals(self::DEFAULT_TYPO_TOLERANCE, $typoTolerance); + self::assertSame(self::DEFAULT_TYPO_TOLERANCE, $typoTolerance); } } diff --git a/tests/Settings/WordDictionaryTest.php b/tests/Settings/WordDictionaryTest.php index 04865229..f8a4fbdc 100644 --- a/tests/Settings/WordDictionaryTest.php +++ b/tests/Settings/WordDictionaryTest.php @@ -23,7 +23,7 @@ public function testGetDefaultWordDictionary(): void { $response = $this->index->getDictionary(); - $this->assertSame(self::DEFAULT_WORD_DICTIONARY, $response); + self::assertSame(self::DEFAULT_WORD_DICTIONARY, $response); } public function testUpdateWordDictionary(): void @@ -39,7 +39,7 @@ public function testUpdateWordDictionary(): void $wordDictionary = $this->index->getDictionary(); - $this->assertSame($newWordDictionary, $wordDictionary); + self::assertSame($newWordDictionary, $wordDictionary); } public function testResetWordDictionary(): void @@ -49,6 +49,6 @@ public function testResetWordDictionary(): void $this->index->waitForTask($promise['taskUid']); $wordDictionary = $this->index->getDictionary(); - $this->assertSame(self::DEFAULT_WORD_DICTIONARY, $wordDictionary); + self::assertSame(self::DEFAULT_WORD_DICTIONARY, $wordDictionary); } } diff --git a/tests/TestCase.php b/tests/TestCase.php index 25dc3092..be414382 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -66,7 +66,7 @@ protected function tearDown(): void public function assertIsValidPromise(array $promise): void { - $this->assertArrayHasKey('taskUid', $promise); + self::assertArrayHasKey('taskUid', $promise); } public function assertFinitePagination(array $response): void @@ -75,7 +75,7 @@ public function assertFinitePagination(array $response): void $validBody = ['hitsPerPage', 'totalHits', 'totalPages', 'page', 'processingTimeMs', 'query', 'hits']; foreach ($validBody as $value) { - $this->assertContains( + self::assertContains( $value, $currentKeys, 'Not a valid finite pagination response, since the "'.$value.'" key is not present in: ['.implode( @@ -92,7 +92,7 @@ public function assertEstimatedPagination(array $response): void $validBody = ['offset', 'limit', 'estimatedTotalHits', 'processingTimeMs', 'query', 'hits']; foreach ($validBody as $value) { - $this->assertContains( + self::assertContains( $value, $currentKeys, 'Not a valid estimated pagination response, since the "'.$value.'" key is not present in: ['.implode( diff --git a/tests/VersionTest.php b/tests/VersionTest.php index 4b151536..2d7e1e2a 100644 --- a/tests/VersionTest.php +++ b/tests/VersionTest.php @@ -12,6 +12,6 @@ public function testQualifiedVersion(): void { $qualifiedVersion = sprintf('Meilisearch PHP (v%s)', Meilisearch::VERSION); - $this->assertEquals(Meilisearch::qualifiedVersion(), $qualifiedVersion); + self::assertSame(Meilisearch::qualifiedVersion(), $qualifiedVersion); } }