@@ -26,8 +26,9 @@ public function testNormalize()
26
26
$ obj = new GetSetDummy ;
27
27
$ obj ->setFoo ('foo ' );
28
28
$ obj ->setBar ('bar ' );
29
+ $ obj ->setCamelCase ('camelcase ' );
29
30
$ this ->assertEquals (
30
- array ('foo ' => 'foo ' , 'bar ' => 'bar ' , 'fooBar ' => 'foobar ' ),
31
+ array ('foo ' => 'foo ' , 'bar ' => 'bar ' , 'fooBar ' => 'foobar ' , ' camelCase ' => ' camelcase ' ),
31
32
$ this ->normalizer ->normalize ($ obj , 'any ' )
32
33
);
33
34
}
@@ -43,6 +44,39 @@ public function testDenormalize()
43
44
$ this ->assertEquals ('bar ' , $ obj ->getBar ());
44
45
}
45
46
47
+ public function testDenormalizeOnCamelCaseFormat ()
48
+ {
49
+ $ this ->normalizer ->setCamelizedAttributes (array ('camel_case ' ));
50
+ $ obj = $ this ->normalizer ->denormalize (
51
+ array ('camel_case ' => 'camelCase ' ),
52
+ __NAMESPACE__ .'\GetSetDummy '
53
+ );
54
+ $ this ->assertEquals ('camelCase ' , $ obj ->getCamelCase ());
55
+ }
56
+
57
+ /**
58
+ * @dataProvider attributeProvider
59
+ */
60
+ public function testFormatAttribute ($ attribute , $ camelizedAttributes , $ result )
61
+ {
62
+ $ r = new \ReflectionObject ($ this ->normalizer );
63
+ $ m = $ r ->getMethod ('formatAttribute ' );
64
+ $ m ->setAccessible (true );
65
+
66
+ $ this ->normalizer ->setCamelizedAttributes ($ camelizedAttributes );
67
+ $ this ->assertEquals ($ m ->invoke ($ this ->normalizer , $ attribute , $ camelizedAttributes ), $ result );
68
+ }
69
+
70
+ public function attributeProvider ()
71
+ {
72
+ return array (
73
+ array ('attribute_test ' , array ('attribute_test ' ),'AttributeTest ' ),
74
+ array ('attribute_test ' , array ('any ' ),'attribute_test ' ),
75
+ array ('attribute ' , array ('attribute ' ),'Attribute ' ),
76
+ array ('attribute ' , array (), 'attribute ' ),
77
+ );
78
+ }
79
+
46
80
public function testConstructorDenormalize ()
47
81
{
48
82
$ obj = $ this ->normalizer ->denormalize (
@@ -82,7 +116,7 @@ public function testUncallableCallbacks()
82
116
83
117
public function testIgnoredAttributes ()
84
118
{
85
- $ this ->normalizer ->setIgnoredAttributes (array ('foo ' , 'bar ' ));
119
+ $ this ->normalizer ->setIgnoredAttributes (array ('foo ' , 'bar ' , ' camelCase ' ));
86
120
87
121
$ obj = new GetSetDummy ;
88
122
$ obj ->setFoo ('foo ' );
@@ -160,6 +194,7 @@ class GetSetDummy
160
194
{
161
195
protected $ foo ;
162
196
private $ bar ;
197
+ protected $ camelCase ;
163
198
164
199
public function getFoo ()
165
200
{
@@ -186,6 +221,16 @@ public function getFooBar()
186
221
return $ this ->foo . $ this ->bar ;
187
222
}
188
223
224
+ public function getCamelCase ()
225
+ {
226
+ return $ this ->camelCase ;
227
+ }
228
+
229
+ public function setCamelCase ($ camelCase )
230
+ {
231
+ $ this ->camelCase = $ camelCase ;
232
+ }
233
+
189
234
public function otherMethod ()
190
235
{
191
236
throw new \RuntimeException ("Dummy::otherMethod() should not be called " );
0 commit comments