-
Notifications
You must be signed in to change notification settings - Fork 28
/
Copy pathOrderByAnalyzerTest.php
71 lines (63 loc) · 2.01 KB
/
OrderByAnalyzerTest.php
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
<?php
declare(strict_types=1);
namespace TheCodingMachine\TDBM;
use Doctrine\Common\Cache\ArrayCache;
use Doctrine\Common\Cache\VoidCache;
use PHPUnit\Framework\TestCase;
class OrderByAnalyzerTest extends TestCase
{
public function testAnalyzeOrderBy(): void
{
$analyzer = new OrderByAnalyzer(new VoidCache(), '');
$results = $analyzer->analyzeOrderBy('`a`, b desc, rand() DESC, masc, mytable.mycol');
$this->assertCount(5, $results);
$this->assertEquals([
'type' => 'colref',
'table' => null,
'column' => 'a',
'direction' => 'ASC',
], $results[0]);
$this->assertEquals([
'type' => 'colref',
'table' => null,
'column' => 'b',
'direction' => 'DESC',
], $results[1]);
$this->assertEquals([
'type' => 'expr',
'expr' => 'rand()',
'direction' => 'DESC',
], $results[2]);
$this->assertEquals([
'type' => 'colref',
'table' => null,
'column' => 'masc',
'direction' => 'ASC',
], $results[3]);
$this->assertEquals([
'type' => 'colref',
'table' => 'mytable',
'column' => 'mycol',
'direction' => 'ASC',
], $results[4]);
}
public function testExprWithAsc(): void
{
$analyzer = new OrderByAnalyzer(new VoidCache(), '');
$results = $analyzer->analyzeOrderBy('foodesc + barasc');
$this->assertCount(1, $results);
$this->assertEquals([
'type' => 'expr',
'expr' => 'foodesc + barasc',
'direction' => 'ASC',
], $results[0]);
}
public function testCache(): void
{
$analyzer = new OrderByAnalyzer(new ArrayCache(), '');
$results = $analyzer->analyzeOrderBy('foo');
$results2 = $analyzer->analyzeOrderBy('foo');
// For code coverage purpose
$this->assertSame($results, $results2);
}
}