-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathObjectNormalizationTest.php
More file actions
84 lines (70 loc) · 1.87 KB
/
ObjectNormalizationTest.php
File metadata and controls
84 lines (70 loc) · 1.87 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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
<?php declare(strict_types=1);
namespace Tests\Torr\SimpleNormalizer\Normalizer;
use PHPUnit\Framework\TestCase;
use Tests\Torr\SimpleNormalizer\Fixture\DummyVO;
use Torr\SimpleNormalizer\Exception\ObjectTypeNotSupportedException;
use Torr\SimpleNormalizer\Normalizer\SimpleNormalizer;
use Torr\SimpleNormalizer\Normalizer\SimpleObjectNormalizerInterface;
use Torr\SimpleNormalizer\Test\SimpleNormalizerTestTrait;
/**
* @internal
*/
final class ObjectNormalizationTest extends TestCase
{
use SimpleNormalizerTestTrait;
/**
*
*/
public function testNormalizeObject () : void
{
$dummyNormalizer = new class() implements SimpleObjectNormalizerInterface {
public function normalize (object $value, array $context, SimpleNormalizer $normalizer) : mixed
{
\assert($value instanceof DummyVO);
return [
"id" => $value->id,
];
}
public static function getNormalizedType () : string
{
return DummyVO::class;
}
};
$value = new DummyVO(42);
$normalizer = $this->createNormalizer($dummyNormalizer);
self::assertSame(["id" => 42], $normalizer->normalize($value));
}
/**
*
*/
public function testEmptyStdClass () : void
{
$normalizer = $this->createNormalizer();
$object = new \stdClass();
self::assertSame(
$object,
$normalizer->normalize($object),
);
}
/**
*
*/
public function testNonEmptyStdClassIsInvalid () : void
{
$normalizer = $this->createNormalizer();
$object = new \stdClass();
$object->prop = 5;
$this->expectException(ObjectTypeNotSupportedException::class);
$this->expectExceptionMessage("Can't normalize type 'stdClass' in stack stdClass");
$normalizer->normalize($object);
}
/**
*
*/
public function testMissingNormalizer () : void
{
$this->expectException(ObjectTypeNotSupportedException::class);
$normalizer = $this->createNormalizer();
$normalizer->normalize(new DummyVO(11));
}
}