/
FixedFormatNormalizerTest.php
96 lines (81 loc) 路 2.32 KB
/
FixedFormatNormalizerTest.php
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
<?php
declare(strict_types=1);
/**
* Copyright (c) 2018-2022 Andreas M枚ller
*
* For the full copyright and license information, please view
* the LICENSE.md file that was distributed with this source code.
*
* @see https://github.com/ergebnis/json-normalizer
*/
namespace Ergebnis\Json\Normalizer\Test\Unit;
use Ergebnis\Json\Normalizer\FixedFormatNormalizer;
use Ergebnis\Json\Normalizer\Format;
use Ergebnis\Json\Normalizer\Json;
use Ergebnis\Json\Normalizer\Normalizer;
/**
* @internal
*
* @covers \Ergebnis\Json\Normalizer\FixedFormatNormalizer
*
* @uses \Ergebnis\Json\Normalizer\Format\Format
* @uses \Ergebnis\Json\Normalizer\Format\Indent
* @uses \Ergebnis\Json\Normalizer\Format\JsonEncodeOptions
* @uses \Ergebnis\Json\Normalizer\Format\NewLine
* @uses \Ergebnis\Json\Normalizer\Json
*/
final class FixedFormatNormalizerTest extends AbstractNormalizerTestCase
{
public function testNormalizeNormalizesAndFormatsUsingFormat(): void
{
$faker = self::faker();
$format = Format\Format::create(
Format\JsonEncodeOptions::fromInt($faker->numberBetween(1)),
Format\Indent::fromString("\t"),
Format\NewLine::fromString("\r\n"),
$faker->boolean(),
);
$json = Json::fromEncoded(
<<<'JSON'
{
"status": "original"
}
JSON
);
$normalized = Json::fromEncoded(
<<<'JSON'
{
"status": "normalized"
}
JSON
);
$formatted = Json::fromEncoded(
<<<'JSON'
{
"status": "formatted"
}
JSON
);
$composedNormalizer = $this->createMock(Normalizer::class);
$composedNormalizer
->expects(self::once())
->method('normalize')
->with(self::identicalTo($json))
->willReturn($normalized);
$formatter = $this->createMock(Format\FormatterInterface::class);
$formatter
->expects(self::once())
->method('format')
->with(
self::identicalTo($normalized),
self::identicalTo($format),
)
->willReturn($formatted);
$normalizer = new FixedFormatNormalizer(
$composedNormalizer,
$format,
$formatter,
);
self::assertSame($formatted, $normalizer->normalize($json));
}
}