/
AutoFormatNormalizerTest.php
86 lines (73 loc) 路 2.04 KB
/
AutoFormatNormalizerTest.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
<?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\AutoFormatNormalizer;
use Ergebnis\Json\Normalizer\Format;
use Ergebnis\Json\Normalizer\Json;
use Ergebnis\Json\Normalizer\Normalizer;
/**
* @internal
*
* @covers \Ergebnis\Json\Normalizer\AutoFormatNormalizer
*
* @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 AutoFormatNormalizerTest extends AbstractNormalizerTestCase
{
public function testNormalizeNormalizesAndFormatsUsingJsonFormat(): void
{
$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::equalTo(Format\Format::fromJson($json)),
)
->willReturn($formatted);
$normalizer = new AutoFormatNormalizer(
$composedNormalizer,
$formatter,
);
self::assertSame($formatted, $normalizer->normalize($json));
}
}