UpdatesTest.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. <?php
  2. declare(strict_types=1);
  3. namespace Tests\Endpoints;
  4. use MeiliSearch\Exceptions\ApiException;
  5. use Tests\TestCase;
  6. final class UpdatesTest extends TestCase
  7. {
  8. private $index;
  9. protected function setUp(): void
  10. {
  11. parent::setUp();
  12. $this->index = $this->client->createIndex('index');
  13. }
  14. public function testGetOneUpdate(): void
  15. {
  16. [$promise, $response] = $this->seedIndex();
  17. $this->assertIsArray($response);
  18. $this->assertSame($response['status'], 'processed');
  19. $this->assertSame($response['updateId'], $promise['updateId']);
  20. $this->assertArrayHasKey('type', $response);
  21. $this->assertIsArray($response['type']);
  22. $this->assertArrayHasKey('duration', $response);
  23. $this->assertArrayHasKey('enqueuedAt', $response);
  24. $this->assertArrayHasKey('processedAt', $response);
  25. }
  26. public function testGetAllUpdates(): void
  27. {
  28. $this->seedIndex();
  29. $response = $this->index->getAllUpdateStatus();
  30. $this->assertCount(1, $response);
  31. $this->assertSame('processed', $response[0]['status']);
  32. $this->assertArrayHasKey('updateId', $response[0]);
  33. $this->assertArrayHasKey('type', $response[0]);
  34. $this->assertIsArray($response[0]['type']);
  35. $this->assertArrayHasKey('duration', $response[0]);
  36. $this->assertArrayHasKey('enqueuedAt', $response[0]);
  37. $this->assertArrayHasKey('processedAt', $response[0]);
  38. }
  39. public function testExceptionIfNoUpdateIdWhenGetting(): void
  40. {
  41. $this->expectException(ApiException::class);
  42. $this->index->getUpdateStatus(10000);
  43. }
  44. private function seedIndex(): array
  45. {
  46. $promise = $this->index->updateDocuments(self::DOCUMENTS);
  47. $response = $this->index->waitForPendingUpdate($promise['updateId']);
  48. return [$promise, $response];
  49. }
  50. }