Skip to content

Commit 17383f9

Browse files
committed
add functional test
1 parent a8886c7 commit 17383f9

File tree

3 files changed

+40
-1
lines changed

3 files changed

+40
-1
lines changed

ansible/roles/elasticsearch/templates/config-default.yml

+2
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ node.name: Elastica
3333
# Added for snapshot tests
3434
path.repo: ["/tmp/test_register", "/tmp/test_repository"]
3535

36+
script.engine.groovy.file: on
37+
3638
{% endblock %}
3739

3840
{% block config %}

test/data/calculate-distance.groovy

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
doc['location'].arcDistanceInKm(lat,lon)

test/lib/Elastica/Test/ScriptFileTest.php

+37-1
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,53 @@
11
<?php
22
namespace Elastica\Test;
33

4+
use Elastica\Document;
5+
use Elastica\Query;
46
use Elastica\ScriptFile;
57
use Elastica\Test\Base as BaseTest;
8+
use Elastica\Type;
9+
use Elastica\Type\Mapping;
610

711
class ScriptFileTest extends BaseTest
812
{
13+
/**
14+
* @group functional
15+
*/
16+
public function testSearch()
17+
{
18+
$index = $this->_createIndex();
19+
$type = $index->getType('test');
20+
21+
$type->setMapping(new Mapping(null, array(
22+
'location' => array('type' => 'geo_point'),
23+
)));
24+
25+
$type->addDocuments(array(
26+
new Document(1, array('location' => array('lat' => 48.8825968, 'lon' => 2.3706111))),
27+
new Document(2, array('location' => array('lat' => 48.9057932, 'lon' => 2.2739735))),
28+
));
29+
30+
$index->refresh();
31+
32+
$scriptFile = new ScriptFile('calculate-distance', array('lat' => 48.858859, 'lon' => 2.3470599));
33+
34+
$query = new Query();
35+
$query->addScriptField('distance', $scriptFile);
36+
37+
$resultSet = $type->search($query);
38+
$results = $resultSet->getResults();
39+
40+
$this->assertEquals(2, $resultSet->count());
41+
$this->assertEquals(array(3.1494078652615), $results[0]->__get('distance'));
42+
$this->assertEquals(array(7.4639825876924561), $results[1]->__get('distance'));
43+
}
44+
945
/**
1046
* @group unit
1147
*/
1248
public function testConstructor()
1349
{
14-
$value = "calculate-distance.groovy";
50+
$value = 'calculate-distance.groovy';
1551
$scriptFile = new ScriptFile($value);
1652

1753
$expected = array(

0 commit comments

Comments
 (0)