|
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\Tests\Integration\TestCase; |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* @requires Tarantool 2 |
|
20
|
|
|
*/ |
|
21
|
|
|
final class ExecuteTest extends TestCase |
|
22
|
|
|
{ |
|
23
|
|
|
/** |
|
24
|
|
|
* @dataProvider provideExecuteUpdateData |
|
25
|
|
|
*/ |
|
26
|
|
|
public function testExecuteUpdate(string $sql, array $params, $expectedCount, ?array $expectedAutoincrementIds) : void |
|
27
|
|
|
{ |
|
28
|
|
|
$result = $this->client->executeUpdate($sql, ...$params); |
|
29
|
|
|
|
|
30
|
|
|
is_array($expectedCount) |
|
31
|
|
|
? self::assertContains($result->count(), $expectedCount) |
|
32
|
|
|
: self::assertSame($expectedCount, $result->count()) |
|
33
|
|
|
; |
|
34
|
|
|
|
|
35
|
|
|
self::assertSame($expectedAutoincrementIds, $result->getAutoincrementIds()); |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
public function provideExecuteUpdateData() : iterable |
|
39
|
|
|
{ |
|
40
|
|
|
return [ |
|
41
|
|
|
['DROP TABLE IF EXISTS table_exec', [], [0, 1], null], |
|
42
|
|
|
['CREATE TABLE table_exec (column1 INTEGER PRIMARY KEY AUTOINCREMENT, column2 VARCHAR(100))', [], 1, null], |
|
43
|
|
|
['INSERT INTO table_exec VALUES (1, :val1), (2, :val2)', [[':val1' => 'A'], [':val2' => 'B']], 2, null], |
|
44
|
|
|
['UPDATE table_exec SET column2 = ? WHERE column1 = 2', ['BB'], 1, null], |
|
45
|
|
|
["INSERT INTO table_exec VALUES (100, 'a'), (null, 'b'), (120, 'c'), (null, 'd')", [], 4, [101, 121]], |
|
46
|
|
|
]; |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
/** |
|
50
|
|
|
* @dataProvider provideExecuteQueryData |
|
51
|
|
|
* |
|
52
|
|
|
* @depends testExecuteUpdate |
|
53
|
|
|
*/ |
|
54
|
|
|
public function testExecuteQuery(string $sql, array $params, array $expectedData) : void |
|
55
|
|
|
{ |
|
56
|
|
|
$result = $this->client->executeQuery($sql, ...$params); |
|
57
|
|
|
|
|
58
|
|
|
self::assertSame($expectedData, $result->getData()); |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
public function provideExecuteQueryData() : iterable |
|
62
|
|
|
{ |
|
63
|
|
|
return [ |
|
64
|
|
|
['SELECT * FROM table_exec WHERE column1 = 1', [], [[1, 'A']]], |
|
65
|
|
|
['SELECT column2 FROM table_exec WHERE column1 = 1', [], [['A']]], |
|
66
|
|
|
['SELECT * FROM table_exec WHERE column1 = 2', [], [[2, 'BB']]], |
|
67
|
|
|
['SELECT * FROM table_exec WHERE column1 = 3', [], []], |
|
68
|
|
|
]; |
|
69
|
|
|
} |
|
70
|
|
|
} |
|
71
|
|
|
|