comparison vendor/dflydev/dot-access-data/tests/Dflydev/DotAccessData/UtilTest.php @ 0:c75dbcec494b

Initial commit from drush-created site
author Chris Cannam
date Thu, 05 Jul 2018 14:24:15 +0000
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:c75dbcec494b
1 <?php
2
3 /*
4 * This file is a part of dflydev/dot-access-data.
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\DotAccessData;
13
14 class UtilTest extends \PHPUnit_Framework_TestCase
15 {
16 public function testIsAssoc()
17 {
18 $this->assertTrue(Util::isAssoc(array('a' => 'A',)));
19 $this->assertTrue(Util::isAssoc(array()));
20 $this->assertFalse(Util::isAssoc(array(1 => 'One',)));
21 }
22
23 /**
24 * @dataProvider mergeAssocArrayProvider
25 */
26 public function testMergeAssocArray($message, $to, $from, $clobber, $expectedResult)
27 {
28 $result = Util::mergeAssocArray($to, $from, $clobber);
29 $this->assertEquals($expectedResult, $result, $message);
30 }
31
32 public function mergeAssocArrayProvider()
33 {
34 return array(
35
36 array(
37 'Clobber should replace to value with from value for strings (shallow)',
38 // to
39 array('a' => 'A'),
40 // from
41 array('a' => 'B'),
42 // clobber
43 true,
44 // expected result
45 array('a' => 'B'),
46 ),
47
48 array(
49 'Clobber should replace to value with from value for strings (deep)',
50 // to
51 array('a' => array('b' => 'B',),),
52 // from
53 array('a' => array('b' => 'C',),),
54 // clobber
55 true,
56 // expected result
57 array('a' => array('b' => 'C',),),
58 ),
59
60 array(
61 'Clobber should NOTreplace to value with from value for strings (shallow)',
62 // to
63 array('a' => 'A'),
64 // from
65 array('a' => 'B'),
66 // clobber
67 false,
68 // expected result
69 array('a' => 'A'),
70 ),
71
72 array(
73 'Clobber should NOT replace to value with from value for strings (deep)',
74 // to
75 array('a' => array('b' => 'B',),),
76 // from
77 array('a' => array('b' => 'C',),),
78 // clobber
79 false,
80 // expected result
81 array('a' => array('b' => 'B',),),
82 ),
83
84 array(
85 'Associative arrays should be combined',
86 // to
87 array('a' => array('b' => 'B',),),
88 // from
89 array('a' => array('c' => 'C',),),
90 // clobber
91 null,
92 // expected result
93 array('a' => array('b' => 'B', 'c' => 'C',),),
94 ),
95
96 array(
97 'Arrays should be replaced (with clobber enabled)',
98 // to
99 array('a' => array('b', 'c',)),
100 // from
101 array('a' => array('B', 'C',),),
102 // clobber
103 true,
104 // expected result
105 array('a' => array('B', 'C',),),
106 ),
107
108 array(
109 'Arrays should be NOT replaced (with clobber disabled)',
110 // to
111 array('a' => array('b', 'c',)),
112 // from
113 array('a' => array('B', 'C',),),
114 // clobber
115 false,
116 // expected result
117 array('a' => array('b', 'c',),),
118 ),
119 );
120 }
121 }