|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* This file is part of the tarantool/client package. |
|
5
|
|
|
* |
|
6
|
|
|
* (c) Eugene Leonovich <[email protected]> |
|
7
|
|
|
* |
|
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
9
|
|
|
* file that was distributed with this source code. |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
declare(strict_types=1); |
|
13
|
|
|
|
|
14
|
|
|
namespace Tarantool\Client\Tests\Integration\Requests; |
|
15
|
|
|
|
|
16
|
|
|
use Tarantool\Client\Exception\RequestFailed; |
|
17
|
|
|
use Tarantool\Client\Schema\Criteria; |
|
18
|
|
|
use Tarantool\Client\Schema\Operations; |
|
19
|
|
|
use Tarantool\Client\Tests\Integration\TestCase; |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* @lua space = create_space('request_update') |
|
23
|
|
|
* @lua space:create_index('primary', {type = 'tree', unique = true, parts = {1, 'unsigned'}}) |
|
24
|
|
|
* @lua space:create_index('secondary', {type = 'tree', unique = false, parts = {2, 'unsigned', 3, 'str'}}) |
|
25
|
|
|
* @lua space:replace{1, 2, 'tuple_1'} |
|
26
|
|
|
* @lua space:replace{2, 4, 'tuple_2'} |
|
27
|
|
|
*/ |
|
28
|
|
|
final class UpdateTest extends TestCase |
|
29
|
|
|
{ |
|
30
|
|
|
/** |
|
31
|
|
|
* @dataProvider provideUpdateData |
|
32
|
|
|
*/ |
|
33
|
|
|
public function testUpdate(Operations $operations, array $expectedResult) : void |
|
34
|
|
|
{ |
|
35
|
|
|
$space = $this->client->getSpace('request_update'); |
|
|
|
|
|
|
36
|
|
|
$result = $space->update([1], $operations); |
|
37
|
|
|
|
|
38
|
|
|
self::assertSame($expectedResult, $result); |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
public function provideUpdateData() : iterable |
|
42
|
|
|
{ |
|
43
|
|
|
return [ |
|
44
|
|
|
[ |
|
45
|
|
|
Operations::add(1, 16)->andSet(3, 98)->andSet(4, 0x11111), |
|
46
|
|
|
[[1, 18, 'tuple_1', 98, 0x11111]], |
|
47
|
|
|
], |
|
48
|
|
|
[ |
|
49
|
|
|
Operations::subtract(3, 10)->andBitwiseAnd(4, 0x10101), |
|
50
|
|
|
[[1, 18, 'tuple_1', 88, 0x10101]], |
|
51
|
|
|
], |
|
52
|
|
|
[ |
|
53
|
|
|
Operations::bitwiseXor(4, 0x11100), |
|
54
|
|
|
[[1, 18, 'tuple_1', 88, 0x01001]], |
|
55
|
|
|
], |
|
56
|
|
|
[ |
|
57
|
|
|
Operations::splice(2, 2, 1, 'uup'), |
|
58
|
|
|
[[1, 18, 'tuuuple_1', 88, 0x01001]], |
|
59
|
|
|
], |
|
60
|
|
|
]; |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
public function testUpdateWithIndexName() : void |
|
64
|
|
|
{ |
|
65
|
|
|
$space = $this->client->getSpace('request_update'); |
|
66
|
|
|
|
|
67
|
|
|
self::assertSame([2, 4, 'tuple_2'], $space->select(Criteria::key([2]))[0]); |
|
68
|
|
|
|
|
69
|
|
|
$result = $space->update([2], Operations::splice(2, 0, 1, 'T'), 'primary'); |
|
70
|
|
|
|
|
71
|
|
|
self::assertSame([[2, 4, 'Tuple_2']], $result); |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
public function testUpdateWithNonExistingIndexName() : void |
|
75
|
|
|
{ |
|
76
|
|
|
$space = $this->client->getSpace('request_update'); |
|
77
|
|
|
|
|
78
|
|
|
$this->expectException(RequestFailed::class); |
|
79
|
|
|
$this->expectExceptionMessage("No index 'non_existing_index' is defined in space #".$space->getId()); |
|
80
|
|
|
|
|
81
|
|
|
$space->update([2], Operations::splice(2, 0, 1, 'T'), 'non_existing_index'); |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
public function testUpdateByNonExistingKey() : void |
|
85
|
|
|
{ |
|
86
|
|
|
$space = $this->client->getSpace('request_update'); |
|
87
|
|
|
$result = $space->update([42], Operations::set(2, 'qux')); |
|
88
|
|
|
|
|
89
|
|
|
self::assertSame([], $result); |
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
|
|
public function testUpdateByEmptyKey() : void |
|
93
|
|
|
{ |
|
94
|
|
|
$space = $this->client->getSpace('request_update'); |
|
95
|
|
|
|
|
96
|
|
|
$this->expectException(RequestFailed::class); |
|
97
|
|
|
$this->expectExceptionCode(19); // ER_EXACT_MATCH |
|
98
|
|
|
|
|
99
|
|
|
$space->update([], Operations::set(2, 'qux')); |
|
100
|
|
|
} |
|
101
|
|
|
} |
|
102
|
|
|
|
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.