Skip to content

Commit 90240b3

Browse files
committed
Add unit test for multisearch federation array to object casting
1 parent 015c14e commit 90240b3

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

tests/Endpoints/MultiSearchTest.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,14 @@
44

55
namespace Tests\Endpoints;
66

7+
use Meilisearch\Client;
78
use Meilisearch\Contracts\FederationOptions;
89
use Meilisearch\Contracts\MultiSearchFederation;
910
use Meilisearch\Contracts\SearchQuery;
1011
use Meilisearch\Endpoints\Indexes;
12+
use Symfony\Component\HttpClient\MockHttpClient;
13+
use Symfony\Component\HttpClient\Psr18Client;
14+
use Symfony\Component\HttpClient\Response\MockResponse;
1115
use Tests\TestCase;
1216

1317
final class MultiSearchTest extends TestCase
@@ -159,4 +163,26 @@ public function testMultiSearchWithDistinctAttribute(): void
159163
self::assertCount(1, $response['results'][1]['hits']);
160164
self::assertSame('fantasy', $response['results'][1]['hits'][0]['genre']);
161165
}
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+
}
162188
}

0 commit comments

Comments
 (0)