File tree Expand file tree Collapse file tree 3 files changed +40
-7
lines changed
src/ConstantContact/Definition Expand file tree Collapse file tree 3 files changed +40
-7
lines changed Original file line number Diff line number Diff line change @@ -20,6 +20,28 @@ public function testGetSet() : void
20
20
$ this ->assertIsString ($ fixture ->cf_string );
21
21
}
22
22
23
+ public function testJsonOutput () : void
24
+ {
25
+ $ class = new \Tests \Fixtures \CustomFieldTest ();
26
+ $ class ->cf_gender = 'mail ' ;
27
+ $ class ->cf_firstName = 'First ' ;
28
+ $ class ->cf_lastName = 'Class ' ;
29
+
30
+ $ json = $ class ->getJSON ();
31
+ $ expectedJSON = '{
32
+ "cf:gender": "mail",
33
+ "cf:firstName": "First",
34
+ "cf:lastName": "Class"
35
+ } ' ;
36
+ // normalize line endings
37
+ $ expectedJSON = \str_replace ("\r\n" , "\n" , $ expectedJSON );
38
+ $ this ->assertEquals ($ expectedJSON , $ json );
39
+
40
+ $ class = new \Tests \Fixtures \CustomFieldTest (['cf_gender ' => 'mail ' , 'cf_firstName ' => 'First ' , 'cf_lastName ' => 'Class ' ]);
41
+ $ json = $ class ->getJSON ();
42
+ $ this ->assertEquals ($ expectedJSON , $ json );
43
+ }
44
+
23
45
public function testBadIntType () : void
24
46
{
25
47
$ fixture = new \Tests \Fixtures \CustomFieldTest ();
Original file line number Diff line number Diff line change @@ -61,7 +61,6 @@ public function testGetSet() : void
61
61
62
62
$ json = $ fixture ->getJSON ();
63
63
$ expectedJSON = '{
64
- "class": [],
65
64
"integer": 123,
66
65
"string": "A long string",
67
66
"boolean": true,
@@ -73,7 +72,8 @@ public function testGetSet() : void
73
72
"float": 1.23,
74
73
"enum": "primary_email",
75
74
"intEnum": 1,
76
- "ucEnum": "REMOVED"
75
+ "ucEnum": "REMOVED",
76
+ "class": []
77
77
} ' ;
78
78
// normalize line endings
79
79
$ expectedJSON = \str_replace ("\r\n" , "\n" , $ expectedJSON );
Original file line number Diff line number Diff line change @@ -51,21 +51,32 @@ abstract class Base
51
51
52
52
public function __construct (array $ initialValues = [])
53
53
{
54
- foreach (static :: $ fields as $ field => $ type )
54
+ foreach ($ initialValues as $ field => $ value )
55
55
{
56
- if (! empty ($ initialValues [$ field ]))
56
+ $ actualField = $ field ;
57
+ if (str_starts_with ($ field , 'cf_ ' ))
57
58
{
58
- $ this ->{$ field } = $ initialValues [$ field ];
59
+ $ field = 'cf:custom_field_name ' ;
60
+ }
61
+ $ type = static ::$ fields [$ field ] ?? null ;
62
+ if (! $ type )
63
+ {
64
+ continue ;
65
+ }
66
+
67
+ if (! empty (static ::$ fields [$ field ]))
68
+ {
69
+ $ this ->{$ actualField } = $ value ;
59
70
}
60
71
elseif (! \is_array ($ type ) && ! isset (self ::$ scalars [$ type ]))
61
72
{
62
73
if (\str_starts_with ($ type , 'array ' ))
63
74
{
64
- $ this ->data [$ field ] = [];
75
+ $ this ->data [$ actualField ] = [];
65
76
}
66
77
else
67
78
{
68
- $ this ->data [$ field ] = new $ type ();
79
+ $ this ->data [$ actualField ] = new $ type ();
69
80
}
70
81
}
71
82
}
You can’t perform that action at this time.
0 commit comments