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

Commit 503407c

Browse files
committed
Chore: Moved the last tests to their proper place.
Closes #17
1 parent e8e2263 commit 503407c

5 files changed

Lines changed: 110 additions & 86 deletions

File tree

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/**
2+
This Source Code Form is subject to the terms of the Mozilla Public
3+
License, v. 2.0. If a copy of the MPL was not distributed with this
4+
file, You can obtain one at http://mozilla.org/MPL/2.0/.
5+
**/
6+
7+
namespace PhpSerializerNET.Test.DataTypes {
8+
public partial class DeserializeObjects {
9+
public class CircularTest {
10+
public string Foo { get; set; }
11+
public CircularTest Bar { get; set; }
12+
}
13+
}
14+
}

PhpSerializerNET.Test/Deserialize/ArrayDeserialization.cs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ This Source Code Form is subject to the terms of the Mozilla Public
1010
using System.Linq;
1111
using Microsoft.VisualStudio.TestTools.UnitTesting;
1212
using PhpSerializerNET.Test.DataTypes;
13+
using static PhpSerializerNET.Test.DataTypes.DeserializeObjects;
1314

1415
namespace PhpSerializerNET.Test.Deserialize {
1516
[TestClass]
@@ -200,5 +201,38 @@ public void ImplicitToDictionary(){
200201
Assert.AreEqual(true, dictionary["True"]);
201202
Assert.AreEqual(false, dictionary["False"]);
202203
}
204+
205+
[TestMethod]
206+
public void ExcplicitToNestedObject() {
207+
var result = PhpSerialization.Deserialize<CircularTest>("a:2:{s:3:\"Foo\";s:5:\"First\";s:3:\"Bar\";a:2:{s:3:\"Foo\";s:6:\"Second\";s:3:\"Bar\";N;}}");
208+
209+
Assert.AreEqual(
210+
"First",
211+
result.Foo
212+
);
213+
Assert.IsNotNull(
214+
result.Bar
215+
);
216+
Assert.AreEqual(
217+
"Second",
218+
result.Bar.Foo
219+
);
220+
}
221+
222+
[TestMethod]
223+
public void Test_Issue11() {
224+
// See https://github.com/StringEpsilon/PhpSerializerNET/issues/11
225+
var deserializedObject = PhpSerialization.Deserialize(
226+
"a:1:{i:0;a:7:{s:1:\"A\";N;s:1:\"B\";N;s:1:\"C\";s:1:\"C\";s:5:\"odSdr\";i:1;s:1:\"D\";d:1;s:1:\"E\";N;s:1:\"F\";a:3:{s:1:\"X\";i:8;s:1:\"Y\";N;s:1:\"Z\";N;}}}"
227+
);
228+
Assert.IsNotNull(deserializedObject);
229+
}
230+
231+
[TestMethod]
232+
public void Test_Issue12() {
233+
// See https://github.com/StringEpsilon/PhpSerializerNET/issues/12
234+
var result = PhpSerialization.Deserialize("a:1:{i:0;a:4:{s:1:\"A\";s:2:\"63\";s:1:\"B\";a:2:{i:558710;s:1:\"2\";i:558709;s:1:\"2\";}s:1:\"C\";s:2:\"71\";s:1:\"G\";a:3:{s:1:\"x\";s:6:\"446368\";s:1:\"y\";s:1:\"0\";s:1:\"z\";s:5:\"1.029\";}}}");
235+
Assert.IsNotNull(result);
236+
}
203237
}
204238
}

PhpSerializerNET.Test/Deserialize/StringDeserialization.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ This Source Code Form is subject to the terms of the Mozilla Public
77

88
using System;
99
using Microsoft.VisualStudio.TestTools.UnitTesting;
10+
using PhpSerializerNET.Test.DataTypes;
1011

1112
namespace PhpSerializerNET.Test.Deserialize {
1213
[TestClass]
@@ -83,5 +84,16 @@ public void ExplicitToGuid() {
8384
Guid guid = PhpSerialization.Deserialize<Guid>("s:36:\"82e2ebf0-43e6-4c10-82cf-57d60383a6be\";");
8485
Assert.AreEqual("82e2ebf0-43e6-4c10-82cf-57d60383a6be", guid.ToString());
8586
}
87+
88+
[TestMethod]
89+
public void DeserializesStringToGuidProperty() {
90+
var result = PhpSerialization.Deserialize<MappedClass>(
91+
"a:1:{s:4:\"Guid\";s:36:\"82e2ebf0-43e6-4c10-82cf-57d60383a6be\";}"
92+
);
93+
Assert.AreEqual(
94+
new Guid("82e2ebf0-43e6-4c10-82cf-57d60383a6be"),
95+
result.Guid
96+
);
97+
}
8698
}
8799
}

PhpSerializerNET.Test/DeserializeObjects.cs

Lines changed: 0 additions & 86 deletions
This file was deleted.
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/**
2+
This Source Code Form is subject to the terms of the Mozilla Public
3+
License, v. 2.0. If a copy of the MPL was not distributed with this
4+
file, You can obtain one at http://mozilla.org/MPL/2.0/.
5+
**/
6+
7+
using Microsoft.VisualStudio.TestTools.UnitTesting;
8+
using PhpSerializerNET.Test.DataTypes;
9+
10+
namespace PhpSerializerNET.Test {
11+
[TestClass]
12+
public partial class DeserializeWithRuntimeTypeTest {
13+
14+
[TestMethod]
15+
public void DeserializeObjectWithRuntimeType() {
16+
var expectedType = typeof(NamedClass);
17+
var result = PhpSerialization.Deserialize("O:8:\"stdClass\":2:{s:3:\"Foo\";d:3.14;s:3:\"Bar\";d:2.718;}", expectedType);
18+
19+
Assert.IsNotNull(result);
20+
Assert.IsInstanceOfType(result, expectedType);
21+
22+
Assert.AreEqual(
23+
3.14,
24+
((NamedClass)result).Foo
25+
);
26+
Assert.AreEqual(
27+
2.718,
28+
((NamedClass)result).Bar
29+
);
30+
}
31+
32+
[TestMethod]
33+
public void DeserializeArrayWithRuntimeType() {
34+
var expectedType = typeof(NamedClass);
35+
var result = PhpSerialization.Deserialize("a:2:{s:3:\"Foo\";d:3.14;s:3:\"Bar\";d:2.718;}", expectedType);
36+
37+
Assert.IsNotNull(result);
38+
Assert.IsInstanceOfType(result, expectedType);
39+
40+
Assert.AreEqual(
41+
3.14,
42+
((NamedClass)result).Foo
43+
);
44+
Assert.AreEqual(
45+
2.718,
46+
((NamedClass)result).Bar
47+
);
48+
}
49+
}
50+
}

0 commit comments

Comments
 (0)