Skip to content

Commit 81513ce

Browse files
committed
Refresh index after load fixtures.
1 parent dd4f30a commit 81513ce

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

tests/Data/IndexSeeder.php

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -81,25 +81,32 @@ protected function loadFixtures(): void
8181
{
8282
$baseDir = __DIR__.'/fixtures/';
8383

84-
foreach ($this->fixtures as $fixture) {
85-
$this->loadFixture($baseDir.$fixture);
84+
$hasChanges = collect($this->fixtures)
85+
->reduce(
86+
fn (bool $carry, string $fixture) => $this->loadFixture($baseDir.$fixture) || $carry,
87+
false
88+
);
89+
90+
if ($hasChanges) {
91+
$this->client->indices()->refresh(['index' => $this->indexName]);
8692
}
87-
88-
sleep(1);
8993
}
9094

91-
protected function loadFixture(string $path): void
95+
protected function loadFixture(string $path): bool
9296
{
9397
$documents = json_decode(file_get_contents($path), true);
98+
9499
if (empty($documents)) {
95-
return;
100+
return false;
96101
}
97102

98103
$body = collect($documents)
99104
->flatMap(fn (array $document, int $index) => $this->documentToCommand($document, $index))
100105
->toArray();
101106

102107
$this->client->bulk(['body' => $body]);
108+
109+
return true;
103110
}
104111

105112
protected function documentToCommand(array $document, int $id): array

0 commit comments

Comments
 (0)