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

Adds method to unset last response in Client #221

Merged
merged 18 commits into from
Nov 5, 2024
8 changes: 8 additions & 0 deletions src/Manticoresearch/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -421,4 +421,12 @@ public function request(Request $request, array $params = []): Response {
public function getLastResponse(): Response {
return $this->lastResponse;
}

/*
*
* @return void
*/
public function unsetLastResponse(): void {
$this->lastResponse = new Response([], null, []);
}
}
23 changes: 23 additions & 0 deletions test/Manticoresearch/ClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -167,4 +167,27 @@ public function testGetLastResponse() {
$lastResponse = $client->getLastResponse()->getResponse();
$this->assertEquals($result, $lastResponse);
}
public function testUnsetLastResponse() {
$helper = new PopulateHelperTest();
$helper->populateForKeywords();
$client = $helper->getClient();

$payload = [
'body' => [
'index' => 'products',
'query' => [
'match' => ['*' => 'broken'],
],
],
];

$result = $client->search($payload);
$lastResponse = $client->getLastResponse()->getResponse();
$this->assertEquals($result, $lastResponse);

$client->unsetLastResponse();

$lastResponse = $client->getLastResponse()->getResponse();
$this->assertEquals([], $lastResponse);
}
}
3 changes: 2 additions & 1 deletion test/Manticoresearch/Endpoints/InsertTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,12 @@ public function testInsert() {
],
];
$response = $client->insert(['body' => $doc]);
unset($response['_index']);
unset($response['table']);

// assert inserted
$this->assertEquals(
[
'_index' => 'products',
'_id' => 1001,
'created' => true,
'result' => 'created',
Expand Down
Loading