|
1
|
|
|
<?php |
|
2
|
|
|
namespace Tests\Unit\Business\Mapping; |
|
3
|
|
|
|
|
4
|
|
|
use Tests\TestCase; |
|
5
|
|
|
use Triadev\Es\Mapping\Mapping\Blueprint; |
|
6
|
|
|
use Triadev\Es\Mapping\Mapping\Compiler; |
|
7
|
|
|
use Triadev\Es\Mapping\Mapping\Fluent\FluentBinary; |
|
8
|
|
|
use Triadev\Es\Mapping\Mapping\Fluent\FluentBoolean; |
|
9
|
|
|
use Triadev\Es\Mapping\Mapping\Fluent\FluentByte; |
|
10
|
|
|
use Triadev\Es\Mapping\Mapping\Fluent\FluentCompletion; |
|
11
|
|
|
use Triadev\Es\Mapping\Mapping\Fluent\FluentDate; |
|
12
|
|
|
use Triadev\Es\Mapping\Mapping\Fluent\FluentDateRange; |
|
13
|
|
|
use Triadev\Es\Mapping\Mapping\Fluent\FluentDouble; |
|
14
|
|
|
use Triadev\Es\Mapping\Mapping\Fluent\FluentDoubleRange; |
|
15
|
|
|
use Triadev\Es\Mapping\Mapping\Fluent\FluentFloat; |
|
16
|
|
|
use Triadev\Es\Mapping\Mapping\Fluent\FluentFloatRange; |
|
17
|
|
|
use Triadev\Es\Mapping\Mapping\Fluent\FluentGeoPoint; |
|
18
|
|
|
use Triadev\Es\Mapping\Mapping\Fluent\FluentGeoShape; |
|
19
|
|
|
use Triadev\Es\Mapping\Mapping\Fluent\FluentHalfFloat; |
|
20
|
|
|
use Triadev\Es\Mapping\Mapping\Fluent\FluentInteger; |
|
21
|
|
|
use Triadev\Es\Mapping\Mapping\Fluent\FluentIntegerRange; |
|
22
|
|
|
use Triadev\Es\Mapping\Mapping\Fluent\FluentIp; |
|
23
|
|
|
use Triadev\Es\Mapping\Mapping\Fluent\FluentIpRange; |
|
24
|
|
|
use Triadev\Es\Mapping\Mapping\Fluent\FluentKeyword; |
|
25
|
|
|
use Triadev\Es\Mapping\Mapping\Fluent\FluentLong; |
|
26
|
|
|
use Triadev\Es\Mapping\Mapping\Fluent\FluentLongRange; |
|
27
|
|
|
use Triadev\Es\Mapping\Mapping\Fluent\FluentNested; |
|
28
|
|
|
use Triadev\Es\Mapping\Mapping\Fluent\FluentObject; |
|
29
|
|
|
use Triadev\Es\Mapping\Mapping\Fluent\FluentScaledFloat; |
|
30
|
|
|
use Triadev\Es\Mapping\Mapping\Fluent\FluentShort; |
|
31
|
|
|
use Triadev\Es\Mapping\Mapping\Fluent\FluentText; |
|
32
|
|
|
use Triadev\Es\Mapping\Mapping\Fluent\FluentTokenCount; |
|
33
|
|
|
|
|
34
|
|
|
class CompilerTest extends TestCase |
|
35
|
|
|
{ |
|
36
|
|
|
/** @var Compiler */ |
|
37
|
|
|
private $compiler; |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* Setup the test environment. |
|
41
|
|
|
*/ |
|
42
|
|
|
public function setUp() |
|
43
|
|
|
{ |
|
44
|
|
|
parent::setUp(); |
|
45
|
|
|
|
|
46
|
|
|
$this->compiler = new Compiler(); |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
/** |
|
50
|
|
|
* @test |
|
51
|
|
|
*/ |
|
52
|
|
|
public function it_compiles_a_text() |
|
53
|
|
|
{ |
|
54
|
|
|
$this->assertEquals([ |
|
55
|
|
|
'type' => 'text', |
|
56
|
|
|
'analyzer' => 'ANALYZER' |
|
57
|
|
|
], $this->compiler->compileText(new FluentText([ |
|
58
|
|
|
'type' => 'text', |
|
59
|
|
|
'analyzer' => 'ANALYZER' |
|
60
|
|
|
]))); |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
/** |
|
64
|
|
|
* @test |
|
65
|
|
|
*/ |
|
66
|
|
|
public function it_compiles_a_keyword() |
|
67
|
|
|
{ |
|
68
|
|
|
$this->assertEquals([ |
|
69
|
|
|
'type' => 'keyword' |
|
70
|
|
|
], $this->compiler->compileKeyword(new FluentKeyword())); |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
/** |
|
74
|
|
|
* @test |
|
75
|
|
|
*/ |
|
76
|
|
|
public function it_compiles_long() |
|
77
|
|
|
{ |
|
78
|
|
|
$this->assertEquals([ |
|
79
|
|
|
'type' => 'long' |
|
80
|
|
|
], $this->compiler->compileLong(new FluentLong([ |
|
81
|
|
|
'type' => 'long' |
|
82
|
|
|
]))); |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
/** |
|
86
|
|
|
* @test |
|
87
|
|
|
*/ |
|
88
|
|
|
public function it_compiles_integer() |
|
89
|
|
|
{ |
|
90
|
|
|
$this->assertEquals([ |
|
91
|
|
|
'type' => 'integer' |
|
92
|
|
|
], $this->compiler->compileInteger(new FluentInteger([ |
|
93
|
|
|
'type' => 'integer' |
|
94
|
|
|
]))); |
|
95
|
|
|
} |
|
96
|
|
|
|
|
97
|
|
|
/** |
|
98
|
|
|
* @test |
|
99
|
|
|
*/ |
|
100
|
|
|
public function it_compiles_short() |
|
101
|
|
|
{ |
|
102
|
|
|
$this->assertEquals([ |
|
103
|
|
|
'type' => 'short' |
|
104
|
|
|
], $this->compiler->compileShort(new FluentShort([ |
|
105
|
|
|
'type' => 'short' |
|
106
|
|
|
]))); |
|
107
|
|
|
} |
|
108
|
|
|
|
|
109
|
|
|
/** |
|
110
|
|
|
* @test |
|
111
|
|
|
*/ |
|
112
|
|
|
public function it_compiles_byte() |
|
113
|
|
|
{ |
|
114
|
|
|
$this->assertEquals([ |
|
115
|
|
|
'type' => 'byte' |
|
116
|
|
|
], $this->compiler->compileByte(new FluentByte([ |
|
117
|
|
|
'type' => 'byte' |
|
118
|
|
|
]))); |
|
119
|
|
|
} |
|
120
|
|
|
|
|
121
|
|
|
/** |
|
122
|
|
|
* @test |
|
123
|
|
|
*/ |
|
124
|
|
|
public function it_compiles_double() |
|
125
|
|
|
{ |
|
126
|
|
|
$this->assertEquals([ |
|
127
|
|
|
'type' => 'double' |
|
128
|
|
|
], $this->compiler->compileDouble(new FluentDouble([ |
|
129
|
|
|
'type' => 'double' |
|
130
|
|
|
]))); |
|
131
|
|
|
} |
|
132
|
|
|
|
|
133
|
|
|
/** |
|
134
|
|
|
* @test |
|
135
|
|
|
*/ |
|
136
|
|
|
public function it_compiles_float() |
|
137
|
|
|
{ |
|
138
|
|
|
$this->assertEquals([ |
|
139
|
|
|
'type' => 'float' |
|
140
|
|
|
], $this->compiler->compileFloat(new FluentFloat([ |
|
141
|
|
|
'type' => 'float' |
|
142
|
|
|
]))); |
|
143
|
|
|
} |
|
144
|
|
|
|
|
145
|
|
|
/** |
|
146
|
|
|
* @test |
|
147
|
|
|
*/ |
|
148
|
|
|
public function it_compiles_half_float() |
|
149
|
|
|
{ |
|
150
|
|
|
$this->assertEquals([ |
|
151
|
|
|
'type' => 'half_float' |
|
152
|
|
|
], $this->compiler->compileHalfFloat(new FluentHalfFloat([ |
|
153
|
|
|
'type' => 'half_float' |
|
154
|
|
|
]))); |
|
155
|
|
|
} |
|
156
|
|
|
|
|
157
|
|
|
/** |
|
158
|
|
|
* @test |
|
159
|
|
|
*/ |
|
160
|
|
|
public function it_compiles_scaled_float() |
|
161
|
|
|
{ |
|
162
|
|
|
$this->assertEquals([ |
|
163
|
|
|
'type' => 'scaled_float' |
|
164
|
|
|
], $this->compiler->compileScaledFloat(new FluentScaledFloat([ |
|
165
|
|
|
'type' => 'scaled_float' |
|
166
|
|
|
]))); |
|
167
|
|
|
} |
|
168
|
|
|
|
|
169
|
|
|
/** |
|
170
|
|
|
* @test |
|
171
|
|
|
*/ |
|
172
|
|
|
public function it_compiles_date() |
|
173
|
|
|
{ |
|
174
|
|
|
$this->assertEquals([ |
|
175
|
|
|
'type' => 'date' |
|
176
|
|
|
], $this->compiler->compileDate(new FluentDate())); |
|
177
|
|
|
} |
|
178
|
|
|
|
|
179
|
|
|
/** |
|
180
|
|
|
* @test |
|
181
|
|
|
*/ |
|
182
|
|
|
public function it_compiles_boolean() |
|
183
|
|
|
{ |
|
184
|
|
|
$this->assertEquals([ |
|
185
|
|
|
'type' => 'boolean' |
|
186
|
|
|
], $this->compiler->compileBoolean(new FluentBoolean())); |
|
187
|
|
|
} |
|
188
|
|
|
|
|
189
|
|
|
/** |
|
190
|
|
|
* @test |
|
191
|
|
|
*/ |
|
192
|
|
|
public function it_compiles_binary() |
|
193
|
|
|
{ |
|
194
|
|
|
$this->assertEquals([ |
|
195
|
|
|
'type' => 'binary' |
|
196
|
|
|
], $this->compiler->compileBinary(new FluentBinary())); |
|
197
|
|
|
} |
|
198
|
|
|
|
|
199
|
|
|
/** |
|
200
|
|
|
* @test |
|
201
|
|
|
*/ |
|
202
|
|
|
public function it_compiles_integer_range() |
|
203
|
|
|
{ |
|
204
|
|
|
$this->assertEquals([ |
|
205
|
|
|
'type' => 'integer_range' |
|
206
|
|
|
], $this->compiler->compileIntegerRange(new FluentIntegerRange([ |
|
207
|
|
|
'type' => 'integer_range' |
|
208
|
|
|
]))); |
|
209
|
|
|
} |
|
210
|
|
|
|
|
211
|
|
|
/** |
|
212
|
|
|
* @test |
|
213
|
|
|
*/ |
|
214
|
|
|
public function it_compiles_float_range() |
|
215
|
|
|
{ |
|
216
|
|
|
$this->assertEquals([ |
|
217
|
|
|
'type' => 'float_range' |
|
218
|
|
|
], $this->compiler->compileFloatRange(new FluentFloatRange([ |
|
219
|
|
|
'type' => 'float_range' |
|
220
|
|
|
]))); |
|
221
|
|
|
} |
|
222
|
|
|
|
|
223
|
|
|
/** |
|
224
|
|
|
* @test |
|
225
|
|
|
*/ |
|
226
|
|
|
public function it_compiles_long_range() |
|
227
|
|
|
{ |
|
228
|
|
|
$this->assertEquals([ |
|
229
|
|
|
'type' => 'long_range' |
|
230
|
|
|
], $this->compiler->compileLongRange(new FluentLongRange([ |
|
231
|
|
|
'type' => 'long_range' |
|
232
|
|
|
]))); |
|
233
|
|
|
} |
|
234
|
|
|
|
|
235
|
|
|
/** |
|
236
|
|
|
* @test |
|
237
|
|
|
*/ |
|
238
|
|
|
public function it_compiles_double_range() |
|
239
|
|
|
{ |
|
240
|
|
|
$this->assertEquals([ |
|
241
|
|
|
'type' => 'double_range' |
|
242
|
|
|
], $this->compiler->compileDoubleRange(new FluentDoubleRange([ |
|
243
|
|
|
'type' => 'double_range' |
|
244
|
|
|
]))); |
|
245
|
|
|
} |
|
246
|
|
|
|
|
247
|
|
|
/** |
|
248
|
|
|
* @test |
|
249
|
|
|
*/ |
|
250
|
|
|
public function it_compiles_date_range() |
|
251
|
|
|
{ |
|
252
|
|
|
$this->assertEquals([ |
|
253
|
|
|
'type' => 'date_range' |
|
254
|
|
|
], $this->compiler->compileDateRange(new FluentDateRange([ |
|
255
|
|
|
'type' => 'date_range' |
|
256
|
|
|
]))); |
|
257
|
|
|
} |
|
258
|
|
|
|
|
259
|
|
|
/** |
|
260
|
|
|
* @test |
|
261
|
|
|
*/ |
|
262
|
|
|
public function it_compiles_ip_range() |
|
263
|
|
|
{ |
|
264
|
|
|
$this->assertEquals([ |
|
265
|
|
|
'type' => 'ip_range' |
|
266
|
|
|
], $this->compiler->compileIpRange(new FluentIpRange([ |
|
267
|
|
|
'type' => 'ip_range' |
|
268
|
|
|
]))); |
|
269
|
|
|
} |
|
270
|
|
|
|
|
271
|
|
|
/** |
|
272
|
|
|
* @test |
|
273
|
|
|
*/ |
|
274
|
|
|
public function it_compiles_nested() |
|
275
|
|
|
{ |
|
276
|
|
|
$this->assertEquals([ |
|
277
|
|
|
'type' => 'nested', |
|
278
|
|
|
'properties' => [ |
|
279
|
|
|
'KEYWORD' => [ |
|
280
|
|
|
'type' => 'keyword' |
|
281
|
|
|
] |
|
282
|
|
|
] |
|
283
|
|
|
], $this->compiler->compileNested(new FluentNested([ |
|
284
|
|
|
'callback' => function (Blueprint $blueprint) { |
|
285
|
|
|
$blueprint->keyword('KEYWORD'); |
|
286
|
|
|
} |
|
287
|
|
|
]))); |
|
288
|
|
|
} |
|
289
|
|
|
|
|
290
|
|
|
/** |
|
291
|
|
|
* @test |
|
292
|
|
|
*/ |
|
293
|
|
|
public function it_compiles_object() |
|
294
|
|
|
{ |
|
295
|
|
|
$this->assertEquals([ |
|
296
|
|
|
'type' => 'nested', |
|
297
|
|
|
'properties' => [ |
|
298
|
|
|
'KEYWORD' => [ |
|
299
|
|
|
'type' => 'keyword' |
|
300
|
|
|
] |
|
301
|
|
|
] |
|
302
|
|
|
], $this->compiler->compileObject(new FluentObject([ |
|
303
|
|
|
'callback' => function (Blueprint $blueprint) { |
|
304
|
|
|
$blueprint->keyword('KEYWORD'); |
|
305
|
|
|
} |
|
306
|
|
|
]))); |
|
307
|
|
|
} |
|
308
|
|
|
|
|
309
|
|
|
/** |
|
310
|
|
|
* @test |
|
311
|
|
|
*/ |
|
312
|
|
|
public function it_compiles_geo_point() |
|
313
|
|
|
{ |
|
314
|
|
|
$this->assertEquals([ |
|
315
|
|
|
'type' => 'geo_point' |
|
316
|
|
|
], $this->compiler->compileGeoPoint(new FluentGeoPoint())); |
|
317
|
|
|
} |
|
318
|
|
|
|
|
319
|
|
|
/** |
|
320
|
|
|
* @test |
|
321
|
|
|
*/ |
|
322
|
|
|
public function it_compiles_geo_shape() |
|
323
|
|
|
{ |
|
324
|
|
|
$this->assertEquals([ |
|
325
|
|
|
'type' => 'geo_shape' |
|
326
|
|
|
], $this->compiler->compileGeoShape(new FluentGeoShape())); |
|
327
|
|
|
} |
|
328
|
|
|
|
|
329
|
|
|
/** |
|
330
|
|
|
* @test |
|
331
|
|
|
*/ |
|
332
|
|
|
public function it_compiles_ip() |
|
333
|
|
|
{ |
|
334
|
|
|
$this->assertEquals([ |
|
335
|
|
|
'type' => 'ip' |
|
336
|
|
|
], $this->compiler->compileIp(new FluentIp())); |
|
337
|
|
|
} |
|
338
|
|
|
|
|
339
|
|
|
/** |
|
340
|
|
|
* @test |
|
341
|
|
|
*/ |
|
342
|
|
|
public function it_compiles_completion() |
|
343
|
|
|
{ |
|
344
|
|
|
$this->assertEquals([ |
|
345
|
|
|
'type' => 'completion' |
|
346
|
|
|
], $this->compiler->compileCompletion(new FluentCompletion())); |
|
347
|
|
|
} |
|
348
|
|
|
|
|
349
|
|
|
/** |
|
350
|
|
|
* @test |
|
351
|
|
|
*/ |
|
352
|
|
|
public function it_compiles_token_count() |
|
353
|
|
|
{ |
|
354
|
|
|
$this->assertEquals([ |
|
355
|
|
|
'type' => 'token_count' |
|
356
|
|
|
], $this->compiler->compileTokenCount(new FluentTokenCount())); |
|
357
|
|
|
} |
|
358
|
|
|
} |
|
359
|
|
|
|