@@ -18,9 +18,10 @@ public function testToJsonFile00() {
1818 }
1919 /**
2020 * @test
21- * @depends testToJsonFile00
2221 */
2322 public function testToJsonFile01 () {
23+ $ json = new Json ();
24+ $ json ->toJsonFile ('json-file ' , ROOT .DIRECTORY_SEPARATOR .'json-output ' , true );
2425 $ outputPath = ROOT .DIRECTORY_SEPARATOR .'json-output ' .DIRECTORY_SEPARATOR .'json-file.json ' ;
2526 $ this ->expectException (\Exception::class);
2627 $ this ->expectExceptionMessage ("File already exist: ' $ outputPath' " );
@@ -34,13 +35,12 @@ public function testToJsonString00() {
3435 $ j = new Json (['hello ' =>'world ' ]);
3536 $ this ->assertEquals ('{"hello":"world"} ' ,$ j ->toJSONString ());
3637 $ this ->assertEquals ('world ' ,$ j ->get ('hello ' ));
37- return $ j ;
3838 }
3939 /**
40- * @depends testToJsonString00
41- * @param Json $json
40+ * @test
4241 */
43- public function testToJsonXString00 (Json $ json ) {
42+ public function testToJsonXString00 () {
43+ $ json = new Json (['hello ' =>'world ' ]);
4444 $ this ->assertEquals ('<?xml version="1.0" encoding="UTF-8"?> ' ."\r\n"
4545 . '<json:object xsi:schemaLocation="http://www.datapower.com/schemas/json jsonx.xsd" '
4646 . 'xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" '
@@ -57,13 +57,12 @@ public function testToJsonString01() {
5757 $ j = new Json (['number ' =>100 ]);
5858 $ this ->assertEquals ('{"number":100} ' ,$ j ->toJSONString ());
5959 $ this ->assertSame (100 ,$ j ->get ('number ' ));
60- return $ j ;
6160 }
6261 /**
63- * @depends testToJsonString01
64- * @param Json $json
62+ * @test
6563 */
66- public function testToJsonXString01 (Json $ json ) {
64+ public function testToJsonXString01 () {
65+ $ json = new Json (['number ' =>100 ]);
6766 $ this ->assertEquals ('<?xml version="1.0" encoding="UTF-8"?> ' ."\r\n"
6867 . '<json:object xsi:schemaLocation="http://www.datapower.com/schemas/json jsonx.xsd" '
6968 . 'xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" '
@@ -80,13 +79,12 @@ public function testToJsonString02() {
8079 $ j = new Json (['number ' =>20.2235 ]);
8180 $ this ->assertEquals ('{"number":20.2235} ' ,$ j ->toJSONString ());
8281 $ this ->assertSame (20.2235 ,$ j ->get ('number ' ));
83- return $ j ;
8482 }
8583 /**
86- * @depends testToJsonString02
87- * @param Json $json
84+ * @test
8885 */
89- public function testToJsonXString02 (Json $ json ) {
86+ public function testToJsonXString02 () {
87+ $ json = new Json (['number ' =>20.2235 ]);
9088 $ this ->assertEquals ('<?xml version="1.0" encoding="UTF-8"?> ' ."\r\n"
9189 . '<json:object xsi:schemaLocation="http://www.datapower.com/schemas/json jsonx.xsd" '
9290 . 'xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" '
@@ -103,13 +101,12 @@ public function testToJsonString03() {
103101 $ j = new Json (['number ' =>NAN ]);
104102 $ this ->assertEquals ('{"number":"NaN"} ' ,$ j ->toJSONString ());
105103 $ this ->assertTrue (is_nan ($ j ->get ('number ' )));
106- return $ j ;
107104 }
108105 /**
109- * @depends testToJsonString03
110- * @param Json $json
106+ * @test
111107 */
112- public function testToJsonXString03 (Json $ json ) {
108+ public function testToJsonXString03 () {
109+ $ json = new Json (['number ' =>NAN ]);
113110 $ this ->assertEquals ('<?xml version="1.0" encoding="UTF-8"?> ' ."\r\n"
114111 . '<json:object xsi:schemaLocation="http://www.datapower.com/schemas/json jsonx.xsd" '
115112 . 'xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" '
@@ -126,13 +123,12 @@ public function testToJsonString04() {
126123 $ j = new Json (['number ' =>INF ]);
127124 $ this ->assertEquals ('{"number":"Infinity"} ' ,$ j ->toJSONString ());
128125 $ this ->assertSame (INF ,$ j ->get ('number ' ));
129- return $ j ;
130126 }
131127 /**
132- * @depends testToJsonString04
133- * @param Json $json
128+ * @test
134129 */
135- public function testToJsonXString04 (Json $ json ) {
130+ public function testToJsonXString04 () {
131+ $ json = new Json (['number ' =>INF ]);
136132 $ this ->assertEquals ('<?xml version="1.0" encoding="UTF-8"?> ' ."\r\n"
137133 . '<json:object xsi:schemaLocation="http://www.datapower.com/schemas/json jsonx.xsd" '
138134 . 'xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" '
@@ -150,13 +146,12 @@ public function testToJsonString05() {
150146 $ this ->assertEquals ('{"bool-true":true,"bool-false":false} ' ,$ j ->toJSONString ());
151147 $ this ->assertSame (true ,$ j ->get ('bool-true ' ));
152148 $ this ->assertSame (false ,$ j ->get ('bool-false ' ));
153- return $ j ;
154149 }
155150 /**
156- * @depends testToJsonString05
157- * @param Json $json
151+ * @test
158152 */
159- public function testToJsonXString05 (Json $ json ) {
153+ public function testToJsonXString05 () {
154+ $ json = new Json (['bool-true ' =>true ,'bool-false ' =>false ]);
160155 $ this ->assertEquals ('<?xml version="1.0" encoding="UTF-8"?> ' ."\r\n"
161156 . '<json:object xsi:schemaLocation="http://www.datapower.com/schemas/json jsonx.xsd" '
162157 . 'xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" '
@@ -176,13 +171,12 @@ public function testToJsonString06() {
176171 $ j = new Json (['null ' =>null ]);
177172 $ this ->assertEquals ('{"null":null} ' ,$ j ->toJSONString ());
178173 $ this ->assertNull ($ j ->get ('null ' ));
179- return $ j ;
180174 }
181175 /**
182- * @depends testToJsonString06
183- * @param Json $json
176+ * @test
184177 */
185- public function testToJsonXString06 (Json $ json ) {
178+ public function testToJsonXString06 () {
179+ $ json = new Json (['null ' =>null ]);
186180 $ this ->assertEquals ('<?xml version="1.0" encoding="UTF-8"?> ' ."\r\n"
187181 . '<json:object xsi:schemaLocation="http://www.datapower.com/schemas/json jsonx.xsd" '
188182 . 'xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" '
@@ -199,13 +193,12 @@ public function testToJsonString07() {
199193 $ j = new Json (['array ' =>['one ' ,1 ]]);
200194 $ this ->assertEquals ('{"array":["one",1]} ' ,$ j ->toJSONString ());
201195 $ this ->assertEquals (['one ' ,1 ],$ j ->get ('array ' ));
202- return $ j ;
203196 }
204197 /**
205- * @depends testToJsonString07
206- * @param Json $json
198+ * @test
207199 */
208- public function testToJsonXString07 (Json $ json ) {
200+ public function testToJsonXString07 () {
201+ $ json = new Json (['array ' =>['one ' ,1 ]]);
209202 $ this ->assertEquals ('<?xml version="1.0" encoding="UTF-8"?> ' ."\r\n"
210203 . '<json:object xsi:schemaLocation="http://www.datapower.com/schemas/json jsonx.xsd" '
211204 . 'xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" '
@@ -231,13 +224,16 @@ public function testToJsonString08() {
231224 ]);
232225 $ this ->assertEquals ('{"array":["one",1,null,1.8,true,false,"NaN","Infinity",{"hello":"world"},["two","good"]]} ' ,$ j ->toJSONString ());
233226
234- return $ j ;
235227 }
236228 /**
237- * @depends testToJsonString08
238- * @param Json $json
229+ * @test
239230 */
240- public function testToJsonXString08 (Json $ json ) {
231+ public function testToJsonXString08 () {
232+ $ jx = new Json (['hello ' =>'world ' ]);
233+ $ arr = ['one ' ,1 ,null ,1.8 ,true ,false ,NAN ,INF ,$ jx ,['two ' ,'good ' ]];
234+ $ json = new Json ([
235+ 'array ' =>$ arr
236+ ]);
241237 $ this ->assertEquals ('<?xml version="1.0" encoding="UTF-8"?> ' ."\r\n"
242238 . '<json:object xsi:schemaLocation="http://www.datapower.com/schemas/json jsonx.xsd" '
243239 . 'xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" '
@@ -300,13 +296,14 @@ public function testToJsonString09() {
300296 . '} ' ,$ j ->toJSONString ());
301297 $ j ->setIsFormatted (false );
302298 $ this ->assertEquals ('{"arr":{"0":"NaN","1":"Infinity"}} ' ,$ j ->toJSONString ());
303- return $ j ;
304299 }
305300 /**
306- * @depends testToJsonString09
307- * @param Json $json
301+ * @test
308302 */
309- public function testToJsonXString09 (Json $ json ) {
303+ public function testToJsonXString09 () {
304+ $ arr = [NAN ,INF ];
305+ $ json = new Json ();
306+ $ json ->addArray ('arr ' ,$ arr ,true );
310307 $ this ->assertEquals ('<?xml version="1.0" encoding="UTF-8"?> ' ."\r\n"
311308 . '<json:object xsi:schemaLocation="http://www.datapower.com/schemas/json jsonx.xsd" '
312309 . 'xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" '
@@ -390,13 +387,22 @@ public function testToJsonString10() {
390387 . '} ' ,$ j .'' );
391388 $ j ->setIsFormatted (false );
392389 $ this ->assertEquals ('{"jsonx":{"number_one":1,"arr":[],"obj":{},"general":{"property_00":"1","property_01":"3","property_02":99,"property_04":"ok"}},"o":{"property_00":"1","property_01":2,"property_02":3}} ' ,$ j .'' );
393- return $ j ;
394390 }
395391 /**
396- * @depends testToJsonString10
397- * @param Json $json
392+ * @test
398393 */
399- public function testToJsonXString10 (Json $ json ) {
394+ public function testToJsonXString10 () {
395+ $ json = new Json ();
396+ $ subJ = new Json ([
397+ 'number-one ' => 1 ,
398+ 'arr ' => [],
399+ 'obj ' => new Json ()
400+ ]);
401+ $ json ->add ('jsonx ' ,$ subJ );
402+ $ json ->add ('o ' ,new Obj1 ('1 ' ,2 ,3 ,4 ,'5 ' ));
403+ $ json ->setPropsStyle ('snake ' );
404+ $ json ->setIsFormatted (false );
405+ $ json ->get ('jsonx ' )->add ('general ' ,new Obj0 ('1 ' ,'3 ' ,99 ,100 ,"ok " ));
400406 $ this ->assertEquals ('<?xml version="1.0" encoding="UTF-8"?> ' ."\r\n"
401407 . '<json:object xsi:schemaLocation="http://www.datapower.com/schemas/json jsonx.xsd" '
402408 . 'xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" '
@@ -463,7 +469,6 @@ public function testToJsonString11() {
463469 $ json ->addArray ('x-array ' , $ arr , true );
464470 $ this ->assertEquals ('{"x-array":{"0":{"0":"sub-arr","1":1,"2":2,"hello":"world", '
465471 . '"3":{"Property00":"1","Property01":2,"Property02":3,"Property04":5},"4":{"good":true}},"1":{"bad":false}}} ' ,$ json .'' );
466- return $ json ;
467472 }
468473 /**
469474 * @test
@@ -495,10 +500,22 @@ public function testToJsonString13() {
495500
496501 }
497502 /**
498- * @depends testToJsonString11
499- * @param Json $json
503+ * @test
500504 */
501- public function testToJsonXString11 (Json $ json ) {
505+ public function testToJsonXString11 () {
506+ $ arr = [
507+ [
508+ "sub-arr " ,
509+ 1 ,
510+ 2 ,
511+ "hello " =>"world " ,
512+ new Obj0 ('1 ' ,2 ,3 ,4 ,5 ),
513+ new Json (['good ' =>true ])
514+ ],
515+ new Json (['bad ' =>false ])
516+ ];
517+ $ json = new Json ();
518+ $ json ->addArray ('x-array ' , $ arr , true );
502519 $ this ->assertEquals ('<?xml version="1.0" encoding="UTF-8"?> ' ."\r\n"
503520 . '<json:object xsi:schemaLocation="http://www.datapower.com/schemas/json jsonx.xsd" '
504521 . 'xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" '
0 commit comments