1+ <?php
2+
3+ /*
4+ * This file is a part of dflydev/dot-access-configuration.
5+ *
6+ * (c) Dragonfly Development Inc.
7+ *
8+ * For the full copyright and license information, please view the LICENSE
9+ * file that was distributed with this source code.
10+ */
11+
12+ namespace Dflydev \Tests \DotAccessConfiguration ;
13+
14+ use Dflydev \DotAccessConfiguration \Util ;
15+
16+ class UtilTest extends \PHPUnit_Framework_TestCase
17+ {
18+ /**
19+ * @dataProvider mergeAssocArrayProvider
20+ */
21+ public function testMergeAssocArray ($ message , $ to , $ from , $ clobber , $ expectedResult )
22+ {
23+ $ result = Util::mergeAssocArray ($ to , $ from , $ clobber );
24+ $ this ->assertEquals ($ expectedResult , $ result , $ message );
25+ }
26+
27+ public function mergeAssocArrayProvider ()
28+ {
29+ return array (
30+
31+ array (
32+ 'Clobber should replace to value with from value for strings (shallow) ' ,
33+ // to
34+ array ('a ' => 'A ' ),
35+ // from
36+ array ('a ' => 'B ' ),
37+ // clobber
38+ true ,
39+ // expected result
40+ array ('a ' => 'B ' ),
41+ ),
42+
43+ array (
44+ 'Clobber should replace to value with from value for strings (deep) ' ,
45+ // to
46+ array ('a ' => array ('b ' => 'B ' ,),),
47+ // from
48+ array ('a ' => array ('b ' => 'C ' ,),),
49+ // clobber
50+ true ,
51+ // expected result
52+ array ('a ' => array ('b ' => 'C ' ,),),
53+ ),
54+
55+ array (
56+ 'Clobber should NOTreplace to value with from value for strings (shallow) ' ,
57+ // to
58+ array ('a ' => 'A ' ),
59+ // from
60+ array ('a ' => 'B ' ),
61+ // clobber
62+ false ,
63+ // expected result
64+ array ('a ' => 'A ' ),
65+ ),
66+
67+ array (
68+ 'Clobber should NOT replace to value with from value for strings (deep) ' ,
69+ // to
70+ array ('a ' => array ('b ' => 'B ' ,),),
71+ // from
72+ array ('a ' => array ('b ' => 'C ' ,),),
73+ // clobber
74+ false ,
75+ // expected result
76+ array ('a ' => array ('b ' => 'B ' ,),),
77+ ),
78+
79+ array (
80+ 'Associative arrays should be combined ' ,
81+ // to
82+ array ('a ' => array ('b ' => 'B ' ,),),
83+ // from
84+ array ('a ' => array ('c ' => 'C ' ,),),
85+ // clobber
86+ null ,
87+ // expected result
88+ array ('a ' => array ('b ' => 'B ' , 'c ' => 'C ' ,),),
89+ ),
90+
91+ array (
92+ 'Arrays should be replaced (with clobber enabled) ' ,
93+ // to
94+ array ('a ' => array ('b ' , 'c ' ,)),
95+ // from
96+ array ('a ' => array ('B ' , 'C ' ,),),
97+ // clobber
98+ true ,
99+ // expected result
100+ array ('a ' => array ('B ' , 'C ' ,),),
101+ ),
102+
103+ array (
104+ 'Arrays should be NOT replaced (with clobber disabled) ' ,
105+ // to
106+ array ('a ' => array ('b ' , 'c ' ,)),
107+ // from
108+ array ('a ' => array ('B ' , 'C ' ,),),
109+ // clobber
110+ false ,
111+ // expected result
112+ array ('a ' => array ('b ' , 'c ' ,),),
113+ ),
114+ );
115+ }
116+ }
0 commit comments