Skip to content
This repository was archived by the owner on Apr 25, 2026. It is now read-only.

Commit 390b630

Browse files
committed
Unit tests: Improve coverage of the deserializer.
1 parent 55baad7 commit 390b630

3 files changed

Lines changed: 38 additions & 16 deletions

File tree

PhpSerializerNET.Test/Deserialize/ArrayDeserialization.cs

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -72,19 +72,19 @@ public void ExplicitToDictionaryOfComplexType() {
7272

7373
var expected = new Dictionary<string, SimpleClass>
7474
{
75+
{
76+
"AKey",
77+
new SimpleClass
7578
{
76-
"AKey",
77-
new SimpleClass
78-
{
79-
ADouble = 1.2345d,
80-
AString = "this is a string value",
81-
AnInteger = 10,
82-
False = false,
83-
True = true
84-
}
85-
79+
ADouble = 1.2345d,
80+
AString = "this is a string value",
81+
AnInteger = 10,
82+
False = false,
83+
True = true
8684
}
87-
};
85+
86+
}
87+
};
8888

8989
// No easy way to assert dicts in MsTest :/
9090

@@ -173,6 +173,14 @@ public void ExplicitToList() {
173173
Assert.Equal(new List<string>() { "Hello", "World", "12345" }, result);
174174
}
175175

176+
[Fact]
177+
public void ExplicitToObjectList() {
178+
var result = PhpSerialization.Deserialize<List<object>>("a:3:{i:0;s:5:\"Hello\";i:1;s:5:\"World\";i:2;i:12345;}");
179+
180+
Assert.Equal(3, result.Count);
181+
Assert.Equal(new List<object>() { "Hello", "World", 12345 }, result);
182+
}
183+
176184
[Fact]
177185
public void ExplicitToArray() {
178186
var result = PhpSerialization.Deserialize<string[]>("a:3:{i:0;s:5:\"Hello\";i:1;s:5:\"World\";i:2;i:12345;}");
@@ -255,14 +263,12 @@ public void MixedKeyArrayIntoObject() {
255263
Assert.Equal("B", result.Dummy);
256264
}
257265

258-
public class ArrayItem
259-
{
266+
public class ArrayItem {
260267
[PhpProperty("foo")] public string Foo { get; set; }
261268
[PhpProperty("bar")] public InnerArrayItem Bar { get; set; }
262269
}
263270

264-
public class InnerArrayItem
265-
{
271+
public class InnerArrayItem {
266272
public string A { get; set; }
267273
public string B { get; set; }
268274
}
@@ -271,7 +277,7 @@ public class InnerArrayItem
271277
public void NestedArrays() {
272278
// Regression test for https://github.com/StringEpsilon/PhpSerializerNET/issues/40
273279
var value = """a:2:{i:0;a:2:{s:3:"foo";s:4:"ixcg";s:3:"bar";a:2:{s:1:"A";s:5:"04381";s:1:"B";s:5:"11576";}}i:1;a:2:{s:3:"foo";s:4:"atnp";s:3:"bar";a:2:{s:1:"A";s:5:"33267";s:1:"B";s:5:"68391";}}}""";
274-
// PropertyType is
280+
// PropertyType is
275281
var item = PhpSerialization.Deserialize<List<ArrayItem>>(value);
276282
Assert.NotNull(item);
277283
}

PhpSerializerNET.Test/Deserialize/DoubleDeserialization.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ This Source Code Form is subject to the terms of the Mozilla Public
66
file, You can obtain one at http://mozilla.org/MPL/2.0/.
77
**/
88

9+
using System.Globalization;
910
using PhpSerializerNET.Test.Deserialize.Options;
1011
using Xunit;
1112

@@ -36,6 +37,20 @@ public void DeserializesDoubles(string input, double expected) {
3637
);
3738
}
3839

40+
[Theory]
41+
[InlineData("d:1;", "1")]
42+
[InlineData("d:-1;", "-1")]
43+
[InlineData("d:1.23456789;", "1.23456789")]
44+
[InlineData("d:-1.23456789;", "-1.23456789")]
45+
[InlineData("d:INF;", "Infinity")]
46+
[InlineData("d:-INF;", "-Infinity")]
47+
public void DeserializesDoubleToStrings(string input, string expected) {
48+
Assert.Equal(
49+
expected,
50+
PhpSerialization.Deserialize<string>(input)
51+
);
52+
}
53+
3954
[Fact]
4055
public void ExplicetlyDeserializesToInteger() {
4156
double number = PhpSerialization.Deserialize<double>("d:10;");

PhpSerializerNET.Test/Deserialize/IntegerDeserialization.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ public class IntegerDeserializationTest {
1616
[InlineData("i:+1;", 1)]
1717
[InlineData("i:-1;", -1)]
1818
[InlineData("i:2147483647;", int.MaxValue)]
19+
[InlineData("i:+2147483647;", int.MaxValue)]
1920
[InlineData("i:-2147483648;", int.MinValue)]
2021
public void Deserialize(string input, int expected) {
2122
Assert.Equal(expected, PhpSerialization.Deserialize<int>(input));

0 commit comments

Comments
 (0)