@@ -27,59 +27,64 @@ public function testIsAssoc()
2727 /**
2828 * @dataProvider mergeAssocArrayProvider
2929 */
30- public function testMergeAssocArray ($ message , $ to , $ from , $ clobber , $ expectedResult )
30+ public function testMergeAssocArray ($ message , $ to , $ from , $ mode , $ expectedResult )
3131 {
32- $ result = Util::mergeAssocArray ($ to , $ from , $ clobber );
32+ if ($ mode === null ) {
33+ $ result = Util::mergeAssocArray ($ to , $ from );
34+ } else {
35+ $ result = Util::mergeAssocArray ($ to , $ from , $ mode );
36+ }
37+
3338 $ this ->assertEquals ($ expectedResult , $ result , $ message );
3439 }
3540
3641 public function mergeAssocArrayProvider ()
3742 {
3843 return [
3944 [
40- 'Clobber should replace to value with from value for strings (shallow) ' ,
45+ 'Overwrite should replace to value with from value for strings (shallow) ' ,
4146 // to
4247 ['a ' => 'A ' ],
4348 // from
4449 ['a ' => 'B ' ],
45- // clobber
46- true ,
50+ // mode
51+ DataInterface:: REPLACE ,
4752 // expected result
4853 ['a ' => 'B ' ],
4954 ],
5055
5156 [
52- 'Clobber should replace to value with from value for strings (deep) ' ,
57+ 'Overwrite should replace to value with from value for strings (deep) ' ,
5358 // to
5459 ['a ' => ['b ' => 'B ' ]],
5560 // from
5661 ['a ' => ['b ' => 'C ' ]],
57- // clobber
58- true ,
62+ // mode
63+ DataInterface:: REPLACE ,
5964 // expected result
6065 ['a ' => ['b ' => 'C ' ]]
6166 ],
6267
6368 [
64- 'Clobber should NOTreplace to value with from value for strings (shallow) ' ,
69+ 'Existing values are not replaced in preserve mode (shallow) ' ,
6570 // to
6671 ['a ' => 'A ' ],
6772 // from
6873 ['a ' => 'B ' ],
69- // clobber
70- false ,
74+ // mode
75+ DataInterface:: PRESERVE ,
7176 // expected result
7277 ['a ' => 'A ' ],
7378 ],
7479
7580 [
76- 'Clobber should NOT replace to value with from value for strings (deep) ' ,
81+ 'Existing values are not replaced in preserve mode (deep) ' ,
7782 // to
7883 ['a ' => ['b ' => 'B ' ]],
7984 // from
8085 ['a ' => ['b ' => 'C ' ]],
81- // clobber
82- false ,
86+ // mode
87+ DataInterface:: PRESERVE ,
8388 // expected result
8489 ['a ' => ['b ' => 'B ' ]],
8590 ],
@@ -90,35 +95,47 @@ public function mergeAssocArrayProvider()
9095 ['a ' => ['b ' => 'B ' ]],
9196 // from
9297 ['a ' => ['c ' => 'C ' ]],
93- // clobber
98+ // mode
9499 null ,
95100 // expected result
96101 ['a ' => ['b ' => 'B ' , 'c ' => 'C ' ]],
97102 ],
98103
99104 [
100- 'Arrays should be replaced (with clobber enabled) ' ,
105+ 'Arrays should be replaced ' ,
101106 // to
102107 ['a ' => ['b ' , 'c ' ]],
103108 // from
104109 ['a ' => ['B ' , 'C ' ]],
105- // clobber
106- true ,
110+ // mode
111+ DataInterface:: REPLACE ,
107112 // expected result
108113 ['a ' => ['B ' , 'C ' ]],
109114 ],
110115
111116 [
112- 'Arrays should be NOT replaced (with clobber disabled) ' ,
117+ 'Arrays should be preserved ' ,
113118 // to
114119 ['a ' => ['b ' , 'c ' ]],
115120 // from
116121 ['a ' => ['B ' , 'C ' ]],
117- // clobber
118- false ,
122+ // mode
123+ DataInterface:: PRESERVE ,
119124 // expected result
120125 ['a ' => ['b ' , 'c ' ]],
121126 ],
127+
128+ [
129+ 'Arrays should be merged/appended (when using MERGE) ' ,
130+ // to
131+ ['a ' => 1 , 'b ' => 1 , 'n ' => [1 ], 'x ' => 'string ' , 'y ' => ['stringindex ' => 1 ]],
132+ // from
133+ ['a ' => 2 , 'c ' => 2 , 'n ' => [2 ], 'x ' => ['array ' ], 'y ' => [2 ]],
134+ // mode
135+ DataInterface::MERGE ,
136+ // expected result
137+ ['a ' => 2 , 'b ' => 1 , 'c ' => 2 , 'n ' => [1 , 2 ], 'x ' => ['array ' ], 'y ' => ['stringindex ' => 1 , 0 => 2 ]]
138+ ],
122139 ];
123140 }
124141}
0 commit comments