Skip to content

Commit

Permalink
Fix building error message in ElasticsearchFileFixture (#40)
Browse files Browse the repository at this point in the history
* Fix building error message in ElasticsearchFileFixture

* Remove unused constants
  • Loading branch information
hugo-goncalves-kununu authored Mar 1, 2024
1 parent b724bdd commit 236ec0e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 37 deletions.
16 changes: 2 additions & 14 deletions src/Adapter/ElasticsearchFileFixture.php
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand All @@ -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);
Expand Down
29 changes: 6 additions & 23 deletions tests/Adapter/ElasticsearchJsonDirectoryFixtureTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 236ec0e

Please sign in to comment.