1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
use PHPUnit\Framework\TestCase; |
4
|
|
|
use HexMakina\Crudites\Grammar\Clause\GroupBy; |
5
|
|
|
|
6
|
|
|
class GroupByTest extends TestCase |
7
|
|
|
{ |
8
|
|
|
public function testName() |
9
|
|
|
{ |
10
|
|
|
$selected = 'column1'; |
11
|
|
|
$groupBy = new GroupBy($selected); |
12
|
|
|
$this->assertEquals(GroupBy::GROUP, $groupBy->name()); |
13
|
|
|
} |
14
|
|
|
|
15
|
|
|
public function testConstructString() |
16
|
|
|
{ |
17
|
|
|
$selected = 'column1'; |
18
|
|
|
$groupBy = new GroupBy($selected); |
19
|
|
|
$this->assertEquals('GROUP BY column1', (string)$groupBy); |
20
|
|
|
} |
21
|
|
|
|
22
|
|
|
public function testConstructArray() |
23
|
|
|
{ |
24
|
|
|
$selected = ['table', 'column']; |
25
|
|
|
$groupBy = new GroupBy($selected); |
26
|
|
|
$this->assertEquals('GROUP BY `table`.`column`', (string)$groupBy); |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
public function testAddString() |
30
|
|
|
{ |
31
|
|
|
$selected = 'column1'; |
32
|
|
|
$groupBy = new GroupBy($selected); |
33
|
|
|
$groupBy->add('column2'); |
34
|
|
|
$this->assertEquals('GROUP BY column1,column2', (string)$groupBy); |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
public function testAddArray() |
38
|
|
|
{ |
39
|
|
|
$selected = ['table', 'column']; |
40
|
|
|
$groupBy = new GroupBy($selected); |
41
|
|
|
$groupBy->add(['table', 'column2']); |
42
|
|
|
$this->assertEquals('GROUP BY `table`.`column`,`table`.`column2`', (string)$groupBy); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
public function testStringAddArray() |
46
|
|
|
{ |
47
|
|
|
$selected = 'column'; |
48
|
|
|
$groupBy = new GroupBy($selected); |
49
|
|
|
$groupBy->add(['table', 'column2']); |
50
|
|
|
$this->assertEquals('GROUP BY column,`table`.`column2`', (string)$groupBy); |
51
|
|
|
} |
52
|
|
|
} |
53
|
|
|
|