-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathShape.phpt
More file actions
76 lines (55 loc) · 1.81 KB
/
Copy pathShape.phpt
File metadata and controls
76 lines (55 loc) · 1.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
<?php declare(strict_types = 1);
namespace SpameriTests\ElasticQuery\Query;
require_once __DIR__ . '/../../bootstrap.php';
class Shape extends \SpameriTests\ElasticQuery\AbstractElasticTestCase
{
protected const INDEX = 'spameri_test_query_shape';
protected function mapping(): array|null
{
return ['mappings' => ['properties' => ['geometry' => ['type' => 'shape']]]];
}
public function testToArray(): void
{
$shape = new \Spameri\ElasticQuery\Query\Shape(
field: 'geometry',
shape: ['type' => 'envelope', 'coordinates' => [[0, 100], [100, 0]]],
relation: 'intersects',
);
$array = $shape->toArray();
\Tester\Assert::same('envelope', $array['shape']['geometry']['shape']['type']);
\Tester\Assert::same('intersects', $array['shape']['geometry']['relation']);
}
public function testToArrayWithIndexedShape(): void
{
$shape = new \Spameri\ElasticQuery\Query\Shape(
field: 'geometry',
indexedShape: new \Spameri\ElasticQuery\Query\IndexedShape(
id: 'box',
index: 'shapes',
path: 'geometry',
),
boost: 1.5,
);
\Tester\Assert::same('box', $shape->toArray()['shape']['geometry']['indexed_shape']['id']);
\Tester\Assert::same(1.5, $shape->toArray()['shape']['boost']);
}
public function testCreate(): void
{
$this->indexDocument(['geometry' => ['type' => 'point', 'coordinates' => [10, 10]]]);
$query = new \Spameri\ElasticQuery\ElasticQuery(
new \Spameri\ElasticQuery\Query\QueryCollection(
null,
new \Spameri\ElasticQuery\Query\MustCollection(
new \Spameri\ElasticQuery\Query\Shape(
field: 'geometry',
shape: ['type' => 'envelope', 'coordinates' => [[0, 100], [100, 0]]],
relation: 'intersects',
),
),
),
);
$result = $this->search($query);
\Tester\Assert::same(1, $result->stats()->total());
}
}
(new Shape())->run();