|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace AmaTeam\ElasticSearch\Test\Suite\Acceptance\Client\MappingClient; |
|
6
|
|
|
|
|
7
|
|
|
use AmaTeam\ElasticSearch\Client\MappingClient; |
|
8
|
|
|
use AmaTeam\ElasticSearch\Mapping\Mapping; |
|
9
|
|
|
use AmaTeam\ElasticSearch\Mapping\Type\IntegerType; |
|
10
|
|
|
use AmaTeam\ElasticSearch\Mapping\Type\NestedType; |
|
11
|
|
|
use AmaTeam\ElasticSearch\Mapping\Type\Parameter\DynamicParameter; |
|
12
|
|
|
use AmaTeam\ElasticSearch\Mapping\Type\Parameter\IndexOptionsParameter; |
|
13
|
|
|
use AmaTeam\ElasticSearch\Mapping\Type\RootType; |
|
14
|
|
|
use AmaTeam\ElasticSearch\Mapping\Type\TextType; |
|
15
|
|
|
use AmaTeam\ElasticSearch\Test\Support\Allure\AttachmentAware; |
|
16
|
|
|
use AmaTeam\ElasticSearch\Test\Support\TestClientFactory; |
|
17
|
|
|
use Codeception\Test\Unit; |
|
18
|
|
|
use Elasticsearch\Client; |
|
19
|
|
|
use PHPUnit\Framework\Assert; |
|
20
|
|
|
use Ramsey\Uuid\Uuid; |
|
21
|
|
|
|
|
22
|
|
|
class SetAndGetMappingTest extends Unit |
|
23
|
|
|
{ |
|
24
|
|
|
use AttachmentAware; |
|
25
|
|
|
|
|
26
|
|
|
const TYPE = 'default'; |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* @var Client |
|
30
|
|
|
*/ |
|
31
|
|
|
private $client; |
|
32
|
|
|
/** |
|
33
|
|
|
* @var string |
|
34
|
|
|
*/ |
|
35
|
|
|
private $index; |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* @inheritDoc |
|
39
|
|
|
*/ |
|
40
|
|
|
protected function _before() |
|
41
|
|
|
{ |
|
42
|
|
|
$this->client = (new TestClientFactory())->getClient(); |
|
43
|
|
|
$this->index = (string) Uuid::uuid4(); |
|
44
|
|
|
$this->client->indices()->create(['index' => $this->index]); |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
protected function _after() |
|
48
|
|
|
{ |
|
49
|
|
|
$this->client->indices()->delete(['index' => $this->index]); |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
public function dataProvider() |
|
53
|
|
|
{ |
|
54
|
|
|
return [ |
|
55
|
|
|
[ |
|
56
|
|
|
(new Mapping(RootType::ID)) |
|
57
|
|
|
->setParameter(DynamicParameter::ID, DynamicParameter::VALUE_STRICT) |
|
58
|
|
|
->setProperty('id', (new Mapping(IntegerType::ID))->setParameter('index', false)) |
|
59
|
|
|
->setProperty( |
|
60
|
|
|
'title', |
|
61
|
|
|
(new Mapping(TextType::ID)) |
|
62
|
|
|
->setParameter(IndexOptionsParameter::ID, IndexOptionsParameter::VALUE_OFFSETS) |
|
63
|
|
|
) |
|
64
|
|
|
->setProperty( |
|
65
|
|
|
'departments', |
|
66
|
|
|
(new Mapping(NestedType::ID)) |
|
67
|
|
|
->setParameter(DynamicParameter::ID, DynamicParameter::VALUE_FALSE) |
|
68
|
|
|
->setProperty('id', (new Mapping(IntegerType::ID))->setParameter('index', false)) |
|
69
|
|
|
->setProperty( |
|
70
|
|
|
'title', |
|
71
|
|
|
(new Mapping(TextType::ID)) |
|
72
|
|
|
->setParameter(IndexOptionsParameter::ID, IndexOptionsParameter::VALUE_OFFSETS) |
|
73
|
|
|
) |
|
74
|
|
|
) |
|
75
|
|
|
] |
|
76
|
|
|
]; |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
/** |
|
80
|
|
|
* @param Mapping $mapping |
|
81
|
|
|
* |
|
82
|
|
|
* @test |
|
83
|
|
|
* @dataProvider dataProvider |
|
84
|
|
|
*/ |
|
85
|
|
|
public function setAndGetMapping(Mapping $mapping) |
|
86
|
|
|
{ |
|
87
|
|
|
$pusher = new MappingClient($this->client); |
|
88
|
|
|
$this->addDataAttachment($mapping, 'input'); |
|
89
|
|
|
$pusher->apply($this->index, self::TYPE, $mapping); |
|
90
|
|
|
$result = $pusher->get($this->index, self::TYPE); |
|
91
|
|
|
$this->addDataAttachment($result, 'output'); |
|
92
|
|
|
Assert::assertEquals($mapping, $result); |
|
93
|
|
|
} |
|
94
|
|
|
} |
|
95
|
|
|
|