Passed
Pull Request — master (#197)
by
unknown
01:33
created

FacetTest::testFacet()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 37
Code Lines 25

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 25
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 37
rs 9.52
1
<?php
2
namespace Foolz\SphinxQL\Tests;
3
4
use Foolz\SphinxQL\Exception\SphinxQLException;
5
use Foolz\SphinxQL\Facet;
6
7
use PHPUnit\Framework\TestCase;
8
9
class FacetTest extends TestCase{
10
11
//	public static $DATA = [
12
//		0 => [
13
//			'id'		=> '10',
14
//			'gid'		=> '9003',
15
//			'title'		=> 'modifying the same line again',
16
//			'content'	=> 'because i am that lazy',
17
//		],
18
//		1 => [
19
//			'id'		=> '11',
20
//			'gid'		=> '201',
21
//			'title'		=> 'replacing value by value',
22
//			'content'	=> 'i have no idea who would use this directly',
23
//		],
24
//		2 => [
25
//			'id'		=> '12',
26
//			'gid'		=> '200',
27
//			'title'		=> 'simple logic',
28
//			'content'	=> 'inside the box there was the content',
29
//		],
30
//		3 => [
31
//			'id'		=> '13',
32
//			'gid'		=> '304',
33
//			'title'		=> 'i am getting bored',
34
//			'content'	=> 'with all this CONTENT',
35
//		],
36
//		4 => [
37
//			'id'		=> '14',
38
//			'gid'		=> '304',
39
//			'title'		=> 'i want a vacation',
40
//			'content'	=> 'the code is going to break sometime',
41
//		],
42
//		5 => [
43
//			'id'		=> '15',
44
//			'gid'		=> '304',
45
//			'title'		=> 'there\'s no hope in this class',
46
//			'content'	=> 'just give up',
47
//		],
48
//		6 => [
49
//			'id'		=> '16',
50
//			'gid'		=> '500',
51
//			'title'		=> 'we need to test',
52
//			'content'	=> 'selecting the best result in groups',
53
//		],
54
//		7 => [
55
//			'id'		=> '17',
56
//			'gid'		=> '500',
57
//			'title'		=> 'what is there to do',
58
//			'content'	=> 'we need to create dummy data for tests',
59
//		],
60
//	];
61
62
	/**
63
	 * @return Facet
64
	 */
65
	protected function createFacet(): Facet
66
	{
67
		return new Facet(null);
68
	}
69
70
	/**
71
	 * @throws SphinxQLException
72
	 */
73
	public function testFacet(): void{
74
		$facet = $this->createFacet()
75
			->facet(['gid'])
76
			->getFacet();
77
78
		$this->assertEquals('FACET gid', $facet);
79
80
		$facet = $this->createFacet()
81
			->facet(['gid', 'title', 'content'])
82
			->getFacet();
83
84
		$this->assertEquals('FACET gid, title, content', $facet);
85
86
		$facet = $this->createFacet()
87
			->facet('gid', 'title', 'content')
88
			->getFacet();
89
90
		$this->assertEquals('FACET gid, title, content', $facet);
91
92
		$facet = $this->createFacet()
93
			->facet(['aliAS' => 'gid'])
94
			->getFacet();
95
96
		$this->assertEquals('FACET gid AS aliAS', $facet);
97
98
		$facet = $this->createFacet()
99
			->facet(['gid', 'name' => 'title', 'content'])
100
			->getFacet();
101
102
		$this->assertEquals('FACET gid, title AS name, content', $facet);
103
104
		$facet = new Facet();
105
		$facet = $facet
106
			->facet('gid', ['name' => 'title'], 'content')
107
			->getFacet();
108
109
		$this->assertEquals('FACET gid, title AS name, content', $facet);
110
	}
111
112
	/**
113
	 * @throws SphinxQLException
114
	 */
115
	public function testFacetFunction(): void
116
	{
117
		$facet = $this->createFacet()
118
			->facetFunction('INTERVAL',['price', 200, 400, 600, 800])
119
			->getFacet();
120
121
		$this->assertEquals('FACET INTERVAL(price,200,400,600,800)', $facet);
122
123
		$facet = $this->createFacet()
124
			->facetFunction('COUNT', 'gid')
125
			->getFacet();
126
127
		$this->assertEquals('FACET COUNT(gid)', $facet);
128
	}
129
130
	/**
131
	 * @throws SphinxQLException
132
	 */
133
	public function testBy(): void
134
	{
135
		$facet = $this->createFacet()
136
			->facet(['gid', 'title', 'content'])
137
			->by('gid')
138
			->getFacet();
139
140
		$this->assertEquals('FACET gid, title, content BY gid', $facet);
141
	}
142
143
	/**
144
	 * @throws SphinxQLException
145
	 */
146
	public function testOrderBy(): void
147
	{
148
		$facet = $this->createFacet()
149
			->facet(['gid', 'title'])
150
			->orderBy('gid', 'DESC')
151
			->getFacet();
152
153
		$this->assertEquals('FACET gid, title ORDER BY gid DESC', $facet);
154
155
		$facet = $this->createFacet()
156
			->facet(['gid', 'content'])
157
			->orderBy('gid', 'ASC')
158
			->orderBy('content', 'DESC')
159
			->getFacet();
160
161
		$this->assertEquals('FACET gid, content ORDER BY gid ASC, content DESC', $facet);
162
	}
163
164
	/**
165
	 * @throws SphinxQLException
166
	 */
167
	public function testOrderByFunction(): void
168
	{
169
		$facet = $this->createFacet()
170
			->facet(['gid', 'title'])
171
			->orderByFunction('COUNT', '*', 'DESC')
172
			->getFacet();
173
174
		$this->assertEquals('FACET gid, title ORDER BY COUNT(*) DESC', $facet);
175
	}
176
177
	/**
178
	 * @throws SphinxQLException
179
	 */
180
	public function testLimit(): void
181
	{
182
		$facet = $this->createFacet()
183
			->facet(['gid', 'title'])
184
			->orderByFunction('COUNT', '*', 'DESC')
185
			->limit(5, 5)
186
			->getFacet();
187
188
		$this->assertEquals('FACET gid, title ORDER BY COUNT(*) DESC LIMIT 5, 5', $facet);
189
	}
190
191
}