-
Notifications
You must be signed in to change notification settings - Fork 103
Cast federation payload explicilty to an object #686
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
base: main
Are you sure you want to change the base?
Changes from all commits
0f3a300
d666c0b
a5fe717
4d6c355
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,35 @@ | ||||||||||||||||||||
<?php | ||||||||||||||||||||
|
||||||||||||||||||||
declare(strict_types=1); | ||||||||||||||||||||
|
||||||||||||||||||||
namespace Endpoints; | ||||||||||||||||||||
|
||||||||||||||||||||
use Meilisearch\Contracts\MultiSearchFederation; | ||||||||||||||||||||
use Meilisearch\Contracts\SearchQuery; | ||||||||||||||||||||
use Meilisearch\Endpoints\Indexes; | ||||||||||||||||||||
use Tests\TestCase; | ||||||||||||||||||||
|
||||||||||||||||||||
final class HandlesMultiSearchTest extends TestCase | ||||||||||||||||||||
{ | ||||||||||||||||||||
private Indexes $firstIndex; | ||||||||||||||||||||
private Indexes $secondIndex; | ||||||||||||||||||||
|
||||||||||||||||||||
protected function setUp(): void | ||||||||||||||||||||
{ | ||||||||||||||||||||
parent::setUp(); | ||||||||||||||||||||
$this->firstIndex = $this->createEmptyIndex($this->safeIndexName()); | ||||||||||||||||||||
$this->secondIndex = $this->createEmptyIndex($this->safeIndexName()); | ||||||||||||||||||||
} | ||||||||||||||||||||
|
||||||||||||||||||||
public function testPassingEmptyMultiSearchFederationDoesNotCauseException(): void | ||||||||||||||||||||
{ | ||||||||||||||||||||
$this->expectNotToPerformAssertions(); | ||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Remove expectNotToPerformAssertions() and add meaningful assertions. The At minimum, consider adding an assertion that verifies the method completes successfully: - $this->expectNotToPerformAssertions();
-
- $this->client->multiSearch([
+ $result = $this->client->multiSearch([
(new SearchQuery())->setIndexUid($this->firstIndex->getUid()),
(new SearchQuery())->setIndexUid($this->secondIndex->getUid()),
],
new MultiSearchFederation()
);
+
+ $this->assertIsArray($result); 📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents
|
||||||||||||||||||||
|
||||||||||||||||||||
$this->client->multiSearch([ | ||||||||||||||||||||
(new SearchQuery())->setIndexUid($this->firstIndex->getUid()), | ||||||||||||||||||||
(new SearchQuery())->setIndexUid($this->secondIndex->getUid()), | ||||||||||||||||||||
], | ||||||||||||||||||||
new MultiSearchFederation() | ||||||||||||||||||||
); | ||||||||||||||||||||
} | ||||||||||||||||||||
Comment on lines
+24
to
+34
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Consider implementing unit tests with HTTP client assertions. While this test ensures no exceptions are thrown, it lacks assertions on the actual behavior and uses a functional testing approach. As discussed in the PR comments, a more robust approach would be to unit test the HTTP client interactions directly. Consider implementing the suggestion from the PR comments to mock the HTTP client and assert on the request payload: public function testEmptyFederationPayloadIsCastToObject(): void
{
$httpClient = $this->createMock(Http::class);
$httpClient->expects($this->once())
->method('post')
->with(
'/multi-search',
$this->callback(function ($payload) {
// Verify federation is an object (stdClass) not an array
return isset($payload['federation'])
&& $payload['federation'] instanceof \stdClass;
})
);
$client = new Client('http://localhost:7700');
// Inject mocked HTTP client...
$client->multiSearch(
[(new SearchQuery())->setIndexUid('test')],
new MultiSearchFederation()
);
} This approach would:
Would you like me to help implement a more comprehensive unit testing approach for this functionality? 🤖 Prompt for AI Agents
|
||||||||||||||||||||
} |
There was a problem hiding this comment.
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.