Skip to content

Commit

Permalink
Adds method to unset last response in Client (#221)
Browse files Browse the repository at this point in the history
* Fixes search by multiple attributes

* upd

* upd

* upd

* fix

* fix

* fix

* Adds method to unset last response in Client

* getLastResponse(): ?Response

* test fix

* test fix

* test fix

* test fix

* manticoresearch/manticore:5.0.2

* manticoresearch/manticore:dev

---------

Co-authored-by: Анастасия Скульская <[email protected]>
  • Loading branch information
acya-skulskaya and Анастасия Скульская authored Nov 5, 2024
1 parent 02950b0 commit ed28112
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 1 deletion.
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

0 comments on commit ed28112

Please sign in to comment.