Newer
Older
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
<?php
/*
* This file is part of the ONGR package.
*
* (c) NFQ Technologies UAB <info@nfq.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace ONGR\ElasticsearchDSL\Tests\Unit\Bucketing\Aggregation;
use ONGR\ElasticsearchDSL\Aggregation\Bucketing\AdjacencyMatrixAggregation;
use ONGR\ElasticsearchDSL\BuilderInterface;
/**
* Unit test for adjacency matrix aggregation.
*/
class AdjacencyMatrixAggregationTest extends \PHPUnit\Framework\TestCase
{
// /**
// * Test if exception is thrown when not anonymous filter is without name.
// *
// * @expectedException \LogicException
// * @expectedExceptionMessage In not anonymous filters filter name must be set.
// */
// public function testIfExceptionIsThrown()
// {
// $mock = $this->getMockBuilder('ONGR\ElasticsearchDSL\BuilderInterface')->getMock();
// $aggregation = new FiltersAggregation('test_agg');
// $aggregation->addFilter($mock);
// }
/**
* Test GetArray method.
*/
public function testFiltersAggregationGetArray()
{
$mock = $this->getMockBuilder('ONGR\ElasticsearchDSL\BuilderInterface')->getMock();
$aggregation = new AdjacencyMatrixAggregation('test_agg');
$aggregation->addFilter('name', $mock);
$result = $aggregation->getArray();
$this->assertArrayHasKey('filters', $result);
}
/**
* Tests getType method.
*/
public function testFiltersAggregationGetType()
{
$aggregation = new AdjacencyMatrixAggregation('foo');
$result = $aggregation->getType();
$this->assertEquals('adjacency_matrix', $result);
}
/**
* Test for filter aggregation toArray() method.
*/
public function testToArray()
{
$aggregation = new AdjacencyMatrixAggregation('test_agg');
$filter = $this->getMockBuilder('ONGR\ElasticsearchDSL\BuilderInterface')
->setMethods(['toArray', 'getType'])
->getMockForAbstractClass();
$filter->expects($this->any())
->method('toArray')
->willReturn(['test_field' => ['test_value' => 'test']]);
$aggregation->addFilter('first', $filter );
$aggregation->addFilter('second', $filter );
$results = $aggregation->toArray();
$expected = [
'adjacency_matrix' => [
'filters' => [
'first' => [
'test_field' => [
'test_value' => 'test',
],
],
'second' => [
'test_field' => [
'test_value' => 'test',
],
],
],
],
];
$this->assertEquals($expected, $results);
}
/**
* Tests if filters can be passed to the constructor.
*/
public function testFilterConstructor()
{
/** @var BuilderInterface|\PHPUnit_Framework_MockObject_MockObject $builderInterface1 */
$builderInterface1 = $this->getMockForAbstractClass('ONGR\ElasticsearchDSL\BuilderInterface');
/** @var BuilderInterface|\PHPUnit_Framework_MockObject_MockObject $builderInterface2 */
$builderInterface2 = $this->getMockForAbstractClass('ONGR\ElasticsearchDSL\BuilderInterface');
$aggregation = new AdjacencyMatrixAggregation(
'test',
[
'filter1' => $builderInterface1,
'filter2' => $builderInterface2,
]
);
$this->assertSame(
[
'adjacency_matrix' => [
'filters' => [
'filter1' => null,
'filter2' => null,
],
],
],
$aggregation->toArray()
);
$aggregation = new AdjacencyMatrixAggregation('test');
$this->assertSame(
[
'adjacency_matrix' => [
'filters' => [],
],
],
$aggregation->toArray()
);
}
}