Passed
Branch master (923150)
by Eugene
06:30
created

print_result()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 3
nc 2
nop 2
dl 0
loc 5
rs 10
c 1
b 0
f 0
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
use Symfony\Component\Uid\Uuid;
15
use Tarantool\Client\Schema\Criteria;
16
17
require __DIR__.'/../bootstrap.php';
18
19
$client = create_client();
20
ensure_server_version_at_least('2.4', $client);
21
ensure_class(Uuid::class, 'Composer package "symfony/uid" is required');
22
ensure_pure_packer($client);
23
24
$spaceName = 'example';
25
26
$client->evaluate(
27
<<<LUA
28
    if box.space[...] then box.space[...]:drop() end
29
    local space = box.schema.space.create(...)
30
    space:create_index("primary", {parts = {1, 'uuid'}})
31
    local uuid = require('uuid')
32
    space:insert({uuid.fromstr('64d22e4d-ac92-4a23-899a-e59f34af5479'), 'foo'})
33
LUA
34
, $spaceName);
35
36
$space = $client->getSpace($spaceName);
37
38
$result1 = $space->insert([new Uuid('7e3b84a4-0819-473a-9625-5d57ad1c9604'), 'bar']);
39
$result2 = $space->select(Criteria::geIterator());
40
41
function print_result(string $title, array $rows) : void
42
{
43
    echo "$title:\n";
44
    foreach ($rows as $row) {
45
        printf("[%s('%s'), '%s']\n", get_class($row[0]), $row[0], $row[1]);
46
    }
47
}
48
49
print_result('Result 1', $result1);
50
print_result('Result 2', $result2);
51
52
/* OUTPUT
53
Result 1:
54
[Symfony\Component\Uid\UuidV4('7e3b84a4-0819-473a-9625-5d57ad1c9604'), 'bar']
55
Result 2:
56
[Symfony\Component\Uid\UuidV4('64d22e4d-ac92-4a23-899a-e59f34af5479'), 'foo']
57
[Symfony\Component\Uid\UuidV4('7e3b84a4-0819-473a-9625-5d57ad1c9604'), 'bar']
58
*/
59