Skip to content

Commit 1bb9668

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

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

tests/Endpoints/MultiSearchTest.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,15 @@
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\JsonMockResponse;
15+
use Symfony\Component\HttpClient\Response\MockResponse;
1116
use Tests\TestCase;
1217

1318
final class MultiSearchTest extends TestCase
@@ -159,4 +164,23 @@ public function testMultiSearchWithDistinctAttribute(): void
159164
self::assertCount(1, $response['results'][1]['hits']);
160165
self::assertSame('fantasy', $response['results'][1]['hits'][0]['genre']);
161166
}
167+
168+
public function testMultiSearchFederationCastingToObject(): void
169+
{
170+
$httpClient = new MockHttpClient(static function (string $method, string $url, array $options): MockResponse {
171+
self::assertSame('POST', $method);
172+
self::assertSame('http://meilisearch/multi-search', $url);
173+
self::assertSame('{"queries":[{"indexUid":"first"},{"indexUid":"second"}],"federation":{}}', $options['body']);
174+
175+
return new JsonMockResponse(['results' => []]);
176+
});
177+
178+
$client = new Client('http://meilisearch', 'apikey', new Psr18Client($httpClient));
179+
$client->multiSearch([
180+
(new SearchQuery())->setIndexUid('first'),
181+
(new SearchQuery())->setIndexUid('second'),
182+
],
183+
new MultiSearchFederation()
184+
);
185+
}
162186
}

0 commit comments

Comments
 (0)