1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
use PHPUnit\Framework\TestCase; |
4
|
|
|
use HexMakina\Crudites\Grammar\Deck; |
5
|
|
|
|
6
|
|
|
|
7
|
|
|
|
8
|
|
|
class DeckTest extends TestCase |
9
|
|
|
{ |
10
|
|
|
public function testConstructWithStringAggregate() |
11
|
|
|
{ |
12
|
|
|
$deck = new Deck('COUNT(*)'); |
13
|
|
|
$this->assertEquals('COUNT(*)', (string)$deck); |
14
|
|
|
} |
15
|
|
|
|
16
|
|
|
public function testConstructWithArrayAggregate() |
17
|
|
|
{ |
18
|
|
|
$deck = new Deck(['table', 'column']); |
19
|
|
|
$this->assertEquals('`table`.`column`', (string)$deck); |
20
|
|
|
} |
21
|
|
|
|
22
|
|
|
public function testConstructWithAlias() |
23
|
|
|
{ |
24
|
|
|
$deck = new Deck('COUNT(*)', 'total'); |
25
|
|
|
$this->assertEquals('COUNT(*) AS `total`', (string)$deck); |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
public function testAddAggregate() |
29
|
|
|
{ |
30
|
|
|
$deck = new Deck('COUNT(*)'); |
31
|
|
|
$deck->add('SUM(column)', 'sum_column'); |
32
|
|
|
$this->assertEquals('COUNT(*),SUM(column) AS `sum_column`', (string)$deck); |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
public function testAddRawAggregate() |
36
|
|
|
{ |
37
|
|
|
$deck = new Deck('COUNT(*)'); |
38
|
|
|
$deck->addRaw('SUM(column) AS `sum_column`'); |
39
|
|
|
$this->assertEquals('COUNT(*),SUM(column) AS `sum_column`', (string)$deck); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
public function testToString() |
43
|
|
|
{ |
44
|
|
|
$deck = new Deck('COUNT(*)'); |
45
|
|
|
$this->assertEquals('COUNT(*)', (string)$deck); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
public function testEmpty() |
49
|
|
|
{ |
50
|
|
|
$deck = new Deck(''); |
51
|
|
|
$this->assertTrue($deck->empty()); |
52
|
|
|
|
53
|
|
|
$deck = new Deck('COUNT(*)'); |
54
|
|
|
$this->assertFalse($deck->empty()); |
55
|
|
|
} |
56
|
|
|
} |