Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cast federation payload explicilty to an object #686

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

thijskuilman
Copy link

Pull Request

Related issue

Fixes #685

What does this PR do?

  • It casts the federation payload explicitly to an object. This solves the error that appears when no MultiSearchFederation properties have been set.

PR checklist

Please check if your PR fulfills the following requirements:

  • Does this PR fix an existing issue, or have you listed the changes applied in the PR description (and why they are needed)?
  • Have you read the contributing guidelines?
  • Have you made sure that the title is accurate and descriptive of the changes?

@norkunas
Copy link
Collaborator

norkunas commented Oct 4, 2024

Please add test then to avoid regressions in future

Copy link

codecov bot commented Oct 4, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 89.71%. Comparing base (55dc98f) to head (a5fe717).
Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #686   +/-   ##
=======================================
  Coverage   89.71%   89.71%           
=======================================
  Files          52       52           
  Lines        1322     1322           
=======================================
  Hits         1186     1186           
  Misses        136      136           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Member

@curquiza curquiza left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@thijskuilman

thank you for your PR ❤️

I agree with norkunas, can you add a test with an empty MultiSearchFederation to ensure it works all the time?

@curquiza curquiza added the bug Something isn't working label Oct 4, 2024
…hen you pass an empty MultiSearchFederation to the multiSearch function
…hen you pass an empty MultiSearchFederation to the multiSearch function
@thijskuilman
Copy link
Author

@norkunas @curquiza I have added a test!

@norkunas
Copy link
Collaborator

@thijskuilman not sure that we need a functional test here :) better would be to assert on that what was really passed to http client, because now a test without assertions doesn't prove anything

@norkunas
Copy link
Collaborator

norkunas commented Oct 11, 2024

IMHO we should a dev requirement for symfony/http-client, which allows easier testing than the guzzle.

Then your test could look like this:

$mockHttpClient = new \Symfony\Component\HttpClient\MockHttpClient(static function (string $method, string $url, array $options) {
    // assert on method, url, options['body'] or whatever what was passed

    return new JsonMockResponse([]);
});
$httpClient = new \Symfony\Component\HttpClient\Psr18Client($mockHttpClient);

$meilisearch = new \Meilisearch\Client('http://meilisearch', 'api_key', $httpClient);
$meilisearch->multiSearch([], new MultiSearchFederation());

code is just an idea and is not validated :)

@thijskuilman
Copy link
Author

thijskuilman commented Oct 11, 2024

better would be to assert on that what was really passed to http client, because now a test without assertions doesn't prove anything

Yeah, I agree that it seems a bit weird that no assertions are done in the test. However, the current test does prove that no exceptions are raised during the function call: if you'd revert the object casting, then the test fails because the ApiException is thrown. I could make the test more specific by wrapping it in a try catch and check specifically on ApiException if that's more desirable.

Beside that: I agree that testing the HTTP client instead might be nice (or a better solution) as well! :)

@norkunas
Copy link
Collaborator

My point was that unit test will be faster than the functional one :)

@@ -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();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is typecasting necessary? You could use $payload['federation'] = $federation; and it would work just fine.

@ruhulfbr
Copy link

@curquiza Could you please review and process this PR or provide a solution? This is an important update.

@curquiza curquiza requested a review from Strift January 15, 2025 08:44
@curquiza
Copy link
Member

Hello @ruhulfbr
we have a lot on our plate now, but @Strift will review your PR when he will have more time for this
In the meantime if you have time @norkunas, you can review and merge of course. If you cannot, no worries, we will take care of it later

@norkunas
Copy link
Collaborator

norkunas commented Jan 23, 2025

I've already reviewed and my point still stands - it'd enough for unit test (current test does not do any assertion)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Federated multi-search example does not work
4 participants