1
|
|
|
<?php |
2
|
|
|
declare(strict_types = 1); |
3
|
|
|
|
4
|
|
|
namespace TBolier\RethinkQL\IntegrationTest\Aggregation; |
5
|
|
|
|
6
|
|
|
use TBolier\RethinkQL\IntegrationTest\Query\AbstractTableTest; |
7
|
|
|
use TBolier\RethinkQL\Response\ResponseInterface; |
8
|
|
|
|
9
|
|
|
class OrderByTest extends AbstractTableTest |
10
|
|
|
{ |
11
|
|
|
/** |
12
|
|
|
* @return void |
13
|
|
|
* @throws \Exception |
14
|
|
|
*/ |
15
|
|
|
public function testOrderByDesc(): void |
16
|
|
|
{ |
17
|
|
|
$this->insertDocument(5); |
18
|
|
|
$this->insertDocument(4); |
19
|
|
|
$this->insertDocument(3); |
20
|
|
|
$this->insertDocument(2); |
21
|
|
|
$this->insertDocument(1); |
22
|
|
|
|
23
|
|
|
/** @var ResponseInterface $res */ |
24
|
|
|
$res = $this->r() |
25
|
|
|
->table('tabletest') |
26
|
|
|
->orderBy($this->r()->desc('id')) |
27
|
|
|
->run(); |
28
|
|
|
|
29
|
|
|
$this->assertArraySubset(['id' => 5], $res->getData()[0]); |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* @return void |
34
|
|
|
* @throws \Exception |
35
|
|
|
*/ |
36
|
|
|
public function testOrderByAsc(): void |
37
|
|
|
{ |
38
|
|
|
$this->insertDocument(5); |
39
|
|
|
$this->insertDocument(4); |
40
|
|
|
$this->insertDocument(3); |
41
|
|
|
$this->insertDocument(2); |
42
|
|
|
$this->insertDocument(1); |
43
|
|
|
|
44
|
|
|
/** @var ResponseInterface $res */ |
45
|
|
|
$res = $this->r() |
46
|
|
|
->table('tabletest') |
47
|
|
|
->orderBy($this->r()->asc('id')) |
48
|
|
|
->run(); |
49
|
|
|
|
50
|
|
|
$this->assertArraySubset(['id' => 1], $res->getData()[0]); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* @return void |
55
|
|
|
* @throws \Exception |
56
|
|
|
*/ |
57
|
|
|
public function testFilterAndOrderByAsc(): void |
58
|
|
|
{ |
59
|
|
|
$this->insertDocument(5); |
60
|
|
|
$this->insertDocument(4); |
61
|
|
|
$this->insertDocument(3); |
62
|
|
|
$this->insertDocument(2); |
63
|
|
|
$this->insertDocument(1); |
64
|
|
|
|
65
|
|
|
/** @var ResponseInterface $res */ |
66
|
|
|
$res = $this->r() |
67
|
|
|
->table('tabletest') |
68
|
|
|
->filter(['description' => 'A document description.']) |
69
|
|
|
->orderBy($this->r()->asc('id')) |
70
|
|
|
->run(); |
71
|
|
|
|
72
|
|
|
$this->assertArraySubset(['id' => 1], $res->getData()[0]); |
73
|
|
|
} |
74
|
|
|
} |
75
|
|
|
|