1
|
|
|
<?php |
2
|
|
|
namespace Tests\Unit\Business\Mapping; |
3
|
|
|
|
4
|
|
|
use Tests\TestCase; |
5
|
|
|
use Triadev\Es\Mapping\Mapping\Blueprint; |
6
|
|
|
|
7
|
|
|
class BlueprintTest extends TestCase |
8
|
|
|
{ |
9
|
|
|
/** @var Blueprint */ |
10
|
|
|
private $blueprint; |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* Setup the test environment. |
14
|
|
|
*/ |
15
|
|
|
public function setUp() |
16
|
|
|
{ |
17
|
|
|
parent::setUp(); |
18
|
|
|
|
19
|
|
|
$this->blueprint = new Blueprint(); |
20
|
|
|
} |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* @test |
24
|
|
|
*/ |
25
|
|
|
public function it_builds_mapping_with_fluent_syntax() |
26
|
|
|
{ |
27
|
|
|
$this->blueprint->text('TEXT') |
28
|
|
|
->analyzer('ANALYZER') |
29
|
|
|
->boost(5); |
30
|
|
|
|
31
|
|
|
$this->blueprint->keyword('KEYWORD'); |
32
|
|
|
$this->blueprint->long('LONG'); |
33
|
|
|
$this->blueprint->integer('INTEGER'); |
34
|
|
|
$this->blueprint->short('SHORT'); |
35
|
|
|
$this->blueprint->byte('BYTE'); |
36
|
|
|
$this->blueprint->double('DOUBLE'); |
37
|
|
|
$this->blueprint->float('FLOAT'); |
38
|
|
|
$this->blueprint->halfFloat('HALF_FLOAT'); |
39
|
|
|
$this->blueprint->scaledFloat('SCALED_FLOAT'); |
40
|
|
|
$this->blueprint->date('DATE'); |
41
|
|
|
$this->blueprint->boolean('BOOLEAN'); |
42
|
|
|
$this->blueprint->binary('BINARY'); |
43
|
|
|
$this->blueprint->range('RANGE_INTEGER', 'integer'); |
44
|
|
|
$this->blueprint->range('RANGE_FLOAT', 'float'); |
45
|
|
|
$this->blueprint->range('RANGE_LONG', 'long'); |
46
|
|
|
$this->blueprint->range('RANGE_DOUBLE', 'double'); |
47
|
|
|
$this->blueprint->range('RANGE_DATE', 'date'); |
48
|
|
|
$this->blueprint->range('RANGE_IP', 'ip'); |
49
|
|
|
$this->blueprint->nested('NESTED')->callback(function (Blueprint $blueprint) { |
50
|
|
|
$blueprint->keyword('NESTED_KEYWORD'); |
51
|
|
|
}); |
52
|
|
|
$this->blueprint->object('OBJECT')->callback(function (Blueprint $blueprint) { |
53
|
|
|
$blueprint->keyword('OBJECT_KEYWORD'); |
54
|
|
|
}); |
55
|
|
|
$this->blueprint->geoPoint('GEO_POINT'); |
56
|
|
|
$this->blueprint->geoShape('GEO_SHAPE'); |
57
|
|
|
$this->blueprint->ip('IP'); |
58
|
|
|
$this->blueprint->completion('COMPLETION'); |
59
|
|
|
$this->blueprint->tokenCount('TOKEN_COUNT'); |
60
|
|
|
|
61
|
|
|
$this->assertEquals([ |
62
|
|
|
'TEXT' => [ |
63
|
|
|
'type' => 'text', |
64
|
|
|
'analyzer' => 'ANALYZER', |
65
|
|
|
'boost' => 5 |
66
|
|
|
], |
67
|
|
|
'KEYWORD' => [ |
68
|
|
|
'type' => 'keyword' |
69
|
|
|
], |
70
|
|
|
'LONG' => [ |
71
|
|
|
'type' => 'long' |
72
|
|
|
], |
73
|
|
|
'INTEGER' => [ |
74
|
|
|
'type' => 'integer' |
75
|
|
|
], |
76
|
|
|
'SHORT' => [ |
77
|
|
|
'type' => 'short' |
78
|
|
|
], |
79
|
|
|
'BYTE' => [ |
80
|
|
|
'type' => 'byte' |
81
|
|
|
], |
82
|
|
|
'DOUBLE' => [ |
83
|
|
|
'type' => 'double' |
84
|
|
|
], |
85
|
|
|
'FLOAT' => [ |
86
|
|
|
'type' => 'float' |
87
|
|
|
], |
88
|
|
|
'HALF_FLOAT' => [ |
89
|
|
|
'type' => 'half_float' |
90
|
|
|
], |
91
|
|
|
'SCALED_FLOAT' => [ |
92
|
|
|
'type' => 'scaled_float' |
93
|
|
|
], |
94
|
|
|
'DATE' => [ |
95
|
|
|
'type' => 'date' |
96
|
|
|
], |
97
|
|
|
'BOOLEAN' => [ |
98
|
|
|
'type' => 'boolean' |
99
|
|
|
], |
100
|
|
|
'BINARY' => [ |
101
|
|
|
'type' => 'binary' |
102
|
|
|
], |
103
|
|
|
'RANGE_INTEGER' => [ |
104
|
|
|
'type' => 'integer_range' |
105
|
|
|
], |
106
|
|
|
'RANGE_FLOAT' => [ |
107
|
|
|
'type' => 'float_range' |
108
|
|
|
], |
109
|
|
|
'RANGE_LONG' => [ |
110
|
|
|
'type' => 'long_range' |
111
|
|
|
], |
112
|
|
|
'RANGE_DOUBLE' => [ |
113
|
|
|
'type' => 'double_range' |
114
|
|
|
], |
115
|
|
|
'RANGE_DATE' => [ |
116
|
|
|
'type' => 'date_range' |
117
|
|
|
], |
118
|
|
|
'RANGE_IP' => [ |
119
|
|
|
'type' => 'ip_range' |
120
|
|
|
], |
121
|
|
|
'NESTED' => [ |
122
|
|
|
'type' => 'nested', |
123
|
|
|
'properties' => [ |
124
|
|
|
'NESTED_KEYWORD' => [ |
125
|
|
|
'type' => 'keyword' |
126
|
|
|
] |
127
|
|
|
] |
128
|
|
|
], |
129
|
|
|
'OBJECT' => [ |
130
|
|
|
'type' => 'nested', |
131
|
|
|
'properties' => [ |
132
|
|
|
'OBJECT_KEYWORD' => [ |
133
|
|
|
'type' => 'keyword' |
134
|
|
|
] |
135
|
|
|
] |
136
|
|
|
], |
137
|
|
|
'GEO_POINT' => [ |
138
|
|
|
'type' => 'geo_point' |
139
|
|
|
], |
140
|
|
|
'GEO_SHAPE' => [ |
141
|
|
|
'type' => 'geo_shape' |
142
|
|
|
], |
143
|
|
|
'IP' => [ |
144
|
|
|
'type' => 'ip' |
145
|
|
|
], |
146
|
|
|
'COMPLETION' => [ |
147
|
|
|
'type' => 'completion' |
148
|
|
|
], |
149
|
|
|
'TOKEN_COUNT' => [ |
150
|
|
|
'type' => 'token_count' |
151
|
|
|
] |
152
|
|
|
], $this->blueprint->toDsl()); |
153
|
|
|
} |
154
|
|
|
|
155
|
|
|
/** |
156
|
|
|
* @test |
157
|
|
|
*/ |
158
|
|
|
public function it_builds_mapping_with_attributes() |
159
|
|
|
{ |
160
|
|
|
$this->blueprint->text('TEXT', ['analyzer' => 'ANALYZER']); |
161
|
|
|
|
162
|
|
|
$this->assertEquals([ |
163
|
|
|
'TEXT' => [ |
164
|
|
|
'type' => 'text', |
165
|
|
|
'analyzer' => 'ANALYZER' |
166
|
|
|
] |
167
|
|
|
], $this->blueprint->toDsl()); |
168
|
|
|
} |
169
|
|
|
|
170
|
|
|
/** |
171
|
|
|
* @test |
172
|
|
|
* @expectedException \InvalidArgumentException |
173
|
|
|
*/ |
174
|
|
|
public function it_throws_an_exception_if_range_type_is_invalid() |
175
|
|
|
{ |
176
|
|
|
$this->blueprint->range('FIELD', 'INVALID'); |
177
|
|
|
} |
178
|
|
|
} |
179
|
|
|
|