From 3e64e5368c44a215e00fe7aa7bd423b0e28113b5 Mon Sep 17 00:00:00 2001 From: Oleg Zhulnev Date: Sun, 24 Mar 2024 18:58:18 +0300 Subject: [PATCH] Fix tests --- tests/Aggregation/DateRangeTest.php | 2 +- tests/Cluster/SettingsTest.php | 2 +- tests/Index/SettingsTest.php | 9 +++------ tests/IndexTemplateTest.php | 7 +++---- tests/PipelineTest.php | 7 +++---- tests/Query/QueryStringTest.php | 5 ++--- tests/SearchTest.php | 3 +-- 7 files changed, 14 insertions(+), 21 deletions(-) diff --git a/tests/Aggregation/DateRangeTest.php b/tests/Aggregation/DateRangeTest.php index 9e0dea661..f395d56d5 100644 --- a/tests/Aggregation/DateRangeTest.php +++ b/tests/Aggregation/DateRangeTest.php @@ -136,7 +136,7 @@ public function testDateRangeSetFormatAccordingToFormatTargetField(): void $this->_getIndexForTest()->search($query)->getAggregation('date'); $this->fail('Should throw exception to and from parameters in date_range aggregation are interpreted according of the target field'); } catch (ClientResponseException $e) { - $error = \json_decode($e->getResponse()->getBody(), true)['error'] ?? null; + $error = \json_decode($e->getResponse()->getBody()->getContents(), true)['error'] ?? null; $this->assertSame('search_phase_execution_exception', $error['type']); $this->assertStringStartsWith('failed to parse date field', $error['root_cause'][0]['reason']); diff --git a/tests/Cluster/SettingsTest.php b/tests/Cluster/SettingsTest.php index f0ffb4ab9..1b0d94556 100644 --- a/tests/Cluster/SettingsTest.php +++ b/tests/Cluster/SettingsTest.php @@ -40,7 +40,7 @@ public function testSetReadOnly(): void $index->addDocument($doc2); $this->fail('should throw read only exception'); } catch (ClientResponseException $e) { - $error = \json_decode($e->getResponse()->getBody(), true)['error'] ?? null; + $error = \json_decode($e->getResponse()->getBody()->getContents(), true)['error'] ?? null; $this->assertSame('cluster_block_exception', $error['type']); $this->assertStringContainsString('cluster read-only', $error['reason']); diff --git a/tests/Index/SettingsTest.php b/tests/Index/SettingsTest.php index e3475d4a3..20711ad2b 100644 --- a/tests/Index/SettingsTest.php +++ b/tests/Index/SettingsTest.php @@ -138,8 +138,7 @@ public function testDeleteAliasWithException(): void $indexAlias->delete(); $this->fail('Should throw exception because you should delete the concrete index and not the alias'); } catch (ClientResponseException $e) { - $response = ResponseConverter::toElastica($e->getResponse()); - $error = $response->getFullError(); + $error = json_decode($e->getResponse()->getBody()->getContents(), true)['error'] ?? null; $this->assertSame('illegal_argument_exception', $error['type']); $this->assertStringContainsString('specify the corresponding concrete indices instead.', $error['reason']); @@ -351,8 +350,7 @@ public function testSetReadOnly(): void $index->addDocument($doc2); $this->fail('Should throw exception because of read only'); } catch (ClientResponseException $e) { - $response = ResponseConverter::toElastica($e->getResponse()); - $error = $response->getFullError(); + $error = json_decode($e->getResponse()->getBody()->getContents(), true)['error'] ?? null; $this->assertSame('cluster_block_exception', $error['type']); $this->assertStringContainsString('read-only', $error['reason']); @@ -453,8 +451,7 @@ public function testNotFoundIndex(): void $index->getSettings()->get(); $this->fail('Should throw exception because of index not found'); } catch (ClientResponseException $e) { - $response = ResponseConverter::toElastica($e->getResponse()); - $error = $response->getFullError(); + $error = json_decode($e->getResponse()->getBody()->getContents(), true)['error'] ?? null; $this->assertSame('index_not_found_exception', $error['type']); } diff --git a/tests/IndexTemplateTest.php b/tests/IndexTemplateTest.php index bd66de787..21c54560a 100644 --- a/tests/IndexTemplateTest.php +++ b/tests/IndexTemplateTest.php @@ -78,13 +78,12 @@ public function testCreateAlreadyExistsTemplateException(): void $indexTemplate->create($template); try { $indexTemplate->create($template); - } catch (ClientResponseException $ex) { - $response = ResponseConverter::toElastica($ex->getResponse()); - $error = $response->getFullError(); + } catch (ClientResponseException $e) { + $error = json_decode($e->getResponse()->getBody()->getContents(), true)['error'] ?? null; $this->assertNotEquals('index_template_already_exists_exception', $error['type']); $this->assertEquals('resource_already_exists_exception', $error['type']); - $this->assertEquals(400, $ex->getResponse()->getStatusCode()); + $this->assertEquals(400, $e->getResponse()->getStatusCode()); } } } diff --git a/tests/PipelineTest.php b/tests/PipelineTest.php index c9ec96a9f..bbb515c4d 100644 --- a/tests/PipelineTest.php +++ b/tests/PipelineTest.php @@ -135,11 +135,10 @@ public function testDeletePipeline(): void $pipeline->deletePipeline('non_existent_pipeline'); $this->fail('an exception should be raised!'); } catch (ClientResponseException $e) { - $response = ResponseConverter::toElastica($e->getResponse()); - $result = $response->getFullError(); + $error = json_decode($e->getResponse()->getBody()->getContents(), true)['error'] ?? null; - $this->assertEquals('resource_not_found_exception', $result['type']); - $this->assertEquals('pipeline [non_existent_pipeline] is missing', $result['reason']); + $this->assertEquals('resource_not_found_exception', $error['type']); + $this->assertEquals('pipeline [non_existent_pipeline] is missing', $error['reason']); } } } diff --git a/tests/Query/QueryStringTest.php b/tests/Query/QueryStringTest.php index 9324f0a3f..0949c97aa 100644 --- a/tests/Query/QueryStringTest.php +++ b/tests/Query/QueryStringTest.php @@ -107,14 +107,13 @@ public function testSearchFieldsValidationException(): void try { $index->search($query); } catch (ClientResponseException $e) { - $response = ResponseConverter::toElastica($e->getResponse()); - $error = $response->getFullError(); + $error = json_decode($e->getResponse()->getBody()->getContents(), true)['error'] ?? null; $this->assertSame('query_shard_exception', $error['root_cause'][0]['type']); $this->assertStringContainsString('failed to create query', $error['root_cause'][0]['reason']); $this->assertStringContainsString('[fields] parameter in conjunction with [default_field]', $error['failed_shards'][0]['reason']['caused_by']['reason']); - $this->assertEquals(400, $response->getStatus()); + $this->assertEquals(400, $e->getResponse()->getStatusCode()); } } diff --git a/tests/SearchTest.php b/tests/SearchTest.php index e21147ff0..7842ceff0 100644 --- a/tests/SearchTest.php +++ b/tests/SearchTest.php @@ -688,8 +688,7 @@ public function testIgnoreUnavailableOption(): void $search->search($query); $this->fail('Should raise an Index not found exception'); } catch (ClientResponseException $e) { - $response = ResponseConverter::toElastica($e->getResponse()); - $error = $response->getFullError(); + $error = json_decode($e->getResponse()->getBody()->getContents(), true)['error'] ?? null; $this->assertEquals('index_not_found_exception', $error['type']); $this->assertEquals('no such index [elastica_7086b4c2ee585bbb6740ece5ed7ece01]', $error['reason']);