public function testGetValue() { $src = ['a' => 1, 'b' => 2, 'c' => 3, 'someProp' => 4, 'other_prop' => 5]; self::assertEquals(1, mp\getValue($src, 'a')); self::assertEquals(null, mp\getValue($src, 'd')); self::assertEquals('default', mp\getValue($src, 'd', 'default')); self::assertEquals(4, mp\getValue($src, 'someProp')); self::assertEquals(null, mp\getValue($src, 'some_prop')); self::assertEquals(null, mp\getValue($src, 'otherProp')); self::assertEquals(5, mp\getValue($src, 'other_prop')); $src = (object) $src; self::assertEquals(5, mp\getValue($src, 'other_prop')); self::assertEquals(null, mp\getValue($src, 'otherProp')); $person = new PersonStruct(); $person->setEmail('*****@*****.**'); self::assertEquals('*****@*****.**', mp\getValue($person, 'email')); $data = ['a' => ['b' => ['c' => $person]]]; self::assertEquals('*****@*****.**', mp\getValue($data, 'a.b.c.email')); mp\getValueByRef($data, 'a.b')['c'] = 'C'; self::assertEquals('C', mp\getValue($data, 'a.b.c')); }
public function testGetValue() { $src = ['a' => 1, 'b' => 2, 'c' => 3, 'someProp' => 4, 'other_prop' => 5]; self::assertEquals(1, Manipulator::getValue($src, 'a')); self::assertEquals(null, Manipulator::getValue($src, 'd')); self::assertEquals('default', Manipulator::getValue($src, 'd', 'default')); self::assertEquals(4, Manipulator::getValue($src, 'someProp')); self::assertEquals(null, Manipulator::getValue($src, 'some_prop')); self::assertEquals(null, Manipulator::getValue($src, 'otherProp')); self::assertEquals(5, Manipulator::getValue($src, 'other_prop')); $src = (object) $src; self::assertEquals(5, Manipulator::getValue($src, 'other_prop')); self::assertEquals(null, Manipulator::getValue($src, 'otherProp')); $person = new PersonStruct(); $person->setEmail('*****@*****.**'); self::assertEquals('*****@*****.**', Manipulator::getValue($person, 'email')); }