diff --git a/.github/workflows/release-drafter.yml b/.github/workflows/release-drafter.yml index 20f2d83f..49fbecc2 100644 --- a/.github/workflows/release-drafter.yml +++ b/.github/workflows/release-drafter.yml @@ -4,6 +4,7 @@ on: push: branches: - main + - v1.x jobs: update_release_draft: diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index f095115f..562c45a0 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -9,6 +9,7 @@ on: - staging - main - feature/** + - v1.x jobs: yaml-lint: diff --git a/composer.json b/composer.json index 8e382a03..52c1875c 100644 --- a/composer.json +++ b/composer.json @@ -13,8 +13,20 @@ "license": "MIT", "authors": [ { - "name": "Clementine", + "name": "Clémentine Urquizar", "email": "clementine@meilisearch.com" + }, + { + "name": "Bruno Casali", + "email": "bruno@meilisearch.com" + }, + { + "name": "Laurent Cazanove", + "email": "lau.cazanove@gmail.com" + }, + { + "name": "Tomas Norkūnas", + "email": "norkunas.tom@gmail.com" } ], "minimum-stability": "stable", @@ -58,7 +70,9 @@ "./vendor/bin/php-cs-fixer fix --verbose --config=.php-cs-fixer.dist.php --using-cache=no --diff" ], "phpstan": "./vendor/bin/phpstan", - "test": ["sh scripts/tests.sh"] + "test": [ + "sh scripts/tests.sh" + ] }, "config": { "allow-plugins": { diff --git a/src/Endpoints/Delegates/HandlesMultiSearch.php b/src/Endpoints/Delegates/HandlesMultiSearch.php index 4cd84f9b..c6e76123 100644 --- a/src/Endpoints/Delegates/HandlesMultiSearch.php +++ b/src/Endpoints/Delegates/HandlesMultiSearch.php @@ -25,7 +25,7 @@ public function multiSearch(array $queries = [], ?MultiSearchFederation $federat $payload = ['queries' => $body]; if (null !== $federation) { - $payload['federation'] = $federation->toArray(); + $payload['federation'] = (object) $federation->toArray(); } return $this->http->post('/multi-search', $payload); diff --git a/src/Exceptions/ApiException.php b/src/Exceptions/ApiException.php index 2e0f21c7..f7ebc1e9 100644 --- a/src/Exceptions/ApiException.php +++ b/src/Exceptions/ApiException.php @@ -33,7 +33,7 @@ public function __toString() { $base = 'Meilisearch ApiException: Http Status: '.$this->httpStatus; - if (!\is_null($this->message)) { + if ('' !== $this->message) { $base .= ' - Message: '.$this->message; } diff --git a/src/Exceptions/InvalidResponseBodyException.php b/src/Exceptions/InvalidResponseBodyException.php index 5eff72fd..5245df44 100644 --- a/src/Exceptions/InvalidResponseBodyException.php +++ b/src/Exceptions/InvalidResponseBodyException.php @@ -25,7 +25,7 @@ public function __toString() { $base = 'Meilisearch InvalidResponseBodyException: Http Status: '.$this->httpStatus; - if ($this->message) { + if ('' !== $this->message) { $base .= ' - Message: '.$this->message; } diff --git a/src/Exceptions/TimeOutException.php b/src/Exceptions/TimeOutException.php index 7a4cee15..cf2c3a6e 100644 --- a/src/Exceptions/TimeOutException.php +++ b/src/Exceptions/TimeOutException.php @@ -20,7 +20,7 @@ public function __construct(?string $message = null, ?int $code = null, ?\Throwa public function __toString() { $base = 'Meilisearch TimeOutException: Code: '.$this->code; - if ($this->message) { + if ('' !== $this->message) { return $base.' - Message: '.$this->message; } else { return $base; diff --git a/tests/Endpoints/MultiSearchTest.php b/tests/Endpoints/MultiSearchTest.php index 9d82ac9c..5935ac16 100644 --- a/tests/Endpoints/MultiSearchTest.php +++ b/tests/Endpoints/MultiSearchTest.php @@ -4,10 +4,14 @@ namespace Tests\Endpoints; +use Meilisearch\Client; use Meilisearch\Contracts\FederationOptions; use Meilisearch\Contracts\MultiSearchFederation; use Meilisearch\Contracts\SearchQuery; use Meilisearch\Endpoints\Indexes; +use Symfony\Component\HttpClient\MockHttpClient; +use Symfony\Component\HttpClient\Psr18Client; +use Symfony\Component\HttpClient\Response\MockResponse; use Tests\TestCase; final class MultiSearchTest extends TestCase @@ -159,4 +163,26 @@ public function testMultiSearchWithDistinctAttribute(): void self::assertCount(1, $response['results'][1]['hits']); self::assertSame('fantasy', $response['results'][1]['hits'][0]['genre']); } + + public function testMultiSearchFederationCastingToObject(): void + { + $httpClient = new MockHttpClient(static function (string $method, string $url, array $options): MockResponse { + self::assertSame('POST', $method); + self::assertSame('http://meilisearch/multi-search', $url); + self::assertSame('{"queries":[{"indexUid":"first"},{"indexUid":"second"}],"federation":{}}', $options['body']); + + return new MockResponse( + json_encode(['results' => []], \JSON_THROW_ON_ERROR), + ['response_headers' => ['content-type' => 'application/json']], + ); + }); + + $client = new Client('http://meilisearch', 'apikey', new Psr18Client($httpClient)); + $client->multiSearch([ + (new SearchQuery())->setIndexUid('first'), + (new SearchQuery())->setIndexUid('second'), + ], + new MultiSearchFederation() + ); + } }