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\MessagePack; |
15
|
|
|
|
16
|
|
|
use Tarantool\Client\Packer\PurePacker; |
17
|
|
|
use Tarantool\Client\Schema\Criteria; |
18
|
|
|
use Tarantool\Client\Tests\Integration\ClientBuilder; |
19
|
|
|
use Tarantool\Client\Tests\Integration\TestCase; |
20
|
|
|
use Tarantool\Client\Tests\PhpUnitCompat; |
21
|
|
|
|
22
|
|
|
final class MessagePackTest extends TestCase |
23
|
|
|
{ |
24
|
|
|
use PhpUnitCompat; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* @dataProvider providePackUnpackData |
28
|
|
|
*/ |
29
|
|
|
public function testPackUnpack($arg) : void |
30
|
|
|
{ |
31
|
|
|
self::assertSame([$arg], $this->client->evaluate('return ...', $arg)); |
|
|
|
|
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
public function providePackUnpackData() : iterable |
35
|
|
|
{ |
36
|
|
|
return [ |
37
|
|
|
[[]], |
38
|
|
|
[42], |
39
|
|
|
[-42], |
40
|
|
|
[4.2], |
41
|
|
|
[-4.2], |
42
|
|
|
[null], |
43
|
|
|
[false], |
44
|
|
|
['string'], |
45
|
|
|
["\x04\x00\xa0\x00\x00"], |
46
|
|
|
[[1, 2]], |
47
|
|
|
[[[[1, 2]]]], |
48
|
|
|
[['foo' => 'bar']], |
49
|
|
|
// User defined types (MessagePack extensions) are not yet supported: |
50
|
|
|
// https://github.com/tarantool/tarantool/issues/465 |
51
|
|
|
// [[(object) ['foo' => 'bar']]], |
52
|
|
|
]; |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
public function testPackUnpackMultiDimensionalArray() : void |
56
|
|
|
{ |
57
|
|
|
$array = [ |
58
|
|
|
[ |
59
|
|
|
'foo' => [42, 'a' => [null]], |
60
|
|
|
'bar' => [], |
61
|
|
|
10000 => -1, |
62
|
|
|
], |
63
|
|
|
true, |
64
|
|
|
]; |
65
|
|
|
|
66
|
|
|
[$result] = $this->client->evaluate('return ...', $array); |
67
|
|
|
|
68
|
|
|
self::assertEqualsCanonicalizing($array, $result); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* @lua space = create_space('custom_type') |
73
|
|
|
* @lua space:create_index('primary', {type = 'hash', parts = {1, 'unsigned'}}) |
74
|
|
|
*/ |
75
|
|
|
public function testCustomType() : void |
76
|
|
|
{ |
77
|
|
|
$client = ClientBuilder::createFromEnv() |
78
|
|
|
->setPackerFactory(static function () { |
79
|
|
|
return PurePacker::fromExtensions(new DateTimeExtension(42)); |
80
|
|
|
}) |
81
|
|
|
->build(); |
82
|
|
|
|
83
|
|
|
$date = new \DateTimeImmutable(); |
84
|
|
|
$space = $client->getSpace('custom_type'); |
85
|
|
|
$result = $space->insert([100, $date]); |
86
|
|
|
|
87
|
|
|
self::assertEquals($date, $result[0][1]); |
88
|
|
|
self::assertEquals($date, $space->select(Criteria::key([100]))[0][1]); |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* @requires condition env.EXT_DISABLE_DECIMAL |
93
|
|
|
* |
94
|
|
|
* @dataProvider \Tarantool\Client\Tests\PackerDataProvider::providePurePackerWithDefaultSettings() |
95
|
|
|
*/ |
96
|
|
|
public function testPurePackerUnpacksBigIntToString(PurePacker $packer) : void |
97
|
|
|
{ |
98
|
|
|
$client = ClientBuilder::createFromEnv() |
99
|
|
|
->setPackerFactory(static function () use ($packer) { return $packer; }) |
100
|
|
|
->build(); |
101
|
|
|
|
102
|
|
|
[$number] = $client->evaluate(sprintf('return %sULL', DecimalExtensionTest::DECIMAL_BIG_INT)); |
103
|
|
|
|
104
|
|
|
self::assertSame(DecimalExtensionTest::DECIMAL_BIG_INT, $number); |
105
|
|
|
} |
106
|
|
|
} |
107
|
|
|
|
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.