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 CountTest extends AbstractTableTest |
10
|
|
|
{ |
11
|
|
|
/** |
12
|
|
|
* @throws \Exception |
13
|
|
|
*/ |
14
|
|
|
public function testCount() |
15
|
|
|
{ |
16
|
|
|
$this->insertDocument(1); |
17
|
|
|
|
18
|
|
|
$res = $this->r() |
19
|
|
|
->table('tabletest') |
20
|
|
|
->count() |
21
|
|
|
->run(); |
22
|
|
|
|
23
|
|
|
$this->assertInternalType('int', $res->getData()); |
24
|
|
|
} |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* @throws \Exception |
28
|
|
|
*/ |
29
|
|
|
public function testGetAllAndCount() |
30
|
|
|
{ |
31
|
|
|
$this->insertDocument(1); |
32
|
|
|
$this->insertDocument(2); |
33
|
|
|
$this->insertDocument(3); |
34
|
|
|
$this->insertDocument(4); |
35
|
|
|
$this->insertDocument(5); |
36
|
|
|
|
37
|
|
|
/** @var ResponseInterface $res */ |
38
|
|
|
$res = $this->r() |
39
|
|
|
->table('tabletest') |
40
|
|
|
->getAll(1, 2, 3, 4, 5) |
41
|
|
|
->count() |
42
|
|
|
->run(); |
43
|
|
|
|
44
|
|
|
$this->assertEquals(5, $res->getData()); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* @throws \Exception |
49
|
|
|
*/ |
50
|
|
|
public function testFilterAndCount() |
51
|
|
|
{ |
52
|
|
|
$this->insertDocument(1); |
53
|
|
|
$this->insertDocument(2); |
54
|
|
|
$this->insertDocument(3); |
55
|
|
|
$this->insertDocument(4); |
56
|
|
|
$this->insertDocument(5); |
57
|
|
|
|
58
|
|
|
/** @var ResponseInterface $res */ |
59
|
|
|
$res = $this->r() |
60
|
|
|
->table('tabletest') |
61
|
|
|
->filter(['id' => 1]) |
62
|
|
|
->count() |
63
|
|
|
->run(); |
64
|
|
|
|
65
|
|
|
$this->assertEquals(1, $res->getData()); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* @throws \Exception |
70
|
|
|
*/ |
71
|
|
|
public function testFilterAndCountMultiple() |
72
|
|
|
{ |
73
|
|
|
$this->insertDocument(1); |
74
|
|
|
$this->insertDocument(2); |
75
|
|
|
$this->insertDocument(3); |
76
|
|
|
$this->insertDocument(4); |
77
|
|
|
$this->insertDocument(5); |
78
|
|
|
|
79
|
|
|
/** @var ResponseInterface $res */ |
80
|
|
|
$res = $this->r() |
81
|
|
|
->table('tabletest') |
82
|
|
|
->filter(['description' => 'A document description.']) |
83
|
|
|
->count() |
84
|
|
|
->run(); |
85
|
|
|
|
86
|
|
|
$this->assertEquals(5, $res->getData()); |
87
|
|
|
} |
88
|
|
|
} |
89
|
|
|
|