PHPackages                             imdhemy/es-testing-utils - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Testing &amp; Quality](/categories/testing)
4. /
5. imdhemy/es-testing-utils

ActiveLibrary[Testing &amp; Quality](/categories/testing)

imdhemy/es-testing-utils
========================

Elasticsearch Testing utils

8.3.0(3y ago)1149.8k—2.4%MITPHPPHP &gt;=7.4

Since Sep 24Pushed 3y ago1 watchersCompare

[ Source](https://github.com/imdhemy/es-testing-utils)[ Packagist](https://packagist.org/packages/imdhemy/es-testing-utils)[ Docs](https://github.com/imdhemy/es-testing-utils)[ RSS](/packages/imdhemy-es-testing-utils/feed)WikiDiscussions 8.x Synced 1mo ago

READMEChangelog (6)Dependencies (5)Versions (8)Used By (0)

Elastic search testing utils
============================

[](#elastic-search-testing-utils)

[![Tests](https://github.com/imdhemy/es-testing-utils/actions/workflows/tests.yml/badge.svg)](https://github.com/imdhemy/es-testing-utils/actions/workflows/tests.yml) [![Latest Stable Version](https://camo.githubusercontent.com/c90770651253f62634db0fcaea23736280eed683d76a88e0337e4193fa4cc519/68747470733a2f2f706f7365722e707567782e6f72672f696d6468656d792f65732d74657374696e672d7574696c732f762f737461626c65)](https://packagist.org/packages/imdhemy/es-testing-utils) [![Total Downloads](https://camo.githubusercontent.com/8c944b84d2a722c92802d7b3bd10d40809a500ce1c13fe983ea38812eccafa55/68747470733a2f2f706f7365722e707567782e6f72672f696d6468656d792f65732d74657374696e672d7574696c732f646f776e6c6f616473)](https://packagist.org/packages/imdhemy/es-testing-utils)

Unit tests shouldn't depend on a running cluster, should be mocked out instead. To be more specific, the client responses should be mocked out. Elastic search testing utils makes it super easy for you to mock Elasticsearch responses.

Installation
------------

[](#installation)

You can use composer

```
composer require --dev imdhemy/es-testing-utils

```

Versions
--------

[](#versions)

ElasticsearchEs testing Utils7.x[7.x](https://github.com/imdhemy/es-testing-utils/tree/7.x)8.x[8.x](https://github.com/imdhemy/es-testing-utils/tree/8.x)Usage
-----

[](#usage)

### Mocker

[](#mocker)

Es testing utils provides you a fluent Elasticsearch mock builder, you can use it as follows:

```
use Imdhemy\EsUtils\EsMocker;

// Create ES client that returns the mock response
$client = EsMocker::mock(['tagline' => 'You know, for search.'])->build();
```

Or you can mock a sequence of responses:

```
use Imdhemy\EsUtils\EsMocker;

// The created client will return the `$info` response with the first request,
// and the `$search` response with the second request, and so on.
// Note: the `thenFail()` method mocks a request exception.
$client = EsMocker::mock($info)->then($index)->then($search)->thenFail($error)->build();

// Or you can directly fail the first request:
$client = EsMocker::fail($message)->build();
```

Below is a complete example of how to use EsMocker in a test:

```
use Imdhemy\EsUtils\EsMocker;

$expected=['tagline' => 'You know, for search.'];
$client = EsMocker::mock($expected)->build();

$response = $client->info();
$body = (string) $response->getBody();

$this->assertEquals(json_encode($expected), $body);
```

### Faker

[](#faker)

The faker class provides you a set of methods to generate random data for your tests. It provides all the methods of the Faker library along with new methods to generate Elasticsearch data. All the methods related to Elasticsearch starts with `es` prefix.

```
use Imdhemy\EsUtils\Faker;

$faker = Faker::create();

$index = $faker->esIndexName(); // Returns a random index name
$createIndex = $faker->esCreateIndex(); // Returns create index response body

// Explore the Faker class to see all the available methods
```

Credits
-------

[](#credits)

- [Mohamad Eldhemy](https://imdhemy.com)
- [All Contributors](https://github.com/imdhemy/es-testing-utils/graphs/contributors)

License
-------

[](#license)

The ES testing utils is open-sourced software licensed under the [MIT license](/LICENSE)

###  Health Score

33

—

LowBetter than 75% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity36

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity55

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~54 days

Recently: every ~11 days

Total

8

Last Release

1319d ago

Major Versions

7.0.0 → 8.0.02022-08-19

7.x-dev → 8.0.12022-08-23

PHP version history (2 changes)7.0.0PHP &gt;=7.3

8.0.0PHP &gt;=7.4

### Community

Maintainers

![](https://www.gravatar.com/avatar/22a24571a8060dbc3e646a409d2274086f755e57dc0aa3eba2ba37d51b6fd84b?d=identicon)[imdhemy](/maintainers/imdhemy)

---

Top Contributors

[![imdhemy](https://avatars.githubusercontent.com/u/22864831?v=4)](https://github.com/imdhemy "imdhemy (112 commits)")

---

Tags

elasticsearchmockingphpunittestingphptestingmockingelasticsearch

###  Code Quality

TestsPHPUnit

Static AnalysisPsalm

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/imdhemy-es-testing-utils/health.svg)

```
[![Health](https://phpackages.com/badges/imdhemy-es-testing-utils/health.svg)](https://phpackages.com/packages/imdhemy-es-testing-utils)
```

###  Alternatives

[orchestra/workbench

Workbench Companion for Laravel Packages Development

8217.0M43](/packages/orchestra-workbench)[quizlet/hammock

Hammock is a stand-alone mocking library for Hacklang.

27445.5k](/packages/quizlet-hammock)[janmarek/mockista

Mockista is library for mocking, which I've written, because I find mocking in PHPUnit awful.

29221.0k28](/packages/janmarek-mockista)[doppiogancio/mocked-client

A simple way to mock a client

2174.9k3](/packages/doppiogancio-mocked-client)[robiningelbrecht/phpunit-coverage-tools

PHPUnit coverage tools

1783.0k34](/packages/robiningelbrecht-phpunit-coverage-tools)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
