1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace AmaTeam\ElasticSearch\Test\Suite\Unit\Mapping; |
6
|
|
|
|
7
|
|
|
use AmaTeam\ElasticSearch\Mapping\Mapping; |
8
|
|
|
use AmaTeam\ElasticSearch\Mapping\Type\BooleanType; |
9
|
|
|
use AmaTeam\ElasticSearch\Mapping\Type\IntegerType; |
10
|
|
|
use AmaTeam\ElasticSearch\Mapping\Type\KeywordType; |
11
|
|
|
use AmaTeam\ElasticSearch\Mapping\Type\ObjectType; |
12
|
|
|
use AmaTeam\ElasticSearch\Mapping\Type\Parameter\AnalyzerParameter; |
13
|
|
|
use AmaTeam\ElasticSearch\Mapping\Type\Parameter\DocValuesParameter; |
14
|
|
|
use AmaTeam\ElasticSearch\Mapping\Type\Parameter\DynamicParameter; |
15
|
|
|
use AmaTeam\ElasticSearch\Mapping\Type\Parameter\IndexParameter; |
16
|
|
|
use AmaTeam\ElasticSearch\Mapping\Type\TextType; |
17
|
|
|
use Codeception\Test\Unit; |
18
|
|
|
use PHPUnit\Framework\Assert; |
19
|
|
|
|
20
|
|
|
class MappingTest extends Unit |
21
|
|
|
{ |
22
|
|
|
public function fromArrayDataProvider() |
23
|
|
|
{ |
24
|
|
|
return [ |
25
|
|
|
[ |
26
|
|
|
[ |
27
|
|
|
'dynamic' => 'strict', |
28
|
|
|
'properties' => [ |
29
|
|
|
'id' => [ |
30
|
|
|
'type' => 'integer', |
31
|
|
|
'index' => false, |
32
|
|
|
], |
33
|
|
|
'title' => [ |
34
|
|
|
'type' => 'text', |
35
|
|
|
'analyzer' => 'title', |
36
|
|
|
], |
37
|
|
|
'category' => [ |
38
|
|
|
'type' => 'keyword', |
39
|
|
|
'doc_values' => true, |
40
|
|
|
], |
41
|
|
|
'aspects' => [ |
42
|
|
|
'type' => 'object', |
43
|
|
|
'dynamic' => 'true', |
44
|
|
|
'properties' => [ |
45
|
|
|
'comfortable' => ['type' => 'boolean'], |
46
|
|
|
'cheap' => ['type' => 'boolean'], |
47
|
|
|
] |
48
|
|
|
] |
49
|
|
|
] |
50
|
|
|
], |
51
|
|
|
(new Mapping()) |
52
|
|
|
->setParameter(DynamicParameter::ID, DynamicParameter::VALUE_STRICT) |
53
|
|
|
->setProperties([ |
54
|
|
|
'id' => (new Mapping(IntegerType::ID))->setParameter(IndexParameter::ID, false), |
55
|
|
|
'title' => (new Mapping(TextType::ID))->setParameter(AnalyzerParameter::ID, 'title'), |
56
|
|
|
'category' => (new Mapping(KeywordType::ID))->setParameter(DocValuesParameter::ID, true), |
57
|
|
|
'aspects' => (new Mapping(ObjectType::ID)) |
58
|
|
|
->setParameter(DynamicParameter::ID, DynamicParameter::VALUE_TRUE) |
59
|
|
|
->setProperty('comfortable', new Mapping(BooleanType::ID)) |
60
|
|
|
->setProperty('cheap', new Mapping(BooleanType::ID)) |
61
|
|
|
]) |
62
|
|
|
] |
63
|
|
|
]; |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* @param array $input |
68
|
|
|
* @param Mapping $expectation |
69
|
|
|
* |
70
|
|
|
* @test |
71
|
|
|
* @dataProvider fromArrayDataProvider |
72
|
|
|
*/ |
73
|
|
|
public function shouldCorrectlyDeserializeArray(array $input, Mapping $expectation) |
74
|
|
|
{ |
75
|
|
|
$result = Mapping::fromArray($input); |
76
|
|
|
Assert::assertEquals($expectation, $result); |
77
|
|
|
} |
78
|
|
|
} |
79
|
|
|
|