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