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\Client; |
17
|
|
|
use Tarantool\Client\Error; |
18
|
|
|
use Tarantool\Client\Packer\Extension\ErrorExtension; |
19
|
|
|
use Tarantool\Client\Packer\PurePacker; |
20
|
|
|
use Tarantool\Client\Tests\Integration\ClientBuilder; |
21
|
|
|
use Tarantool\Client\Tests\Integration\TestCase; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* @requires clientPacker pure |
25
|
|
|
*/ |
26
|
|
|
final class ErrorExtensionTest extends TestCase |
27
|
|
|
{ |
28
|
|
|
/** |
29
|
|
|
* @requires Tarantool >=2.4.1 <2.10 |
30
|
|
|
* @see https://github.com/tarantool/tarantool/issues/6428 |
31
|
|
|
*/ |
32
|
|
|
public function testLuaPackingAndUnpacking() : void |
33
|
|
|
{ |
34
|
|
|
$client = self::createClientWithExtendedErrorSupport(); |
35
|
|
|
|
36
|
|
|
/** @var Error $error */ |
37
|
|
|
$error = $client->evaluate(' |
38
|
|
|
box.session.settings.error_marshaling_enabled = true |
39
|
|
|
err1 = box.error.new({code = 1, type = "t1", reason = "r1"}) |
40
|
|
|
err2 = box.error.new({code = 2, type = "t2", reason = "r2",}) |
41
|
|
|
err1:set_prev(err2) |
42
|
|
|
return err1 |
43
|
|
|
')[0]; |
44
|
|
|
|
45
|
|
|
self::assertInstanceOf(Error::class, $error); |
46
|
|
|
self::assertSame('CustomError', $error->getType()); |
47
|
|
|
self::assertSame('r1', $error->getMessage()); |
48
|
|
|
self::assertSame(1, $error->getCode()); |
49
|
|
|
self::assertSame(['custom_type' => 't1'], $error->getFields()); |
50
|
|
|
|
51
|
|
|
$prevError = $error->getPrevious(); |
52
|
|
|
self::assertInstanceOf(Error::class, $prevError); |
53
|
|
|
self::assertSame('CustomError', $prevError->getType()); |
54
|
|
|
self::assertSame('r2', $prevError->getMessage()); |
55
|
|
|
self::assertSame(2, $prevError->getCode()); |
56
|
|
|
self::assertSame(['custom_type' => 't2'], $prevError->getFields()); |
57
|
|
|
self::assertNull($prevError->getPrevious()); |
58
|
|
|
|
59
|
|
|
$isEqual = $client->evaluate(' |
60
|
|
|
box.session.settings.error_marshaling_enabled = true |
61
|
|
|
err1 = ... |
62
|
|
|
err2 = err1.prev |
63
|
|
|
return |
64
|
|
|
err1.code == 1 and err1.type == "t1" and err1.message == "r1" and |
65
|
|
|
err2.code == 2 and err2.type == "t2" and err2.message == "r2" and |
66
|
|
|
err1.prev == err2 |
67
|
|
|
', $error)[0]; |
68
|
|
|
|
69
|
|
|
self::assertTrue($isEqual); |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
private static function createClientWithExtendedErrorSupport() : Client |
73
|
|
|
{ |
74
|
|
|
return ClientBuilder::createFromEnv() |
75
|
|
|
->setPackerPureFactory(static function () { |
76
|
|
|
return PurePacker::fromExtensions(new ErrorExtension()); |
77
|
|
|
}) |
78
|
|
|
->build(); |
79
|
|
|
} |
80
|
|
|
} |
81
|
|
|
|