-
-
Notifications
You must be signed in to change notification settings - Fork 9.4k
/
XmlEncoderContextBuilderTest.php
91 lines (82 loc) · 3.52 KB
/
XmlEncoderContextBuilderTest.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
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\Serializer\Tests\Context\Encoder;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Serializer\Context\Encoder\XmlEncoderContextBuilder;
use Symfony\Component\Serializer\Encoder\XmlEncoder;
/**
* @author Mathias Arlaud <mathias.arlaud@gmail.com>
*/
class XmlEncoderContextBuilderTest extends TestCase
{
private XmlEncoderContextBuilder $contextBuilder;
protected function setUp(): void
{
$this->contextBuilder = new XmlEncoderContextBuilder();
}
/**
* @dataProvider withersDataProvider
*/
public function testWithers(array $values)
{
$context = $this->contextBuilder
->withAsCollection($values[XmlEncoder::AS_COLLECTION])
->withDecoderIgnoredNodeTypes($values[XmlEncoder::DECODER_IGNORED_NODE_TYPES])
->withEncoderIgnoredNodeTypes($values[XmlEncoder::ENCODER_IGNORED_NODE_TYPES])
->withEncoding($values[XmlEncoder::ENCODING])
->withFormatOutput($values[XmlEncoder::FORMAT_OUTPUT])
->withLoadOptions($values[XmlEncoder::LOAD_OPTIONS])
->withSaveOptions($values[XmlEncoder::SAVE_OPTIONS])
->withRemoveEmptyTags($values[XmlEncoder::REMOVE_EMPTY_TAGS])
->withRootNodeName($values[XmlEncoder::ROOT_NODE_NAME])
->withStandalone($values[XmlEncoder::STANDALONE])
->withTypeCastAttributes($values[XmlEncoder::TYPE_CAST_ATTRIBUTES])
->withVersion($values[XmlEncoder::VERSION])
->withCdataWrapping($values[XmlEncoder::CDATA_WRAPPING])
->withCdataWrappingPattern($values[XmlEncoder::CDATA_WRAPPING_PATTERN])
->toArray();
$this->assertSame($values, $context);
}
public static function withersDataProvider(): iterable
{
yield 'With values' => [[
XmlEncoder::AS_COLLECTION => true,
XmlEncoder::DECODER_IGNORED_NODE_TYPES => [\XML_PI_NODE, \XML_COMMENT_NODE],
XmlEncoder::ENCODER_IGNORED_NODE_TYPES => [\XML_TEXT_NODE],
XmlEncoder::ENCODING => 'UTF-8',
XmlEncoder::FORMAT_OUTPUT => false,
XmlEncoder::LOAD_OPTIONS => \LIBXML_COMPACT,
XmlEncoder::SAVE_OPTIONS => \LIBXML_NOERROR,
XmlEncoder::REMOVE_EMPTY_TAGS => true,
XmlEncoder::ROOT_NODE_NAME => 'root',
XmlEncoder::STANDALONE => false,
XmlEncoder::TYPE_CAST_ATTRIBUTES => true,
XmlEncoder::VERSION => '1.0',
XmlEncoder::CDATA_WRAPPING => false,
XmlEncoder::CDATA_WRAPPING_PATTERN => '/[<>&"\']/',
]];
yield 'With null values' => [[
XmlEncoder::AS_COLLECTION => null,
XmlEncoder::DECODER_IGNORED_NODE_TYPES => null,
XmlEncoder::ENCODER_IGNORED_NODE_TYPES => null,
XmlEncoder::ENCODING => null,
XmlEncoder::FORMAT_OUTPUT => null,
XmlEncoder::LOAD_OPTIONS => null,
XmlEncoder::SAVE_OPTIONS => null,
XmlEncoder::REMOVE_EMPTY_TAGS => null,
XmlEncoder::ROOT_NODE_NAME => null,
XmlEncoder::STANDALONE => null,
XmlEncoder::TYPE_CAST_ATTRIBUTES => null,
XmlEncoder::VERSION => null,
XmlEncoder::CDATA_WRAPPING => null,
XmlEncoder::CDATA_WRAPPING_PATTERN => null,
]];
}
}