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