Skip to content

Commit e6cf5ec

Browse files
committed
Refresh index after load fixtures.
1 parent 9a9f8ee commit e6cf5ec

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

tests/Seeds/IndexSeeder.php

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

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

90-
protected function loadFixture(string $path): void
94+
protected function loadFixture(string $path): bool
9195
{
9296
$documents = json_decode(file_get_contents($path), true);
97+
9398
if (empty($documents)) {
94-
return;
99+
return false;
95100
}
96101

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

101106
$this->client->bulk(['body' => $body]);
107+
108+
return true;
102109
}
103110

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

0 commit comments

Comments
 (0)