Passed
Push — master ( 694425...cb2fe4 )
by Marc
03:56
created

OrderByTest::testOrderByAsc()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 15
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 15
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 10
nc 1
nop 0
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