trait InteractsWithMeilisearch

Add Meilisearch support to an integration test.

Use this trait on a test case and set MEILISEARCH_HOST. MEILISEARCH_PORT and MEILISEARCH_KEY may also be configured. Test indexes are isolated and cleaned up using a TEST_TOKEN-based prefix.

Properties

protected string $meilisearchTestPrefix

The test prefix for index isolation.

protected Client|null $meilisearch

The Meilisearch client instance.

Methods

void
setUpInteractsWithMeilisearch()

Set up Meilisearch for testing (auto-called by setUpTraits).

void
tearDownInteractsWithMeilisearch()

Tear down Meilisearch (auto-called via beforeApplicationDestroyed).

void
initializeMeilisearchClient()

Initialize the Meilisearch client.

void
computeMeilisearchTestPrefix()

Compute the test prefix for parallel-safe index names.

string
getMeilisearchHost()

Get the Meilisearch host URL.

void
cleanupMeilisearchIndexes()

Clean up all test indexes matching the test prefix.

void
waitForMeilisearchTasks(int $timeoutMs = 5000)

Wait for all pending Meilisearch tasks to complete.

void
waitForMeilisearchTask(int $taskUid, int $timeoutMs = 5000)

Wait for a Meilisearch task to complete successfully.

Details

at line 36
protected void setUpInteractsWithMeilisearch()

Set up Meilisearch for testing (auto-called by setUpTraits).

Meilisearch integration tests are opt-in via MEILISEARCH_HOST. Port and key settings are only read after MEILISEARCH_HOST is present.

Return Value

void

at line 58
protected void tearDownInteractsWithMeilisearch()

Tear down Meilisearch (auto-called via beforeApplicationDestroyed).

Return Value

void

at line 76
protected void initializeMeilisearchClient()

Initialize the Meilisearch client.

Return Value

void

at line 87
protected void computeMeilisearchTestPrefix()

Compute the test prefix for parallel-safe index names.

Return Value

void

at line 100
protected string getMeilisearchHost()

Get the Meilisearch host URL.

Builds URL from MEILISEARCH_HOST and MEILISEARCH_PORT env vars.

Return Value

string

at line 111
protected void cleanupMeilisearchIndexes()

Clean up all test indexes matching the test prefix.

Return Value

void

at line 138
protected void waitForMeilisearchTasks(int $timeoutMs = 5000)

Wait for all pending Meilisearch tasks to complete.

Parameters

int $timeoutMs

Return Value

void

at line 163
protected void waitForMeilisearchTask(int $taskUid, int $timeoutMs = 5000)

Wait for a Meilisearch task to complete successfully.

Parameters

int $taskUid
int $timeoutMs

Return Value

void