1 | <?php |
||||
2 | |||||
3 | declare(strict_types=1); |
||||
4 | |||||
5 | namespace TheCodingMachine\TDBM; |
||||
6 | |||||
7 | use Doctrine\Common\Cache\ArrayCache; |
||||
8 | use Doctrine\Common\Cache\VoidCache; |
||||
9 | use PHPUnit\Framework\TestCase; |
||||
10 | |||||
11 | class OrderByAnalyzerTest extends TestCase |
||||
12 | { |
||||
13 | public function testAnalyzeOrderBy(): void |
||||
14 | { |
||||
15 | $analyzer = new OrderByAnalyzer(new VoidCache(), ''); |
||||
0 ignored issues
–
show
Deprecated Code
introduced
by
![]() |
|||||
16 | $results = $analyzer->analyzeOrderBy('`a`, b desc, rand() DESC, masc, mytable.mycol'); |
||||
17 | |||||
18 | $this->assertCount(5, $results); |
||||
19 | $this->assertEquals([ |
||||
20 | 'type' => 'colref', |
||||
21 | 'table' => null, |
||||
22 | 'column' => 'a', |
||||
23 | 'direction' => 'ASC', |
||||
24 | ], $results[0]); |
||||
25 | $this->assertEquals([ |
||||
26 | 'type' => 'colref', |
||||
27 | 'table' => null, |
||||
28 | 'column' => 'b', |
||||
29 | 'direction' => 'DESC', |
||||
30 | ], $results[1]); |
||||
31 | $this->assertEquals([ |
||||
32 | 'type' => 'expr', |
||||
33 | 'expr' => 'rand()', |
||||
34 | 'direction' => 'DESC', |
||||
35 | ], $results[2]); |
||||
36 | $this->assertEquals([ |
||||
37 | 'type' => 'colref', |
||||
38 | 'table' => null, |
||||
39 | 'column' => 'masc', |
||||
40 | 'direction' => 'ASC', |
||||
41 | ], $results[3]); |
||||
42 | $this->assertEquals([ |
||||
43 | 'type' => 'colref', |
||||
44 | 'table' => 'mytable', |
||||
45 | 'column' => 'mycol', |
||||
46 | 'direction' => 'ASC', |
||||
47 | ], $results[4]); |
||||
48 | } |
||||
49 | |||||
50 | public function testExprWithAsc(): void |
||||
51 | { |
||||
52 | $analyzer = new OrderByAnalyzer(new VoidCache(), ''); |
||||
0 ignored issues
–
show
The class
Doctrine\Common\Cache\VoidCache has been deprecated: Deprecated without replacement in doctrine/cache 1.11. This class will be dropped in 2.0
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||
53 | $results = $analyzer->analyzeOrderBy('foodesc + barasc'); |
||||
54 | |||||
55 | $this->assertCount(1, $results); |
||||
56 | $this->assertEquals([ |
||||
57 | 'type' => 'expr', |
||||
58 | 'expr' => 'foodesc + barasc', |
||||
59 | 'direction' => 'ASC', |
||||
60 | ], $results[0]); |
||||
61 | } |
||||
62 | |||||
63 | public function testCache(): void |
||||
64 | { |
||||
65 | $analyzer = new OrderByAnalyzer(new ArrayCache(), ''); |
||||
0 ignored issues
–
show
The class
Doctrine\Common\Cache\ArrayCache has been deprecated: Deprecated without replacement in doctrine/cache 1.11. This class will be dropped in 2.0
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||
66 | $results = $analyzer->analyzeOrderBy('foo'); |
||||
67 | $results2 = $analyzer->analyzeOrderBy('foo'); |
||||
68 | // For code coverage purpose |
||||
69 | $this->assertSame($results, $results2); |
||||
70 | } |
||||
71 | } |
||||
72 |