|
4 | 4 |
|
5 | 5 | namespace Tests\Endpoints;
|
6 | 6 |
|
| 7 | +use GuzzleHttp\Handler\MockHandler; |
| 8 | +use GuzzleHttp\HandlerStack; |
| 9 | +use GuzzleHttp\Middleware; |
| 10 | +use GuzzleHttp\Psr7\Response; |
| 11 | +use Meilisearch\Client; |
7 | 12 | use Meilisearch\Contracts\FederationOptions;
|
8 | 13 | use Meilisearch\Contracts\MultiSearchFederation;
|
9 | 14 | use Meilisearch\Contracts\SearchQuery;
|
@@ -159,4 +164,27 @@ public function testMultiSearchWithDistinctAttribute(): void
|
159 | 164 | self::assertCount(1, $response['results'][1]['hits']);
|
160 | 165 | self::assertSame('fantasy', $response['results'][1]['hits'][0]['genre']);
|
161 | 166 | }
|
| 167 | + |
| 168 | + public function testMultiSearchFederationCastingToObject(): void |
| 169 | + { |
| 170 | + $historyContainer = []; |
| 171 | + $handlerStack = HandlerStack::create(new MockHandler([ |
| 172 | + new Response(200, ['content-type' => 'application/json'], json_encode(['results' => []], JSON_THROW_ON_ERROR)), |
| 173 | + ])); |
| 174 | + $handlerStack->push(Middleware::history($historyContainer)); |
| 175 | + |
| 176 | + $client = new Client('http://meilisearch', 'apikey', new \GuzzleHttp\Client(['handler' => $handlerStack])); |
| 177 | + $client->multiSearch([ |
| 178 | + (new SearchQuery())->setIndexUid('first'), |
| 179 | + (new SearchQuery())->setIndexUid('second'), |
| 180 | + ], |
| 181 | + new MultiSearchFederation() |
| 182 | + ); |
| 183 | + |
| 184 | + self::assertCount(1, $historyContainer); |
| 185 | + |
| 186 | + $request = $historyContainer[0]['request']; |
| 187 | + |
| 188 | + self::assertSame('{"queries":[{"indexUid":"first"},{"indexUid":"second"}],"federation":{}}', $request->getBody()->getContents()); |
| 189 | + } |
162 | 190 | }
|
0 commit comments