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