Repository navigation
Expand file tree
/
Copy pathExceptionNormalizerTest.php
More file actions
57 lines (51 loc) · 1.9 KB
/
Copy pathExceptionNormalizerTest.php
File metadata and controls
57 lines (51 loc) · 1.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
<?php
declare(strict_types=1);
/**
* This file is part of Hyperf.
*
* @link https://www.hyperf.io
* @document https://hyperf.wiki
* @contact [email protected]
* @license https://github.com/hyperf/hyperf/blob/master/LICENSE
*/
namespace HyperfTest\Serializer;
use Hyperf\Serializer\ExceptionNormalizer;
use HyperfTest\Serializer\Stub\FooException;
use HyperfTest\Serializer\Stub\SerializableException;
use InvalidArgumentException;
use PHPUnit\Framework\Attributes\CoversNothing;
use PHPUnit\Framework\TestCase;
/**
* @internal
* @coversNothing
*/
#[CoversNothing]
class ExceptionNormalizerTest extends TestCase
{
public function testInvalidArgumentException()
{
$normalizer = new ExceptionNormalizer();
$ex = new InvalidArgumentException('invalid param foo');
$result = $normalizer->normalize($ex);
$ret = $normalizer->denormalize($result, InvalidArgumentException::class);
$this->assertInstanceOf(InvalidArgumentException::class, $ret);
$this->assertEquals($ret->getMessage(), $ex->getMessage());
$this->assertEquals($ret, $ex);
}
public function testSerializableException()
{
$normalizer = new ExceptionNormalizer();
$ex = new SerializableException('invalid param foo');
$result = $normalizer->normalize($ex);
$ret = $normalizer->denormalize($result, SerializableException::class);
$this->assertInstanceOf(SerializableException::class, $ret);
$this->assertEquals($ret->getMessage(), $ex->getMessage());
$this->assertEquals($ret, $ex);
$ex = new FooException(1000, 'invalid param foo');
$result = $normalizer->normalize($ex);
$ret = $normalizer->denormalize($result, FooException::class);
$this->assertInstanceOf(FooException::class, $ret);
$this->assertEquals($ret->getMessage(), $ex->getMessage());
$this->assertEquals($ret, $ex);
}
}