/**
  * @param $fieldName
  * @param $default
  * @param $expectedValue
  * @dataProvider providerGetters
  *
  */
 public function testGetValue($fieldName, $default, $expectedValue)
 {
     $testClass = new AccessTestClass();
     $this->assertEquals($expectedValue, gs\getValue($testClass, $fieldName, $default));
     $getSetClass = new gs\GetSet();
     gs\setValue($getSetClass, 'a', new gs\GetSet());
     $this->assertInstanceOf('Revinate\\GetterSetter\\GetSet', gs\getValue($getSetClass, 'a'));
     $notFound = (object) array();
     $this->assertEquals($notFound, gs\getValue($getSetClass, 'b', $notFound));
     gs\setValue($getSetClass, 'b', null);
     $this->assertNull(gs\getValue($getSetClass, 'b', $notFound));
 }
Exemplo n.º 2
0
 public function testMagicMethods()
 {
     $data = new MagicAccessTestClass();
     $data->first_name = 'Joe';
     $data->last_name = 'Rock';
     gs\setValue($data, 'profession', 'Stone cutter');
     gs\setValue($data, 'address', new MagicAccessTestClass());
     gs\set($data, 'address.city', 'Little Rock');
     $this->assertEquals('Joe', gs\getValue($data, 'first_name'));
     $this->assertEquals('Rock', gs\get($data, 'last_name'));
     $this->assertEquals('Little Rock', gs\get($data, 'address.city'));
 }
Exemplo n.º 3
0
 /**
  * @param array|ArrayAccess|object $doc
  * @param string $fieldName
  * @param mixed $value
  * @return array|ArrayAccess|object
  */
 public static function setField($doc, $fieldName, $value)
 {
     return gs\setValue($doc, $fieldName, $value);
 }
 public function testSetNull()
 {
     $this->assertEquals(array('name' => array('first' => 'Joe')), gs\set(null, 'name.first', 'Joe'));
     $this->assertEquals(array('name.first' => 'Joe'), gs\setValue(null, 'name.first', 'Joe'));
 }
Exemplo n.º 5
0
 /**
  * @description Sets the value for the field $fieldName
  * @param array|object $data
  * @param string       $fieldName
  * @param mixed        $value
  * @return $this
  */
 public function setValue($data, $fieldName, $value)
 {
     return gs\setValue($data, $fieldName, $value);
 }