|
| 1 | +<?php declare(strict_types = 1); |
| 2 | + |
| 3 | +namespace SpameriTests\ElasticQuery\Query; |
| 4 | + |
| 5 | +require_once __DIR__ . '/../../bootstrap.php'; |
| 6 | + |
| 7 | + |
| 8 | +class Shape extends \Tester\TestCase |
| 9 | +{ |
| 10 | + |
| 11 | + private const INDEX = 'spameri_test_query_shape'; |
| 12 | + |
| 13 | + |
| 14 | + public function setUp(): void |
| 15 | + { |
| 16 | + $ch = \curl_init(); |
| 17 | + \curl_setopt($ch, \CURLOPT_URL, \ELASTICSEARCH_HOST . '/' . self::INDEX); |
| 18 | + \curl_setopt($ch, \CURLOPT_RETURNTRANSFER, 1); |
| 19 | + \curl_setopt($ch, \CURLOPT_CUSTOMREQUEST, 'PUT'); |
| 20 | + \curl_setopt($ch, \CURLOPT_HTTPHEADER, ['Content-Type: application/json']); |
| 21 | + |
| 22 | + \curl_exec($ch); |
| 23 | + } |
| 24 | + |
| 25 | + |
| 26 | + public function testToArray(): void |
| 27 | + { |
| 28 | + $shape = new \Spameri\ElasticQuery\Query\Shape( |
| 29 | + field: 'geometry', |
| 30 | + shape: ['type' => 'envelope', 'coordinates' => [[0, 100], [100, 0]]], |
| 31 | + relation: 'intersects', |
| 32 | + ); |
| 33 | + |
| 34 | + $array = $shape->toArray(); |
| 35 | + |
| 36 | + \Tester\Assert::same('envelope', $array['shape']['geometry']['shape']['type']); |
| 37 | + } |
| 38 | + |
| 39 | + |
| 40 | + public function testKey(): void |
| 41 | + { |
| 42 | + $shape = new \Spameri\ElasticQuery\Query\Shape('geometry', ['type' => 'point', 'coordinates' => [0, 0]]); |
| 43 | + |
| 44 | + \Tester\Assert::same('shape_geometry', $shape->key()); |
| 45 | + } |
| 46 | + |
| 47 | + |
| 48 | + public function tearDown(): void |
| 49 | + { |
| 50 | + $ch = \curl_init(); |
| 51 | + \curl_setopt($ch, \CURLOPT_URL, \ELASTICSEARCH_HOST . '/' . self::INDEX); |
| 52 | + \curl_setopt($ch, \CURLOPT_RETURNTRANSFER, 1); |
| 53 | + \curl_setopt($ch, \CURLOPT_CUSTOMREQUEST, 'DELETE'); |
| 54 | + \curl_setopt($ch, \CURLOPT_HTTPHEADER, ['Content-Type: application/json']); |
| 55 | + |
| 56 | + \curl_exec($ch); |
| 57 | + } |
| 58 | + |
| 59 | +} |
| 60 | + |
| 61 | +(new Shape())->run(); |
0 commit comments