SearchableAttributesTest.php 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <?php
  2. declare(strict_types=1);
  3. namespace Tests\Settings;
  4. use Tests\TestCase;
  5. final class SearchableAttributesTest extends TestCase
  6. {
  7. public function testGetDefaultSearchableAttributes(): void
  8. {
  9. $indexA = $this->client->createIndex('indexA');
  10. $indexB = $this->client->createIndex('indexB', ['primaryKey' => 'objectID']);
  11. $searchableAttributesA = $indexA->getSearchableAttributes();
  12. $searchableAttributesB = $indexB->getSearchableAttributes();
  13. $this->assertIsArray($searchableAttributesA);
  14. $this->assertEquals(['*'], $searchableAttributesA);
  15. $this->assertIsArray($searchableAttributesB);
  16. $this->assertEquals(['*'], $searchableAttributesB);
  17. }
  18. public function testUpdateSearchableAttributes(): void
  19. {
  20. $indexA = $this->client->createIndex('indexA');
  21. $searchableAttributes = [
  22. 'title',
  23. 'description',
  24. ];
  25. $promise = $indexA->updateSearchableAttributes($searchableAttributes);
  26. $this->assertIsValidPromise($promise);
  27. $indexA->waitForPendingUpdate($promise['updateId']);
  28. $updatedAttributes = $indexA->getSearchableAttributes();
  29. $this->assertIsArray($updatedAttributes);
  30. $this->assertEquals($searchableAttributes, $updatedAttributes);
  31. }
  32. public function testResetSearchableAttributes(): void
  33. {
  34. $index = $this->client->createIndex('indexA');
  35. $promise = $index->resetSearchableAttributes();
  36. $this->assertIsValidPromise($promise);
  37. $index->waitForPendingUpdate($promise['updateId']);
  38. $searchableAttributes = $index->getSearchableAttributes();
  39. $this->assertIsArray($searchableAttributes);
  40. $this->assertEquals(['*'], $searchableAttributes);
  41. }
  42. }