|
1
|
|
|
<?php |
|
2
|
|
|
declare(strict_types = 1); |
|
3
|
|
|
|
|
4
|
|
|
namespace TBolier\RethinkQL\IntegrationTest\Operation; |
|
5
|
|
|
|
|
6
|
|
|
use TBolier\RethinkQL\Response\Cursor; |
|
7
|
|
|
use TBolier\RethinkQL\Response\ResponseInterface; |
|
8
|
|
|
|
|
9
|
|
|
class CursorTest extends AbstractTableTest |
|
10
|
|
|
{ |
|
11
|
|
|
public function setUp() |
|
12
|
|
|
{ |
|
13
|
|
|
parent::setUp(); |
|
14
|
|
|
|
|
15
|
|
|
$res = $this->r()->db()->tableList()->run(); |
|
16
|
|
|
if (\is_array($res->getData()) && !\in_array('tabletest_big', $res->getData(), true)) { |
|
|
|
|
|
|
17
|
|
|
$this->r()->db()->tableCreate('tabletest_big')->run(); |
|
18
|
|
|
} |
|
19
|
|
|
} |
|
20
|
|
|
|
|
21
|
|
|
public function tearDown() |
|
22
|
|
|
{ |
|
23
|
|
|
parent::tearDown(); |
|
24
|
|
|
|
|
25
|
|
|
$res = $this->r()->db()->tableList()->run(); |
|
26
|
|
|
if (\is_array($res->getData()) && \in_array('tabletest_big', $res->getData(), true)) { |
|
27
|
|
|
$this->r()->db()->tableDrop('tabletest_big')->run(); |
|
28
|
|
|
} |
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* @throws \Exception |
|
33
|
|
|
*/ |
|
34
|
|
|
public function testCursor() |
|
35
|
|
|
{ |
|
36
|
|
|
$this->insertDocuments(); |
|
37
|
|
|
|
|
38
|
|
|
$response = $this->r() |
|
39
|
|
|
->table('tabletest') |
|
40
|
|
|
->count() |
|
41
|
|
|
->run(); |
|
42
|
|
|
|
|
43
|
|
|
$this->assertEquals(1000, $response->getData()); |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* @throws \Exception |
|
48
|
|
|
*/ |
|
49
|
|
|
public function testCursorBigDocuments() |
|
50
|
|
|
{ |
|
51
|
|
|
$data = [ |
|
52
|
|
|
'Professor X' => 'Charles Francis Xavier', |
|
53
|
|
|
'Cyclops' => 'Scott Summers', |
|
54
|
|
|
'Iceman' => 'Robert Louis "Bobby" Drake', |
|
55
|
|
|
'Angel' => 'Warren Kenneth Worthington III', |
|
56
|
|
|
'Beast' => 'Henry Philip "Hank" McCoy', |
|
57
|
|
|
'Marvel Girl/Phoenix' => 'Jean Elaine Grey/Jean Elaine Grey-Summers', |
|
58
|
|
|
'Magnetrix/Polaris' => 'Lorna Sally Dane', |
|
59
|
|
|
'Nightcrawler' => 'Kurt Wagner', |
|
60
|
|
|
'Wolverine' => 'James "Logan" Howlett', |
|
61
|
|
|
'Storm' => 'Ororo Monroe', |
|
62
|
|
|
'Colossus' => 'Piotr Nikolaievitch "Peter" Rasputin', |
|
63
|
|
|
'Sprite/Ariel/Shadowcat' => 'Katherine Anne "Kitty" Pryde', |
|
64
|
|
|
'Rogue' => 'Anna Marie', |
|
65
|
|
|
'Phoenix/Marvel Girl/Prestige' => 'Rachel Anne Grey-Summers', |
|
66
|
|
|
'Psylocke' => 'Elizabeth "Betsy" Braddock', |
|
67
|
|
|
'Gambit' => 'Rémy Etienne LeBeau', |
|
68
|
|
|
'Jubilee' => 'Jubilation Lee', |
|
69
|
|
|
'Bishop' => 'Lucas Bishop', |
|
70
|
|
|
]; |
|
71
|
|
|
|
|
72
|
|
|
$this->insertBigDocuments($data); |
|
73
|
|
|
|
|
74
|
|
|
$cursor = $this->r()->table('tabletest_big')->run(); |
|
75
|
|
|
|
|
76
|
|
|
$i = 0; |
|
77
|
|
|
foreach ($cursor as $document) { |
|
78
|
|
|
// Assert the document every 1000s documents. |
|
79
|
|
|
if ($i % 1000 === 0) { |
|
80
|
|
|
$this->assertArraySubset($data, $document); |
|
81
|
|
|
} |
|
82
|
|
|
$i++; |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
$this->assertEquals($i, $this->r()->table('tabletest_big')->count()->run()->getData()); |
|
86
|
|
|
|
|
87
|
|
|
$this->assertInstanceOf(Cursor::class, $cursor); |
|
88
|
|
|
|
|
89
|
|
|
$this->r()->table('tabletest_big')->delete()->run(); |
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
|
|
/** |
|
93
|
|
|
* @return ResponseInterface |
|
94
|
|
|
* @throws \Exception |
|
95
|
|
|
*/ |
|
96
|
|
|
private function insertDocuments(): ResponseInterface |
|
97
|
|
|
{ |
|
98
|
|
|
$documents = []; |
|
99
|
|
|
for ($i = 1; $i <= 1000; $i++) { |
|
100
|
|
|
$documents[] = [ |
|
101
|
|
|
'id' => $i, |
|
102
|
|
|
'title' => 'Test document', |
|
103
|
|
|
'description' => 'My first document.', |
|
104
|
|
|
]; |
|
105
|
|
|
} |
|
106
|
|
|
|
|
107
|
|
|
/** @var ResponseInterface $res */ |
|
108
|
|
|
$res = $this->r() |
|
109
|
|
|
->table('tabletest') |
|
110
|
|
|
->insert($documents) |
|
111
|
|
|
->run(); |
|
112
|
|
|
|
|
113
|
|
|
$this->assertEquals(1000, $res->getData()['inserted']); |
|
114
|
|
|
|
|
115
|
|
|
return $res; |
|
116
|
|
|
} |
|
117
|
|
|
|
|
118
|
|
|
/** |
|
119
|
|
|
* @param array $data |
|
120
|
|
|
* @return ResponseInterface |
|
121
|
|
|
* @throws \Exception |
|
122
|
|
|
*/ |
|
123
|
|
|
private function insertBigDocuments(array $data): ResponseInterface |
|
124
|
|
|
{ |
|
125
|
|
|
$documents = []; |
|
126
|
|
|
for ($i = 1; $i <= 100; $i++) { |
|
127
|
|
|
$documents = []; |
|
128
|
|
|
|
|
129
|
|
|
for ($x = 1; $x <= 100; $x++) { |
|
130
|
|
|
$documents[] = $data; |
|
131
|
|
|
} |
|
132
|
|
|
} |
|
133
|
|
|
|
|
134
|
|
|
/** @var ResponseInterface $res */ |
|
135
|
|
|
$res = $this->r() |
|
136
|
|
|
->table('tabletest_big') |
|
137
|
|
|
->insert($documents) |
|
138
|
|
|
->run(); |
|
139
|
|
|
|
|
140
|
|
|
$this->assertEquals(100, $res->getData()['inserted']); |
|
141
|
|
|
|
|
142
|
|
|
return $res; |
|
143
|
|
|
} |
|
144
|
|
|
} |
|
145
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.