Skip to content

Commit 71be8f2

Browse files
committed
msi 100
1 parent f955edd commit 71be8f2

7 files changed

Lines changed: 146 additions & 3 deletions

File tree

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@
7070
"@test:cs"
7171
],
7272
"test:cs": "mkdir -p build && PHP_CS_FIXER_IGNORE_ENV=1 vendor/bin/php-cs-fixer fix --dry-run --stop-on-violation --cache-file=build/phpcs.cache",
73-
"test:infection": "vendor/bin/infection --threads=$(nproc) --min-msi=93 --verbose --coverage=build/phpunit",
73+
"test:infection": "vendor/bin/infection --threads=$(nproc) --min-msi=100 --verbose --coverage=build/phpunit",
7474
"test:integration": "vendor/bin/phpunit --testsuite=Integration --cache-result-file=build/phpunit/result.cache",
7575
"test:lint": "mkdir -p build && find src tests -name '*.php' -print0 | xargs -0 -n1 -P$(nproc) php -l | tee build/phplint.log",
7676
"test:static-analysis": "mkdir -p build && bash -c 'vendor/bin/phpstan analyse src --no-progress --level=8 --error-format=junit | tee build/phpstan.junit.xml; if [ ${PIPESTATUS[0]} -ne \"0\" ]; then exit 1; fi'",

infection.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
}
1616
},
1717
"mutators": {
18-
"@default": true
18+
"@default": true,
19+
"CastString": false
1920
}
2021
}

src/Decoder/JsonxTypeDecoder.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ private function decodeBooleanNode(\DOMNode $node): bool
116116

117117
private function decodeStringNode(\DOMNode $node): string
118118
{
119-
return html_entity_decode($node->nodeValue, ENT_COMPAT | ENT_XML1, 'UTF-8');
119+
return $node->nodeValue;
120120
}
121121

122122
private function decodeNumberNode(\DOMNode $node): float|int

tests/Unit/Decoder/JsonTypeDecoderTest.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,7 @@ public function testInvalidDecode(): void
198198
{
199199
$this->expectException(RuntimeException::class);
200200
$this->expectExceptionMessage('Data is not parsable with content-type: "application/json", error: "Syntax error"');
201+
201202
$decoderType = new JsonTypeDecoder();
202203
$decoderType->decode('====');
203204
}
@@ -206,7 +207,34 @@ public function testNotArrayDecode(): void
206207
{
207208
$this->expectException(RuntimeException::class);
208209
$this->expectExceptionMessage('Data is not parsable with content-type: "application/json", error: "Not an object"');
210+
209211
$decoderType = new JsonTypeDecoder();
210212
$decoderType->decode('null');
211213
}
214+
215+
public function testMaxNestedDecode(): void
216+
{
217+
$data = [];
218+
for ($i = 0; $i < 510; ++$i) {
219+
$data = ['data' => $data];
220+
}
221+
222+
$decoderType = new JsonTypeDecoder();
223+
224+
self::assertSame('array', \gettype($decoderType->decode(json_encode($data, 0, 511))));
225+
}
226+
227+
public function testTomatchNestedDecode(): void
228+
{
229+
$this->expectException(RuntimeException::class);
230+
$this->expectExceptionMessage('Data is not parsable with content-type: "application/json", error: "Maximum stack depth exceeded"');
231+
232+
$data = [];
233+
for ($i = 0; $i < 511; ++$i) {
234+
$data = ['data' => $data];
235+
}
236+
237+
$decoderType = new JsonTypeDecoder();
238+
$decoderType->decode(json_encode($data, 0, 512));
239+
}
212240
}

tests/Unit/Decoder/JsonxTypeDecoderTest.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,22 @@ public function testTypes(): void
196196
self::assertSame('0041000000000', $data['phone']);
197197
}
198198

199+
public function testWithEntities(): void
200+
{
201+
$jsonx = <<<'EOD'
202+
<?xml version="1.0" encoding="UTF-8"?>
203+
<json:object xsi:schemaLocation="http://www.datapower.com/schemas/json jsonx.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:json="http://www.ibm.com/xmlns/prod/2009/jsonx">
204+
<json:string name="name">"&lt;xml&gt;&lt;/xml&gt;"</json:string>
205+
</json:object>
206+
EOD;
207+
208+
$decoder = new JsonxTypeDecoder();
209+
210+
$data = $decoder->decode($jsonx);
211+
212+
self::assertSame('"<xml></xml>"', $data['name']);
213+
}
214+
199215
public function testInvalidTag(): void
200216
{
201217
$this->expectException(RuntimeException::class);

tests/Unit/Encoder/XmlTypeEncoderTest.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,4 +213,16 @@ public function testFormat(array $data): void
213213
EOT;
214214
self::assertEquals($expectedXml, $xml);
215215
}
216+
217+
public function testWitoutPrettyPrint(): void
218+
{
219+
$encoder = new XmlTypeEncoder();
220+
221+
$expectedXml = <<<'EOT'
222+
<?xml version="1.0" encoding="UTF-8"?>
223+
<json:object xsi:schemaLocation="http://www.datapower.com/schemas/json jsonx.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:json="http://www.ibm.com/xmlns/prod/2009/jsonx"><json:string name="key">value</json:string></json:object>
224+
EOT;
225+
226+
self::assertSame($expectedXml, $encoder->encode(['key' => 'value']));
227+
}
216228
}

tests/Unit/Encoder/YamlTypeEncoderTest.php

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,4 +164,90 @@ public function testFormat(array $data): void
164164

165165
self::assertEquals($expectedYaml, $yaml);
166166
}
167+
168+
public function testNotInline(): void
169+
{
170+
$yamlencoder = new YamlTypeEncoder();
171+
172+
$yaml = $yamlencoder->encode(['key' => [
173+
'key' => [
174+
'key' => [
175+
'key' => [
176+
'key' => [
177+
'key' => [
178+
'key' => [
179+
'key' => [
180+
'key' => [
181+
'key' => 'value',
182+
],
183+
],
184+
],
185+
],
186+
],
187+
],
188+
],
189+
],
190+
],
191+
]);
192+
193+
$expectedYaml =
194+
<<<'EOT'
195+
key:
196+
key:
197+
key:
198+
key:
199+
key:
200+
key:
201+
key:
202+
key:
203+
key:
204+
key: value
205+
EOT;
206+
207+
self::assertEquals($expectedYaml, $yaml);
208+
}
209+
210+
public function testInline(): void
211+
{
212+
$yamlencoder = new YamlTypeEncoder();
213+
214+
$yaml = $yamlencoder->encode([
215+
'key' => [
216+
'key' => [
217+
'key' => [
218+
'key' => [
219+
'key' => [
220+
'key' => [
221+
'key' => [
222+
'key' => [
223+
'key' => [
224+
'key' => [
225+
'key' => 'value',
226+
],
227+
],
228+
],
229+
],
230+
],
231+
],
232+
],
233+
],
234+
],
235+
],
236+
]);
237+
238+
$expectedYaml = <<<'EOT'
239+
key:
240+
key:
241+
key:
242+
key:
243+
key:
244+
key:
245+
key:
246+
key:
247+
key:
248+
key: { key: value }
249+
EOT;
250+
251+
self::assertEquals($expectedYaml, $yaml);
252+
}
167253
}

0 commit comments

Comments
 (0)