blob: 6cbfd37bd4d5af08cb8ad2ee9c74a6d3c28be939 (
plain)
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
77
78
79
80
81
82
83
84
85
86
87
88
|
<?php
namespace Elastica\Test;
use Elastica\Exception\QueryBuilderException;
use Elastica\Query;
use Elastica\QueryBuilder;
use Elastica\Suggest;
class QueryBuilderTest extends \PHPUnit_Framework_TestCase
{
/**
* @group unit
*/
public function testCustomDSL()
{
$qb = new QueryBuilder();
// test custom DSL
$qb->addDSL(new CustomDSL());
$this->assertTrue($qb->custom()->custom_method(), 'custom DSL execution failed');
// test custom DSL exception message
$exceptionMessage = '';
try {
$qb->invalid();
} catch (QueryBuilderException $exception) {
$exceptionMessage = $exception->getMessage();
}
$this->assertEquals('DSL "invalid" not supported', $exceptionMessage);
}
/**
* @group unit
*/
public function testFacade()
{
$qb = new QueryBuilder();
// test one example QueryBuilder flow for each default DSL type
$this->assertInstanceOf('Elastica\Query\AbstractQuery', $qb->query()->match());
$this->assertInstanceOf('Elastica\Filter\AbstractFilter', $qb->filter()->bool());
$this->assertInstanceOf('Elastica\Aggregation\AbstractAggregation', $qb->aggregation()->avg('name'));
$this->assertInstanceOf('Elastica\Suggest\AbstractSuggest', $qb->suggest()->term('name', 'field'));
}
/**
* @group unit
*/
public function testFacadeException()
{
$qb = new QueryBuilder(new QueryBuilder\Version\Version100());
// undefined
$exceptionMessage = '';
try {
$qb->query()->invalid();
} catch (QueryBuilderException $exception) {
$exceptionMessage = $exception->getMessage();
}
$this->assertEquals('undefined query "invalid"', $exceptionMessage);
// unsupported
$exceptionMessage = '';
try {
$qb->aggregation()->top_hits('top_hits');
} catch (QueryBuilderException $exception) {
$exceptionMessage = $exception->getMessage();
}
$this->assertEquals('aggregation "top_hits" in Version100 not supported', $exceptionMessage);
}
}
class CustomDSL implements QueryBuilder\DSL
{
public function getType()
{
return 'custom';
}
public function custom_method()
{
return true;
}
}
|