|
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\Tests\Integration\TestCase; |
|
19
|
|
|
|
|
20
|
|
|
final class SelectTest extends TestCase |
|
21
|
|
|
{ |
|
22
|
|
|
/** |
|
23
|
|
|
* @dataProvider provideSelectData |
|
24
|
|
|
* |
|
25
|
|
|
* @lua space = create_space('request_select') |
|
26
|
|
|
* @lua space:create_index('primary', {type = 'tree', unique = true, parts = {1, 'unsigned'}}) |
|
27
|
|
|
* @lua space:create_index('secondary', {type = 'tree', unique = false, parts = {2, 'unsigned', 3, 'str'}}) |
|
28
|
|
|
* @lua for i = 1, 100 do space:replace{i, i * 2 % 5, 'tuple_' .. i} end |
|
29
|
|
|
*/ |
|
30
|
|
|
public function testSelect(int $expectedCount, Criteria $criteria) : void |
|
31
|
|
|
{ |
|
32
|
|
|
$space = $this->client->getSpace('request_select'); |
|
|
|
|
|
|
33
|
|
|
$result = $space->select($criteria); |
|
34
|
|
|
|
|
35
|
|
|
self::assertCount($expectedCount, $result); |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
public function provideSelectData() : iterable |
|
39
|
|
|
{ |
|
40
|
|
|
return [ |
|
41
|
|
|
[100, Criteria::key([])], |
|
42
|
|
|
[20, Criteria::key([1])->andIndex('secondary')], |
|
43
|
|
|
[20, Criteria::key([2])->andIndex('secondary')], |
|
44
|
|
|
[20, Criteria::key([3])->andIndex('secondary')], |
|
45
|
|
|
[20, Criteria::key([4])->andIndex('secondary')], |
|
46
|
|
|
[20, Criteria::key([0])->andIndex('secondary')], |
|
47
|
|
|
[0, Criteria::key([3, 'tuple_95'])->andIndex('secondary')], |
|
48
|
|
|
[1, Criteria::key([3, 'tuple_94'])->andIndex('secondary')], |
|
49
|
|
|
[1, Criteria::key([1])], |
|
50
|
|
|
[10, Criteria::key([1])->andIndex('secondary')->andLimit(10)], |
|
51
|
|
|
[10, Criteria::key([1])->andIndex('secondary')->andLimit(11)->andOffset(10)], |
|
52
|
|
|
[9, Criteria::key([1])->andIndex('secondary')->andLimit(9)->andOffset(10)], |
|
53
|
|
|
[10, Criteria::key([1])->andIndex('secondary')->andLimit(10)->andOffset(10)], |
|
54
|
|
|
[20, Criteria::key([1])->andIndex('secondary')->andLimit(100500)->andReqIterator()], |
|
55
|
|
|
]; |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
/** |
|
59
|
|
|
* @lua create_space('request_select'):create_index('primary', {type = 'tree', parts = {1, 'unsigned'}}) |
|
60
|
|
|
*/ |
|
61
|
|
|
public function testSelectEmpty() : void |
|
62
|
|
|
{ |
|
63
|
|
|
$space = $this->client->getSpace('request_select'); |
|
64
|
|
|
|
|
65
|
|
|
self::assertEmpty($space->select(Criteria::key([]))); |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
/** |
|
69
|
|
|
* @lua create_space('request_select'):create_index('primary', {type = 'hash', parts = {1, 'unsigned'}}) |
|
70
|
|
|
*/ |
|
71
|
|
|
public function testSelectWithNonExistingIndexName() : void |
|
72
|
|
|
{ |
|
73
|
|
|
$space = $this->client->getSpace('request_select'); |
|
74
|
|
|
|
|
75
|
|
|
$this->expectException(RequestFailed::class); |
|
76
|
|
|
$this->expectExceptionMessage("No index 'non_existing_index' is defined in space #".$space->getId()); |
|
77
|
|
|
|
|
78
|
|
|
$space->select(Criteria::key([1])->andIndex('non_existing_index')); |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
/** |
|
82
|
|
|
* @lua create_space('request_select'):create_index('primary', {type = 'hash', parts = {1, 'unsigned'}}) |
|
83
|
|
|
*/ |
|
84
|
|
|
public function testSelectWithNonExistingIndexId() : void |
|
85
|
|
|
{ |
|
86
|
|
|
$space = $this->client->getSpace('request_select'); |
|
87
|
|
|
|
|
88
|
|
|
$this->expectException(RequestFailed::class); |
|
89
|
|
|
$this->expectExceptionMessage("No index #123456 is defined in space 'request_select'"); |
|
90
|
|
|
|
|
91
|
|
|
$space->select(Criteria::key([1])->andIndex(123456)); |
|
92
|
|
|
} |
|
93
|
|
|
} |
|
94
|
|
|
|
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.