Definition at line 11 of file ElasticsearchTest.php.
◆ getEmptyIndexOption()
- Returns
- array
Definition at line 550 of file ElasticsearchTest.php.
553 'hostname' =>
'localhost',
558 'username' =>
'user',
559 'password' =>
'passwd',
◆ getOptions()
Get elasticsearch client options
- Returns
- array
Definition at line 534 of file ElasticsearchTest.php.
537 'hostname' =>
'localhost',
540 'index' =>
'magento2',
542 'username' =>
'user',
543 'password' =>
'passwd',
◆ setUp()
Setup
- Returns
- void
Definition at line 38 of file ElasticsearchTest.php.
40 $this->elasticsearchClientMock = $this->getMockBuilder(\Elasticsearch\Client::class)
50 ->disableOriginalConstructor()
52 $this->indicesMock = $this->getMockBuilder(\Elasticsearch\Namespaces\IndicesNamespace::class)
65 ->disableOriginalConstructor()
67 $this->elasticsearchClientMock->expects($this->any())
69 ->willReturn($this->indicesMock);
70 $this->elasticsearchClientMock->expects($this->any())
73 $this->elasticsearchClientMock->expects($this->any())
75 ->willReturn([
'version' => [
'number' =>
'5.0.0']]);
77 $this->objectManager =
new ObjectManagerHelper($this);
78 $this->model = $this->objectManager->getObject(
79 \
Magento\Elasticsearch\Elasticsearch5\Model\Client\Elasticsearch::class,
82 'elasticsearchClient' => $this->elasticsearchClientMock
◆ testAddFieldsMapping()
Test testAddFieldsMapping() method
Definition at line 335 of file ElasticsearchTest.php.
337 $this->indicesMock->expects($this->once())
338 ->method(
'putMapping')
340 'index' =>
'indexName',
353 'dynamic_templates' => [
356 'match' =>
'price_*',
357 'match_mapping_type' =>
'string',
365 'string_mapping' => [
367 'match_mapping_type' =>
'string',
375 'position_mapping' => [
376 'match' =>
'position_*',
377 'match_mapping_type' =>
'string',
387 $this->model->addFieldsMapping(
◆ testAddFieldsMappingFailure()
testAddFieldsMappingFailure |
( |
| ) |
|
Test testAddFieldsMapping() method @expectedException \Exception
Definition at line 402 of file ElasticsearchTest.php.
404 $this->indicesMock->expects($this->once())
405 ->method(
'putMapping')
407 'index' =>
'indexName',
420 'dynamic_templates' => [
423 'match' =>
'price_*',
424 'match_mapping_type' =>
'string',
432 'string_mapping' => [
434 'match_mapping_type' =>
'string',
442 'position_mapping' => [
443 'match' =>
'position_*',
444 'match_mapping_type' =>
'string',
454 ->willThrowException(
new \Exception(
'Something went wrong'));
455 $this->model->addFieldsMapping(
◆ testBulkQuery()
Test bulkQuery() method
Definition at line 162 of file ElasticsearchTest.php.
164 $this->elasticsearchClientMock->expects($this->once())
167 $this->model->bulkQuery([]);
◆ testConstructorOptionsException()
testConstructorOptionsException |
( |
| ) |
|
@expectedException \Magento\Framework\Exception\LocalizedException
Definition at line 90 of file ElasticsearchTest.php.
92 $result = $this->objectManager->getObject(
93 \
Magento\Elasticsearch\Model\Client\Elasticsearch::class,
◆ testConstructorWithOptions()
testConstructorWithOptions |
( |
| ) |
|
◆ testCreateIndexExists()
testCreateIndexExists |
( |
| ) |
|
Test createIndex() method, case when such index exists
Definition at line 173 of file ElasticsearchTest.php.
175 $this->indicesMock->expects($this->once())
178 'index' =>
'indexName',
181 $this->model->createIndex(
'indexName', []);
◆ testCreateIndexFailure()
testCreateIndexFailure |
( |
| ) |
|
Test createIndexIfNotExists() method, case when operation fails @expectedException \Exception
Definition at line 320 of file ElasticsearchTest.php.
322 $this->indicesMock->expects($this->once())
325 'index' =>
'indexName',
328 ->willThrowException(
new \Exception(
'Something went wrong'));
329 $this->model->createIndex(
'indexName', []);
◆ testDeleteIndex()
Test deleteIndex() method.
Definition at line 187 of file ElasticsearchTest.php.
189 $this->indicesMock->expects($this->once())
191 ->with([
'index' =>
'indexName']);
192 $this->model->deleteIndex(
'indexName');
◆ testDeleteMapping()
Test deleteMapping() method
Definition at line 469 of file ElasticsearchTest.php.
471 $this->indicesMock->expects($this->once())
472 ->method(
'deleteMapping')
474 'index' =>
'indexName',
477 $this->model->deleteMapping(
◆ testDeleteMappingFailure()
testDeleteMappingFailure |
( |
| ) |
|
Test deleteMapping() method @expectedException \Exception
Definition at line 487 of file ElasticsearchTest.php.
489 $this->indicesMock->expects($this->once())
490 ->method(
'deleteMapping')
492 'index' =>
'indexName',
495 ->willThrowException(
new \Exception(
'Something went wrong'));
496 $this->model->deleteMapping(
◆ testExistsAlias()
Tests existsAlias() method checking for alias.
Definition at line 276 of file ElasticsearchTest.php.
280 $this->indicesMock->expects($this->once())
281 ->method(
'existsAlias')
284 $this->assertTrue($this->model->existsAlias(
$alias));
$params[\Magento\Store\Model\StoreManager::PARAM_RUN_CODE]
◆ testExistsAliasWithIndex()
testExistsAliasWithIndex |
( |
| ) |
|
Tests existsAlias() method checking for alias and index.
Definition at line 290 of file ElasticsearchTest.php.
295 $this->indicesMock->expects($this->once())
296 ->method(
'existsAlias')
299 $this->assertTrue($this->model->existsAlias(
$alias,
$index));
$params[\Magento\Store\Model\StoreManager::PARAM_RUN_CODE]
◆ testGetAlias()
Test getAlias() method.
Definition at line 305 of file ElasticsearchTest.php.
309 $this->indicesMock->expects($this->once())
313 $this->assertEquals([], $this->model->getAlias(
$alias));
$params[\Magento\Store\Model\StoreManager::PARAM_RUN_CODE]
◆ testIndexExists()
Test indexExists() method, case when no such index exists
Definition at line 262 of file ElasticsearchTest.php.
264 $this->indicesMock->expects($this->once())
267 'index' =>
'indexName',
270 $this->model->indexExists(
'indexName');
◆ testIsEmptyIndex()
Test isEmptyIndex() method.
Definition at line 198 of file ElasticsearchTest.php.
200 $indexName =
'magento2_index';
201 $stats[
'indices'][$indexName][
'primaries'][
'docs'][
'count'] = 0;
203 $this->indicesMock->expects($this->once())
205 ->with([
'index' => $indexName,
'metric' =>
'docs'])
206 ->willReturn($stats);
207 $this->assertTrue($this->model->isEmptyIndex($indexName));
◆ testIsEmptyIndexFalse()
testIsEmptyIndexFalse |
( |
| ) |
|
Test isEmptyIndex() method returns false.
Definition at line 213 of file ElasticsearchTest.php.
215 $indexName =
'magento2_index';
216 $stats[
'indices'][$indexName][
'primaries'][
'docs'][
'count'] = 1;
218 $this->indicesMock->expects($this->once())
220 ->with([
'index' => $indexName,
'metric' =>
'docs'])
221 ->willReturn($stats);
222 $this->assertFalse($this->model->isEmptyIndex($indexName));
◆ testPing()
Test ping functionality
Definition at line 118 of file ElasticsearchTest.php.
120 $this->elasticsearchClientMock->expects($this->once())->method(
'ping')->willReturn(
true);
121 $this->assertEquals(
true, $this->model->ping());
◆ testQuery()
Test query() method
- Returns
- void
Definition at line 506 of file ElasticsearchTest.php.
508 $query =
'test phrase query';
509 $this->elasticsearchClientMock->expects($this->once())
513 $this->assertEquals([], $this->model->query(
$query));
◆ testSuggest()
Test suggest() method
- Returns
- void
Definition at line 520 of file ElasticsearchTest.php.
523 $this->elasticsearchClientMock->expects($this->once())
526 $this->assertEquals([], $this->model->suggest(
$query));
◆ testTestConnection()
Test validation of connection parameters
Definition at line 127 of file ElasticsearchTest.php.
129 $this->elasticsearchClientMock->expects($this->once())->method(
'ping')->willReturn(
true);
130 $this->assertEquals(
true, $this->model->testConnection());
◆ testTestConnectionFalse()
testTestConnectionFalse |
( |
| ) |
|
Test validation of connection parameters returns false
Definition at line 136 of file ElasticsearchTest.php.
138 $this->elasticsearchClientMock->expects($this->once())->method(
'ping')->willReturn(
false);
139 $this->assertEquals(
true, $this->model->testConnection());
◆ testTestConnectionPing()
testTestConnectionPing |
( |
| ) |
|
Test validation of connection parameters
Definition at line 145 of file ElasticsearchTest.php.
147 $this->model = $this->objectManager->getObject(
148 \
Magento\Elasticsearch\Model\Client\Elasticsearch::class,
151 'elasticsearchClient' => $this->elasticsearchClientMock
155 $this->model->ping();
156 $this->assertEquals(
true, $this->model->testConnection());
◆ testUpdateAlias()
Test updateAlias() method with new index.
Definition at line 228 of file ElasticsearchTest.php.
235 $this->indicesMock->expects($this->once())
236 ->method(
'updateAliases')
$params[\Magento\Store\Model\StoreManager::PARAM_RUN_CODE]
◆ testUpdateAliasRemoveOldIndex()
testUpdateAliasRemoveOldIndex |
( |
| ) |
|
Test updateAlias() method with new and old index.
Definition at line 244 of file ElasticsearchTest.php.
247 $newIndex =
'index1';
248 $oldIndex =
'indexOld';
250 $params[
'body'][
'actions'][] = [
'remove' => [
'alias' =>
$alias,
'index' => $oldIndex]];
251 $params[
'body'][
'actions'][] = [
'add' => [
'alias' =>
$alias,
'index' => $newIndex]];
253 $this->indicesMock->expects($this->once())
254 ->method(
'updateAliases')
256 $this->model->updateAlias(
$alias, $newIndex, $oldIndex);
$params[\Magento\Store\Model\StoreManager::PARAM_RUN_CODE]
◆ $elasticsearchClientMock
◆ $indicesMock
◆ $model
◆ $objectManager
The documentation for this class was generated from the following file: