From ed2811293813bb0a55b1498c0100decee73f5b45 Mon Sep 17 00:00:00 2001 From: Acya Skulskaya <426505+acya-skulskaya@users.noreply.github.com> Date: Tue, 5 Nov 2024 17:25:00 +0300 Subject: [PATCH] Adds method to unset last response in Client (#221) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 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: Анастасия Скульская --- src/Manticoresearch/Client.php | 8 +++++++ test/Manticoresearch/ClientTest.php | 23 +++++++++++++++++++ test/Manticoresearch/Endpoints/InsertTest.php | 3 ++- 3 files changed, 33 insertions(+), 1 deletion(-) diff --git a/src/Manticoresearch/Client.php b/src/Manticoresearch/Client.php index 7a9c2499..1e7952e4 100755 --- a/src/Manticoresearch/Client.php +++ b/src/Manticoresearch/Client.php @@ -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, []); + } } diff --git a/test/Manticoresearch/ClientTest.php b/test/Manticoresearch/ClientTest.php index 3b6871ec..cb9b231b 100644 --- a/test/Manticoresearch/ClientTest.php +++ b/test/Manticoresearch/ClientTest.php @@ -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); + } } diff --git a/test/Manticoresearch/Endpoints/InsertTest.php b/test/Manticoresearch/Endpoints/InsertTest.php index 887a2676..20c1785c 100644 --- a/test/Manticoresearch/Endpoints/InsertTest.php +++ b/test/Manticoresearch/Endpoints/InsertTest.php @@ -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',