定制 subsan/codeception-module-elasticsearch 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

subsan/codeception-module-elasticsearch

Composer 安装命令:

composer require subsan/codeception-module-elasticsearch

包简介

Elasticsearch module for Codeception

README 文档

README

Connects to Elasticsearch using elasticsearch/elasticsearch official php client.

Can cleanup by delete all or listed in config indexes after each test or test suite run. Can restore snapshot from fs before each test or test suite.

Installation

Composer

composer require --dev "subsan/codeception-module-elasticsearch"

Elasticsearch config

If You need to use snapshots You need add to elasticsearch config path to snapshots

elasticsearch.yml:

path.repo: ["/PATH_TO_YOUR_PROJECT/tests/_data/elasticsearch/"]

Usage

Config

  • hosts required - elasticsearch hosts
  • snapshotPath - path to snapshot
  • snapshotName - snapshot name
  • compressedSnapshot: true - is snapshot compressed
  • populateBeforeTest: false - whether the snapshot should be loaded before the test suite is started
  • populateBeforeSuite: false - whether the snapshot should be reloaded before each test
  • cleanup: false - delete indexes from list [indexes] or all (if indexes null) after after each test or test suite finished
  • indexes: null - list of indexes to delete after after each test or test suite finished.

Example (acceptance.suite.yml)

   modules:
        - Elasticsearch:
            hosts:
              - host: 'localhost'
                port: 9200
                user: 'elastic'
                pass: ''
            snapshotPath: 'tests/_data/elasticsearch'
            snapshotName: 'snapshot_name'
            compressedSnapshot: true
            populateBeforeTest: true
            populateBeforeSuite: true
            cleanup: true
            indexes:
              - index1
              - index2

Create snapshot example:

$hosts = \Jam\Core\Core::getInstance()->config()->elasticsearch()::[YOUR_HOSTS];
$raw   = \Elasticsearch\ClientBuilder::create()->setHosts($hosts)->build();

// create repo
$repoParams = [
    'repository' => 'codeception',
    'body'       => [
        'type'     => 'fs',
        'settings' => [
            'location' => '/PATH_TO_YOUR_PROJECT/tests/_data/elasticsearch',
            'compress' => true
        ]
    ]
];
$raw->snapshot()->createRepository($repoParams);

$restoreParams = [
    'repository'          => 'codeception',
    'snapshot'            => 'snapshotName',
    'wait_for_completion' => true,
    'body'                => [
        "indices"              => "INDEX_1,INDEX_2",
        "include_global_state" => false
    ]
];
$raw->snapshot()->create($restoreParams);

Public Properties

  • elasticsearchClient - instance of Elasticsearch\Client

Actions

seeDocumentInElasticsearch

Asserts that a document with the given id exists in the index. Provide index name and document id.

$I->seeDocumentInElasticsearch('testIndex', 111);
  • param string $index
  • param string|int $id

dontSeeDocumentInElasticsearch

Effect is opposite to ->seeDocumentInElasticsearch Asserts there is no document with the given id exists in the index. Provide index name and document id.

$I->dontSeeDocumentInElasticsearch('testIndex', 222);
  • param string $index
  • param string|int $id

grabDocumentFromElasticsearch

Returns response of get document function

$response = $I->grabDocumentFromElasticsearch('testIndex', 111);
print_r($response);

The response contains some metadata (index, version, etc.) as well as a _source field, which is the original document that you sent to Elasticsearch.

Array
(
    [_index] => testIndex
    [_type] => _doc
    [_id] => 111
    [_version] => 1
    [_seq_no] => 4205
    [_primary_term] => 1
    [found] => 1
    [_source] => Array
        (
            [testField] => abc
        )
  • param string $index

  • param string|int $id

  • return array $response

haveInElasticsearch

Inserts document into an index

$item = [
    'testField' => 'abc'
];
$I->haveInElasticsearch('testIndex', 222, $item);
  • param string $index

  • param string|int $id

  • param array $body

  • return array $response

统计信息

  • 总下载量: 563
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 2
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 2
  • Watchers: 1
  • Forks: 2
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2020-10-13

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固