From 236ec0e5493e89615cc5d0855bf514e9e50542a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hugo=20Gon=C3=A7alves?= Date: Fri, 1 Mar 2024 17:11:49 +0000 Subject: [PATCH] Fix building error message in ElasticsearchFileFixture (#40) * Fix building error message in ElasticsearchFileFixture * Remove unused constants --- src/Adapter/ElasticsearchFileFixture.php | 16 ++-------- .../ElasticsearchJsonDirectoryFixtureTest.php | 29 ++++--------------- 2 files changed, 8 insertions(+), 37 deletions(-) diff --git a/src/Adapter/ElasticsearchFileFixture.php b/src/Adapter/ElasticsearchFileFixture.php index 6d44265..4514c8d 100644 --- a/src/Adapter/ElasticsearchFileFixture.php +++ b/src/Adapter/ElasticsearchFileFixture.php @@ -11,10 +11,6 @@ abstract class ElasticsearchFileFixture extends AbstractFileLoaderFixture implem { use ElasticsearchFixtureTrait; - private const INDEX = 'index'; - private const UPDATE = 'update'; - private const ERROR = 'error'; - public function load(Client $elasticSearch, string $indexName, bool $throwOnFail = true): void { parent::loadFiles(fn(array $documents) => $this->bulk($elasticSearch, $indexName, $documents, $throwOnFail)); @@ -35,16 +31,8 @@ private function bulk(Client $elasticSearch, string $indexName, array $documents if ($throwOnFail && ($result['errors'] ?? false)) { $errors = array_map( - fn(array $item): stdClass => (object) [ - self::INDEX => $item[self::UPDATE]['_index'], - 'id' => $item[self::UPDATE]['_id'], - 'status' => $item[self::UPDATE]['status'], - self::ERROR => $item[self::UPDATE][self::ERROR], - ], - array_filter( - $result['items'] ?? [], - fn(array $item): bool => isset($item[self::UPDATE][self::ERROR]) - ) + fn(array $item): stdClass => (object) $item, + array_filter($result['items'] ?? []) ); throw new LoadFailedException(static::class, $errors); diff --git a/tests/Adapter/ElasticsearchJsonDirectoryFixtureTest.php b/tests/Adapter/ElasticsearchJsonDirectoryFixtureTest.php index dda4adb..6d73e06 100644 --- a/tests/Adapter/ElasticsearchJsonDirectoryFixtureTest.php +++ b/tests/Adapter/ElasticsearchJsonDirectoryFixtureTest.php @@ -120,25 +120,6 @@ public function testLoadWithErrors(): void ], ], ]; - $bulk2 = [ - 'body' => [ - [ - 'index' => [ - '_index' => 'my_index', - '_id' => 'd1cd10a0-7023-434c-8cd3-0196e1d34c2f', - ], - ], - [ - 'uuid' => 'd1cd10a0-7023-434c-8cd3-0196e1d34c2f', - 'name' => 'Document 3', - 'attributes' => [ - 'attrib_1' => 3, - 'attrib_2' => 'inactive', - 'attrib_3' => false, - ], - ], - ], - ]; $this->client ->expects($this->once()) @@ -168,10 +149,12 @@ public function testLoadWithErrors(): void Errors: [ { - "index": "my_index", - "id": "17e05f79-2c6e-4a71-bacf-afc8fd8e5f73", - "status": "some status", - "error": "some error" + "update": { + "error": "some error", + "_index": "my_index", + "_id": "17e05f79-2c6e-4a71-bacf-afc8fd8e5f73", + "status": "some status" + } } ] TEXT