|
4 | 4 |
|
5 | 5 | namespace Tests\Endpoints; |
6 | 6 |
|
| 7 | +use Meilisearch\Client; |
7 | 8 | use Meilisearch\Contracts\FederationOptions; |
8 | 9 | use Meilisearch\Contracts\MultiSearchFederation; |
9 | 10 | use Meilisearch\Contracts\SearchQuery; |
10 | 11 | use Meilisearch\Endpoints\Indexes; |
| 12 | +use Symfony\Component\HttpClient\MockHttpClient; |
| 13 | +use Symfony\Component\HttpClient\Psr18Client; |
| 14 | +use Symfony\Component\HttpClient\Response\MockResponse; |
11 | 15 | use Tests\TestCase; |
12 | 16 |
|
13 | 17 | final class MultiSearchTest extends TestCase |
@@ -159,4 +163,26 @@ public function testMultiSearchWithDistinctAttribute(): void |
159 | 163 | self::assertCount(1, $response['results'][1]['hits']); |
160 | 164 | self::assertSame('fantasy', $response['results'][1]['hits'][0]['genre']); |
161 | 165 | } |
| 166 | + |
| 167 | + public function testMultiSearchFederationCastingToObject(): void |
| 168 | + { |
| 169 | + $httpClient = new MockHttpClient(static function (string $method, string $url, array $options): MockResponse { |
| 170 | + self::assertSame('POST', $method); |
| 171 | + self::assertSame('http://meilisearch/multi-search', $url); |
| 172 | + self::assertSame('{"queries":[{"indexUid":"first"},{"indexUid":"second"}],"federation":{}}', $options['body']); |
| 173 | + |
| 174 | + return new MockResponse( |
| 175 | + json_encode(['results' => []], \JSON_THROW_ON_ERROR), |
| 176 | + ['response_headers' => ['content-type' => 'application/json']], |
| 177 | + ); |
| 178 | + }); |
| 179 | + |
| 180 | + $client = new Client('http://meilisearch', 'apikey', new Psr18Client($httpClient)); |
| 181 | + $client->multiSearch([ |
| 182 | + (new SearchQuery())->setIndexUid('first'), |
| 183 | + (new SearchQuery())->setIndexUid('second'), |
| 184 | + ], |
| 185 | + new MultiSearchFederation() |
| 186 | + ); |
| 187 | + } |
162 | 188 | } |
0 commit comments