|
1
|
|
|
<?php |
|
2
|
|
|
declare(strict_types=1); |
|
3
|
|
|
|
|
4
|
|
|
namespace TBolier\RethinkConnect\Test\Connection; |
|
5
|
|
|
|
|
6
|
|
|
use ArrayObject; |
|
7
|
|
|
use TBolier\RethinkQL\Response\Cursor; |
|
8
|
|
|
use TBolier\RethinkQL\Response\ResponseInterface; |
|
9
|
|
|
use TBolier\RethinkQL\IntegrationTest\BaseTestCase; |
|
10
|
|
|
|
|
11
|
|
|
class CountTest extends BaseTestCase |
|
12
|
|
|
{ |
|
13
|
|
|
public function setUp() |
|
14
|
|
|
{ |
|
15
|
|
|
parent::setUp(); |
|
16
|
|
|
|
|
17
|
|
|
if (!\in_array('tabletest', $this->r()->db()->tableList()->run()->getData(), true)) { |
|
|
|
|
|
|
18
|
|
|
$this->r()->db()->tableCreate('tabletest')->run(); |
|
19
|
|
|
} |
|
20
|
|
|
} |
|
21
|
|
|
|
|
22
|
|
|
public function tearDown() |
|
23
|
|
|
{ |
|
24
|
|
|
if (\in_array('tabletest', $this->r()->db()->tableList()->run()->getData(), true)) { |
|
|
|
|
|
|
25
|
|
|
$this->r()->db()->tableDrop('tabletest')->run(); |
|
26
|
|
|
} |
|
27
|
|
|
|
|
28
|
|
|
parent::tearDown(); |
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* @throws \Exception |
|
33
|
|
|
*/ |
|
34
|
|
|
public function testCount() |
|
35
|
|
|
{ |
|
36
|
|
|
$this->insertDocument(1); |
|
37
|
|
|
|
|
38
|
|
|
$res = $this->r() |
|
39
|
|
|
->table('tabletest') |
|
40
|
|
|
->count() |
|
41
|
|
|
->run(); |
|
42
|
|
|
|
|
43
|
|
|
$this->assertInternalType('int', $res->getData()); |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* @throws \Exception |
|
48
|
|
|
*/ |
|
49
|
|
|
public function testFilterCount() |
|
50
|
|
|
{ |
|
51
|
|
|
$this->insertDocument(1); |
|
52
|
|
|
$this->insertDocument(2); |
|
53
|
|
|
$this->insertDocument(3); |
|
54
|
|
|
$this->insertDocument(4); |
|
55
|
|
|
$this->insertDocument(5); |
|
56
|
|
|
|
|
57
|
|
|
/** @var ResponseInterface $res */ |
|
58
|
|
|
$res = $this->r() |
|
59
|
|
|
->table('tabletest') |
|
60
|
|
|
->filter([ |
|
61
|
|
|
[ |
|
62
|
|
|
'title' => 'Test document', |
|
63
|
|
|
], |
|
64
|
|
|
]) |
|
65
|
|
|
->count() |
|
66
|
|
|
->run(); |
|
67
|
|
|
|
|
68
|
|
|
$this->assertEquals(5, $res->getData()); |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
/** |
|
72
|
|
|
* @param int $documentId |
|
73
|
|
|
* @return ResponseInterface |
|
74
|
|
|
*/ |
|
75
|
|
|
private function insertDocument(int $documentId): ResponseInterface |
|
76
|
|
|
{ |
|
77
|
|
|
$res = $this->r() |
|
78
|
|
|
->table('tabletest') |
|
79
|
|
|
->insert([ |
|
80
|
|
|
[ |
|
81
|
|
|
'documentId' => $documentId, |
|
82
|
|
|
'title' => 'Test document', |
|
83
|
|
|
'description' => 'My first document.', |
|
84
|
|
|
], |
|
85
|
|
|
]) |
|
86
|
|
|
->run(); |
|
87
|
|
|
|
|
88
|
|
|
return $res; |
|
|
|
|
|
|
89
|
|
|
} |
|
90
|
|
|
} |
|
91
|
|
|
|