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 Tarantool\Client\Client; |
15
|
|
|
use Tarantool\Client\Connection\StreamConnection; |
16
|
|
|
use Tarantool\Client\Handler\DefaultHandler; |
17
|
|
|
use Tarantool\Client\Packer\Packer; |
18
|
|
|
use Tarantool\Client\Packer\PackerFactory; |
19
|
|
|
use Tarantool\Client\Packer\PurePacker; |
20
|
|
|
use Tarantool\Client\Tests\Integration\ExamplesTest; |
21
|
|
|
|
22
|
|
|
return require __DIR__.'/../vendor/autoload.php'; |
23
|
|
|
|
24
|
|
|
function create_client(?Packer $packer = null) : Client |
25
|
|
|
{ |
26
|
|
|
$connection = isset($_SERVER['argv'][1]) |
27
|
|
|
? StreamConnection::create($_SERVER['argv'][1]) |
28
|
|
|
: StreamConnection::createTcp(); |
29
|
|
|
|
30
|
|
|
return new Client(new DefaultHandler($connection, $packer ?? PackerFactory::create())); |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
function server_version_at_least(string $version, Client $client) : bool |
34
|
|
|
{ |
35
|
|
|
[$info] = $client->call('box.info'); |
36
|
|
|
$actualVersion = preg_replace('/-[^-]+$/', '', $info['version']); |
37
|
|
|
|
38
|
|
|
return version_compare($actualVersion, $version, '>='); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
function ensure_server_version_at_least(string $version, Client $client) : void |
42
|
|
|
{ |
43
|
|
|
if (server_version_at_least($version, $client)) { |
44
|
|
|
return; |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
printf('Tarantool version >= %s is required to run "%s"%s', $version, $_SERVER['SCRIPT_FILENAME'], PHP_EOL); |
48
|
|
|
exit(ExamplesTest::EXIT_CODE_SKIP); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
function ensure_extension(string $name) : void |
52
|
|
|
{ |
53
|
|
|
if (extension_loaded($name)) { |
54
|
|
|
return; |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
printf('PHP extension "%s" is required to run "%s"%s', $name, $_SERVER['SCRIPT_FILENAME'], PHP_EOL); |
58
|
|
|
exit(ExamplesTest::EXIT_CODE_SKIP); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
function ensure_class(string $className, string $requireMessage = '') : void |
62
|
|
|
{ |
63
|
|
|
if (class_exists($className)) { |
64
|
|
|
return; |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
$errorMessage = $requireMessage ?: sprintf('Class "%s" is required', $className); |
68
|
|
|
|
69
|
|
|
printf('%s to run "%s"%s', $errorMessage, $_SERVER['SCRIPT_FILENAME'], PHP_EOL); |
70
|
|
|
exit(ExamplesTest::EXIT_CODE_SKIP); |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
function ensure_pure_packer(Client $client) : void |
74
|
|
|
{ |
75
|
|
|
$packer = $client->getHandler()->getPacker(); |
76
|
|
|
if ($packer instanceof PurePacker) { |
77
|
|
|
return; |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
printf('Client needs to be configured to use pure packer to run "%s"%s', $_SERVER['SCRIPT_FILENAME'], PHP_EOL); |
81
|
|
|
exit(ExamplesTest::EXIT_CODE_SKIP); |
82
|
|
|
} |
83
|
|
|
|