@@ -28,6 +28,42 @@ public function test_should_flatten_the_array($data)
2828 $ this ->assertEquals ($ expected , $ arguments ->flatten ());
2929 }
3030
31+ public function test_set_without_dot_key ()
32+ {
33+ $ data = new ExtendedArguments ();
34+
35+ $ data ->set ('foo ' , 'bar ' );
36+ $ this ->assertSame ('bar ' , $ data ->get ('foo ' ));
37+
38+ $ data ->set ('foo.bar ' , 'gir ' );
39+
40+ $ this ->assertFalse ($ data ->has ('bar ' ),
41+ 'Sub-keys are not scanned ' );
42+ $ this ->assertTrue ($ data ->has ('foo.bar ' ));
43+ $ this ->assertSame ('gir ' , $ data ->get ('foo.bar ' ));
44+ $ this ->assertSame (['bar ' => 'gir ' ], $ data ->get ('foo ' ),
45+ 'Finds all sub-keys ' );
46+ }
47+
48+ public function test_delete_without_dot_key ()
49+ {
50+ $ data = new ExtendedArguments (['foo ' => 'bar ' ]);
51+
52+ $ other = $ data ->delete ('foo.bar ' );
53+ $ this ->assertSame ($ data , $ other ,
54+ 'Does not modify if key is not found ' );
55+
56+ $ data ->delete ('foo ' );
57+ $ this ->assertFalse ($ data ->has ('foo ' ));
58+
59+ $ data ->set ('foo.bar ' , 'baz ' );
60+ $ this ->assertTrue ($ data ->has ('foo.bar ' ));
61+
62+ $ data ->delete ('bar ' );
63+ $ this ->assertTrue ($ data ->has ('foo.bar ' ),
64+ 'Sub-item is not deleted ' );
65+ }
66+
3167 /**
3268 * @dataProvider data
3369 */
@@ -95,14 +131,19 @@ public function test_flatten($input)
95131
96132 public function test_frakked_up_keys ()
97133 {
98- $ data = include __DIR__ . '/fixtures/nested-array.php ' ;
134+ $ actual = include __DIR__ . '/fixtures/nested-array.php ' ;
135+ $ expected = include __DIR__ . '/fixtures/nested-array-transformed.php ' ;
136+ $ arguments = new ExtendedArguments ($ actual );
99137
100- $ arguments = new ExtendedArguments ( $ data );
101- $ this -> assertSame ( $ data , $ arguments -> toArray (), 'The data is intact ' );
138+ $ this -> assertSame ( $ expected , $ arguments -> toArray (),
139+ 'The data is transformed internally ' );
102140
103141 // But, the keys are messed up now...
104- $ this ->assertSame (true , $ arguments ->get ('array.1 ' ), "The key is TRUE and now juggled into string 1 " );
105- $ this ->assertSame ('null ' , $ arguments ->get ('' ), "The key is NULL but frakked up as empty string " );
142+ $ this ->assertSame (true , $ arguments ->get ('array.1 ' ),
143+ 'The key is TRUE and now juggled into string 1 ' );
144+
145+ $ this ->assertSame ('null ' , $ arguments ->get ('' ),
146+ 'The key is NULL but frakked up as empty string ' );
106147 }
107148
108149 /** @dataProvider data */
@@ -111,10 +152,17 @@ public function test_extract($data)
111152 $ arguments = new ExtendedArguments ($ data );
112153 $ this ->assertEquals ([
113154 'key3.1 ' => 'B ' ,
155+ 'key2.key21 ' => 'B ' ,
114156 'key4.key41.key412 ' => 'E ' ,
115157 'key2 ' => ['key21 ' => 'B ' ],
116158 'non-existent ' => null
117- ], $ arguments ->extract (['key3.1 ' , 'key4.key41.key412 ' , 'key2 ' , 'non-existent ' ]));
159+ ], $ arguments ->extract ([
160+ 'key3.1 ' ,
161+ 'key2.key21 ' ,
162+ 'key4.key41.key412 ' ,
163+ 'key2 ' ,
164+ 'non-existent '
165+ ]));
118166 }
119167
120168 public function data ()
0 commit comments