PHP code example of subsan / codeception-module-elasticsearch
1. Go to this page and download the library: Download subsan/codeception-module-elasticsearch library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
subsan / codeception-module-elasticsearch example snippets
$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",
"
$I->seeDocumentInElasticsearch('testIndex', 111);
$I->dontSeeDocumentInElasticsearch('testIndex', 222);
$response = $I->grabDocumentFromElasticsearch('testIndex', 111);
print_r($response);
Array
(
[_index] => testIndex
[_type] => _doc
[_id] => 111
[_version] => 1
[_seq_no] => 4205
[_primary_term] => 1
[found] => 1
[_source] => Array
(
[testField] => abc
)
$item = [
'testField' => 'abc'
];
$I->haveInElasticsearch('testIndex', 222, $item);