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 InsertTest 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 testInsert() |
35
|
|
|
{ |
36
|
|
|
$res = $this->insertDocument(1); |
37
|
|
|
|
38
|
|
|
$this->assertObStatus(['inserted' => 1], $res->getData()); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* @throws \Exception |
43
|
|
|
*/ |
44
|
|
|
public function testMultipleInserts() |
45
|
|
|
{ |
46
|
|
|
$res = $this->r() |
47
|
|
|
->table('tabletest') |
48
|
|
|
->insert([ |
49
|
|
|
[ |
50
|
|
|
'documentId' => 1, |
51
|
|
|
'title' => 'Test document', |
52
|
|
|
'description' => 'My first document.', |
53
|
|
|
], |
54
|
|
|
[ |
55
|
|
|
'documentId' => 2, |
56
|
|
|
'title' => 'Test document', |
57
|
|
|
'description' => 'My first document.', |
58
|
|
|
], |
59
|
|
|
[ |
60
|
|
|
'documentId' => 3, |
61
|
|
|
'title' => 'Test document', |
62
|
|
|
'description' => 'My first document.', |
63
|
|
|
] |
64
|
|
|
]) |
65
|
|
|
->run(); |
66
|
|
|
|
67
|
|
|
$this->assertObStatus(['inserted' => 3], $res->getData()); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* @param int $documentId |
72
|
|
|
* @return ResponseInterface |
73
|
|
|
*/ |
74
|
|
|
private function insertDocument(int $documentId): ResponseInterface |
75
|
|
|
{ |
76
|
|
|
$res = $this->r() |
77
|
|
|
->table('tabletest') |
78
|
|
|
->insert([ |
79
|
|
|
[ |
80
|
|
|
'documentId' => $documentId, |
81
|
|
|
'title' => 'Test document', |
82
|
|
|
'description' => 'My first document.', |
83
|
|
|
], |
84
|
|
|
]) |
85
|
|
|
->run(); |
86
|
|
|
|
87
|
|
|
return $res; |
|
|
|
|
88
|
|
|
} |
89
|
|
|
} |
90
|
|
|
|