imdhemy/es-testing-utils 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

imdhemy/es-testing-utils

最新稳定版本:8.3.0

Composer 安装命令:

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

包简介

Elasticsearch Testing utils

README 文档

README

Tests Latest Stable Version Total Downloads

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

You can use composer

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

Versions

Elasticsearch Es testing Utils
7.x 7.x
8.x 8.x

Usage

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

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

License

The ES testing utils is open-sourced software licensed under the MIT license

统计信息

  • 总下载量: 44.67k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 11
  • 点击次数: 1
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 11
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2021-09-24