-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathInlineNormalizerTest.php
More file actions
98 lines (77 loc) · 2.7 KB
/
Copy pathInlineNormalizerTest.php
File metadata and controls
98 lines (77 loc) · 2.7 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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
<?php
declare(strict_types=1);
namespace Patchlevel\Hydrator\Tests\Unit\Normalizer;
use Patchlevel\Hydrator\Normalizer\InlineNormalizer;
use Patchlevel\Hydrator\Normalizer\InvalidType;
use PHPUnit\Framework\TestCase;
final class InlineNormalizerTest extends TestCase
{
public function testNormalizeWithValue(): void
{
$normalizer = new InlineNormalizer(
static fn (int $value): string => (string)$value,
static fn (string $value): int => (int)$value,
);
$this->assertEquals('123', $normalizer->normalize(123));
}
public function testDenormalizeWithValue(): void
{
$normalizer = new InlineNormalizer(
static fn (int $value): string => (string)$value,
static fn (string $value): int => (int)$value,
);
$this->assertEquals(123, $normalizer->denormalize('123'));
}
public function testNormalizeWithNull(): void
{
$normalizer = new InlineNormalizer(
static fn (mixed $value) => 'not null',
static fn (mixed $value) => 'not null',
);
$this->assertNull($normalizer->normalize(null));
}
public function testDenormalizeWithNull(): void
{
$normalizer = new InlineNormalizer(
static fn (mixed $value) => 'not null',
static fn (mixed $value) => 'not null',
);
$this->assertNull($normalizer->denormalize(null));
}
public function testNormalizePassNull(): void
{
$normalizer = new InlineNormalizer(
static fn (mixed $value) => $value === null ? 'is null' : 'is not null',
static fn (mixed $value) => $value,
true,
);
$this->assertEquals('is null', $normalizer->normalize(null));
}
public function testDenormalizePassNull(): void
{
$normalizer = new InlineNormalizer(
static fn (mixed $value) => $value,
static fn (mixed $value) => $value === null ? 'is null' : 'is not null',
true,
);
$this->assertEquals('is null', $normalizer->denormalize(null));
}
public function testNormalizeInvalidType(): void
{
$this->expectException(InvalidType::class);
$normalizer = new InlineNormalizer(
static fn (string $value) => $value,
static fn (mixed $value) => $value,
);
$normalizer->normalize(123);
}
public function testDenormalizeInvalidType(): void
{
$this->expectException(InvalidType::class);
$normalizer = new InlineNormalizer(
static fn (mixed $value) => $value,
static fn (string $value) => $value,
);
$normalizer->denormalize(123);
}
}