@@ -17,30 +17,35 @@ class ChildTest extends \PHPUnit\Framework\TestCase
17
17
{
18
18
public function testChildExists ()
19
19
{
20
- $ browser = new JsonBrowser ('{"childOne": "valueOne", "2": "valueTwo"} ' );
20
+ $ browser = new JsonBrowser ();
21
+ $ browser ->loadJSON ('{"childOne": "valueOne", "2": "valueTwo"} ' );
21
22
$ this ->assertTrue ($ browser ->childExists ('childOne ' ));
22
23
$ this ->assertTrue ($ browser ->childExists ('2 ' ));
23
24
$ this ->assertTrue ($ browser ->childExists (2 )); // array_key_exists() allows sloppy typing
24
25
$ this ->assertFalse ($ browser ->childExists ('childThree ' ));
25
26
$ this ->assertFalse ($ browser ->childExists (3 ));
26
27
27
- $ browser = new JsonBrowser ('["valueOne", "valueTwo"] ' );
28
+ $ browser = new JsonBrowser ();
29
+ $ browser ->loadJSON ('["valueOne", "valueTwo"] ' );
28
30
$ this ->assertTrue ($ browser ->childExists (0 ));
29
31
$ this ->assertTrue ($ browser ->childExists ('1 ' ));
30
32
$ this ->assertFalse ($ browser ->childExists (2 ));
31
33
$ this ->assertFalse ($ browser ->childExists ("childThree " ));
32
34
33
- $ browser = new JsonBrowser ('"stringValue" ' );
35
+ $ browser = new JsonBrowser ();
36
+ $ browser ->loadJSON ('"stringValue" ' );
34
37
$ this ->assertFalse ($ browser ->childExists ('childOne ' ));
35
38
}
36
39
37
40
public function testGetChild ()
38
41
{
39
- $ array = new JsonBrowser ('["valueOne"] ' );
42
+ $ array = new JsonBrowser ();
43
+ $ array ->loadJSON ('["valueOne"] ' );
40
44
$ this ->assertEquals ('valueOne ' , $ array ->getChild (0 )->getValue ());
41
45
$ this ->assertNull ($ array ->getChild (1 )->getValue ());
42
46
43
- $ root = new JsonBrowser ('{"childOne": "valueOne", "childTwo": {"childThree": "valueThree"}} ' );
47
+ $ root = new JsonBrowser ();
48
+ $ root ->loadJSON ('{"childOne": "valueOne", "childTwo": {"childThree": "valueThree"}} ' );
44
49
$ childOne = $ root ->getChild ('childOne ' );
45
50
$ childTwo = $ root ->getChild ('childTwo ' );
46
51
$ childThree = $ childTwo ->getChild ('childThree ' );
@@ -56,15 +61,17 @@ public function testGetChild()
56
61
$ this ->assertNull ($ childFour ->getValue ());
57
62
$ this ->assertNull ($ childFive ->getValue ());
58
63
59
- $ root = new JsonBrowser ('{"childOne": "valueOne"} ' , JsonBrowser::OPT_NONEXISTENT_EXCEPTIONS );
64
+ $ root = new JsonBrowser (JsonBrowser::OPT_NONEXISTENT_EXCEPTIONS );
65
+ $ root ->loadJSON ('{"childOne": "valueOne"} ' );
60
66
$ this ->assertEquals ('valueOne ' , $ root ->getChild ('childOne ' )->getValue ());
61
67
$ this ->expectException (Exception::class);
62
68
$ root ->getChild ('childTwo ' );
63
69
}
64
70
65
71
public function testGetRoot ()
66
72
{
67
- $ root = new JsonBrowser ('{"childOne": {"childTwo": "valueTwo"}} ' );
73
+ $ root = new JsonBrowser ();
74
+ $ root ->loadJSON ('{"childOne": {"childTwo": "valueTwo"}} ' );
68
75
$ childOne = $ root ->getChild ('childOne ' );
69
76
$ childTwo = $ childOne ->getChild ('childTwo ' );
70
77
@@ -75,7 +82,8 @@ public function testGetRoot()
75
82
76
83
public function testGetParent ()
77
84
{
78
- $ root = new JsonBrowser ('{"childOne": {"childTwo": "valueTwo"}} ' );
85
+ $ root = new JsonBrowser ();
86
+ $ root ->loadJSON ('{"childOne": {"childTwo": "valueTwo"}} ' );
79
87
$ childOne = $ root ->getChild ('childOne ' );
80
88
$ childTwo = $ childOne ->getChild ('childTwo ' );
81
89
@@ -86,7 +94,8 @@ public function testGetParent()
86
94
87
95
public function testGetSet ()
88
96
{
89
- $ root = new JsonBrowser ('{"childOne": "valueOne"} ' );
97
+ $ root = new JsonBrowser ();
98
+ $ root ->loadJSON ('{"childOne": "valueOne"} ' );
90
99
$ this ->assertEquals ('valueOne ' , $ root ->childOne ->getValue ());
91
100
92
101
$ root ->childTwo = 'valueTwo ' ;
@@ -95,7 +104,8 @@ public function testGetSet()
95
104
96
105
public function testDynamicGetValue ()
97
106
{
98
- $ root = new JsonBrowser ('{"childOne": "valueOne"} ' , JsonBrowser::OPT_GET_VALUE );
107
+ $ root = new JsonBrowser (JsonBrowser::OPT_GET_VALUE );
108
+ $ root ->loadJSON ('{"childOne": "valueOne"} ' );
99
109
$ this ->assertEquals ('valueOne ' , $ root ->childOne );
100
110
}
101
111
}
0 commit comments