Skip to content

Commit 9b717a2

Browse files
author
Christopher Lorke
committed
Refactoring: tests
1 parent 0744db2 commit 9b717a2

File tree

2 files changed

+162
-297
lines changed

2 files changed

+162
-297
lines changed

tests/helpers/CreateMigrationStep.php

Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
<?php
2+
namespace Tests\Helpers;
3+
4+
use Triadev\EsMigration\Business\Mapper\MigrationTypes;
5+
use Triadev\EsMigration\Contract\ElasticsearchMigrationContract;
6+
7+
class CreateMigrationStep extends \PHPUnit\Framework\TestCase
8+
{
9+
/** @var ElasticsearchMigrationContract */
10+
private $migrationService;
11+
12+
/**
13+
* CreateMigrationStep constructor.
14+
* @param null|string $name
15+
* @param array $data
16+
* @param string $dataName
17+
*/
18+
public function __construct(?string $name = null, array $data = [], string $dataName = '')
19+
{
20+
parent::__construct($name, $data, $dataName);
21+
22+
$this->migrationService = app(ElasticsearchMigrationContract::class);
23+
}
24+
25+
public function createIndex(int $priority = 1)
26+
{
27+
$this->assertTrue($this->migrationService->addMigrationStep(
28+
'phpunit',
29+
MigrationTypes::MIGRATION_TYPE_CREATE_INDEX,
30+
[
31+
'index' => 'index',
32+
'body' => [
33+
'mappings' => [
34+
'phpunit' => [
35+
'dynamic' => 'strict',
36+
'properties' => [
37+
'title' => [
38+
'type' => 'text'
39+
],
40+
'count' => [
41+
'type' => 'integer'
42+
]
43+
]
44+
]
45+
],
46+
'settings' => [
47+
'refresh_interval' => "30s"
48+
]
49+
]
50+
],
51+
$priority
52+
));
53+
}
54+
55+
public function updateIndex(int $priority = 1, bool $stopOnFailure = true)
56+
{
57+
$this->assertTrue($this->migrationService->addMigrationStep(
58+
'phpunit',
59+
MigrationTypes::MIGRATION_TYPE_UPDATE_INDEX_MAPPING,
60+
[
61+
'index' => 'index'
62+
],
63+
$priority,
64+
$stopOnFailure
65+
));
66+
}
67+
68+
public function deleteIndex(int $priority = 1)
69+
{
70+
$this->assertTrue($this->migrationService->addMigrationStep(
71+
'phpunit',
72+
MigrationTypes::MIGRATION_TYPE_DELETE_INDEX,
73+
[
74+
'index' => 'index'
75+
],
76+
$priority
77+
));
78+
}
79+
80+
public function alias(int $priority = 1)
81+
{
82+
$this->assertTrue($this->migrationService->addMigrationStep(
83+
'phpunit',
84+
MigrationTypes::MIGRATION_TYPE_PUT_ALIAS,
85+
[
86+
'index' => 'index'
87+
],
88+
$priority
89+
));
90+
}
91+
92+
public function deleteByQuery(int $priority = 1)
93+
{
94+
$this->assertTrue($this->migrationService->addMigrationStep(
95+
'phpunit',
96+
MigrationTypes::MIGRATION_TYPE_DELETE_BY_QUERY,
97+
[
98+
'index' => 'index',
99+
'query' => []
100+
],
101+
$priority
102+
));
103+
}
104+
105+
public function updateByQuery(int $priority = 1)
106+
{
107+
$this->assertTrue($this->migrationService->addMigrationStep(
108+
'phpunit',
109+
MigrationTypes::MIGRATION_TYPE_UPDATE_BY_QUERY,
110+
[
111+
'index' => 'index',
112+
'query' => []
113+
],
114+
$priority
115+
));
116+
}
117+
118+
public function reindex(int $priority = 1)
119+
{
120+
$this->assertTrue($this->migrationService->addMigrationStep(
121+
'phpunit',
122+
MigrationTypes::MIGRATION_TYPE_REINDEX,
123+
[
124+
'index' => 'index',
125+
'destindex' => 'phpunit'
126+
],
127+
$priority
128+
));
129+
}
130+
}

0 commit comments

Comments
 (0)