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\Tests\Integration\TestCase; |
||
18 | |||
19 | final class InsertTest extends TestCase |
||
20 | { |
||
21 | /** |
||
22 | * @dataProvider provideInsertData |
||
23 | * |
||
24 | * @lua create_space('request_insert_str'):create_index('primary', {type = 'hash', parts = {1, 'str'}}) |
||
25 | * @lua create_space('request_insert_num'):create_index('primary', {type = 'hash', parts = {1, 'unsigned'}}) |
||
26 | */ |
||
27 | public function testInsert(string $spaceName, array $values) : void |
||
28 | { |
||
29 | $space = $this->client->getSpace($spaceName); |
||
0 ignored issues
–
show
|
|||
30 | $result = $space->insert($values); |
||
31 | |||
32 | self::assertSame([$values], $result); |
||
33 | } |
||
34 | |||
35 | public function provideInsertData() : iterable |
||
36 | { |
||
37 | return [ |
||
38 | ['request_insert_str', ['']], |
||
39 | ['request_insert_str', ['foo']], |
||
40 | ['request_insert_str', ['null', null, null]], |
||
41 | ['request_insert_str', ['int', 42, -42]], |
||
42 | ['request_insert_str', ['float', 4.2, -4.2]], |
||
43 | ['request_insert_str', ['array', ['foo' => 'bar']]], |
||
44 | ['request_insert_num', [42]], |
||
45 | ]; |
||
46 | } |
||
47 | |||
48 | /** |
||
49 | * @dataProvider provideInsertDataWithMismatchedTypes |
||
50 | * |
||
51 | * @lua create_space('request_insert_str'):create_index('primary', {type = 'hash', parts = {1, 'str'}}) |
||
52 | * @lua create_space('request_insert_num'):create_index('primary', {type = 'hash', parts = {1, 'unsigned'}}) |
||
53 | */ |
||
54 | public function testInsertTypeMismatchedValues(string $spaceName, array $values) : void |
||
55 | { |
||
56 | $space = $this->client->getSpace($spaceName); |
||
57 | |||
58 | $this->expectException(RequestFailed::class); |
||
59 | $this->expectExceptionCode(23); // ER_FIELD_TYPE |
||
60 | |||
61 | $space->insert($values); |
||
62 | } |
||
63 | |||
64 | public function provideInsertDataWithMismatchedTypes() : iterable |
||
65 | { |
||
66 | return [ |
||
67 | ['request_insert_str', [null]], |
||
68 | ['request_insert_str', [42]], |
||
69 | ['request_insert_str', [[]]], |
||
70 | ['request_insert_num', [null]], |
||
71 | ['request_insert_num', [-42]], |
||
72 | ['request_insert_num', [4.2]], |
||
73 | ['request_insert_num', [[]]], |
||
74 | ]; |
||
75 | } |
||
76 | |||
77 | /** |
||
78 | * @lua space = create_space('request_insert_dup_key') |
||
79 | * @lua space:create_index('primary', {type = 'hash', parts = {1, 'unsigned'}}) |
||
80 | * @lua space:insert{1, 'foobar'} |
||
81 | */ |
||
82 | public function testInsertDuplicateKey() : void |
||
83 | { |
||
84 | $space = $this->client->getSpace('request_insert_dup_key'); |
||
85 | |||
86 | $this->expectException(RequestFailed::class); |
||
87 | $this->expectExceptionMessageMatches('/^Duplicate key exists in unique index ("|\')primary\1 in space ("|\')request_insert_dup_key\2/'); |
||
88 | |||
89 | $space->insert([1, 'bazqux']); |
||
90 | } |
||
91 | |||
92 | /** |
||
93 | * @lua space = create_space('request_insert_empty_tuple') |
||
94 | * @lua space:create_index('primary', {type = 'hash', parts = {1, 'unsigned'}}) |
||
95 | */ |
||
96 | public function testInsertEmptyTuple() : void |
||
97 | { |
||
98 | $space = $this->client->getSpace('request_insert_empty_tuple'); |
||
99 | |||
100 | $this->expectException(RequestFailed::class); |
||
101 | $this->expectExceptionCode(39); // ER_FIELD_MISSING |
||
102 | |||
103 | $space->insert([]); |
||
104 | } |
||
105 | } |
||
106 |
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.