Chris@0: assertTrue(Util::isAssoc(array('a' => 'A',))); Chris@0: $this->assertTrue(Util::isAssoc(array())); Chris@0: $this->assertFalse(Util::isAssoc(array(1 => 'One',))); Chris@0: } Chris@0: Chris@0: /** Chris@0: * @dataProvider mergeAssocArrayProvider Chris@0: */ Chris@0: public function testMergeAssocArray($message, $to, $from, $clobber, $expectedResult) Chris@0: { Chris@0: $result = Util::mergeAssocArray($to, $from, $clobber); Chris@0: $this->assertEquals($expectedResult, $result, $message); Chris@0: } Chris@0: Chris@0: public function mergeAssocArrayProvider() Chris@0: { Chris@0: return array( Chris@0: Chris@0: array( Chris@0: 'Clobber should replace to value with from value for strings (shallow)', Chris@0: // to Chris@0: array('a' => 'A'), Chris@0: // from Chris@0: array('a' => 'B'), Chris@0: // clobber Chris@0: true, Chris@0: // expected result Chris@0: array('a' => 'B'), Chris@0: ), Chris@0: Chris@0: array( Chris@0: 'Clobber should replace to value with from value for strings (deep)', Chris@0: // to Chris@0: array('a' => array('b' => 'B',),), Chris@0: // from Chris@0: array('a' => array('b' => 'C',),), Chris@0: // clobber Chris@0: true, Chris@0: // expected result Chris@0: array('a' => array('b' => 'C',),), Chris@0: ), Chris@0: Chris@0: array( Chris@0: 'Clobber should NOTreplace to value with from value for strings (shallow)', Chris@0: // to Chris@0: array('a' => 'A'), Chris@0: // from Chris@0: array('a' => 'B'), Chris@0: // clobber Chris@0: false, Chris@0: // expected result Chris@0: array('a' => 'A'), Chris@0: ), Chris@0: Chris@0: array( Chris@0: 'Clobber should NOT replace to value with from value for strings (deep)', Chris@0: // to Chris@0: array('a' => array('b' => 'B',),), Chris@0: // from Chris@0: array('a' => array('b' => 'C',),), Chris@0: // clobber Chris@0: false, Chris@0: // expected result Chris@0: array('a' => array('b' => 'B',),), Chris@0: ), Chris@0: Chris@0: array( Chris@0: 'Associative arrays should be combined', Chris@0: // to Chris@0: array('a' => array('b' => 'B',),), Chris@0: // from Chris@0: array('a' => array('c' => 'C',),), Chris@0: // clobber Chris@0: null, Chris@0: // expected result Chris@0: array('a' => array('b' => 'B', 'c' => 'C',),), Chris@0: ), Chris@0: Chris@0: array( Chris@0: 'Arrays should be replaced (with clobber enabled)', Chris@0: // to Chris@0: array('a' => array('b', 'c',)), Chris@0: // from Chris@0: array('a' => array('B', 'C',),), Chris@0: // clobber Chris@0: true, Chris@0: // expected result Chris@0: array('a' => array('B', 'C',),), Chris@0: ), Chris@0: Chris@0: array( Chris@0: 'Arrays should be NOT replaced (with clobber disabled)', Chris@0: // to Chris@0: array('a' => array('b', 'c',)), Chris@0: // from Chris@0: array('a' => array('B', 'C',),), Chris@0: // clobber Chris@0: false, Chris@0: // expected result Chris@0: array('a' => array('b', 'c',),), Chris@0: ), Chris@0: ); Chris@0: } Chris@0: }