Skip to content

Commit

Permalink
Merge pull request #14 from roippi/master
Browse files Browse the repository at this point in the history
allow default typeservice to resolve public fields on objects
  • Loading branch information
viniychuk authored Jul 14, 2016
2 parents c79eb70 + 5241e24 commit d75e93f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
8 changes: 8 additions & 0 deletions Tests/Library/Utilities/TypeUtilitiesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use Youshido\GraphQL\Type\TypeService;
use Youshido\Tests\DataProvider\TestInterfaceType;
use Youshido\Tests\DataProvider\TestObjectType;
use Youshido\Tests\Library\Type\ObjectTypeTest;

class TypeUtilitiesTest extends \PHPUnit_Framework_TestCase
{
Expand Down Expand Up @@ -55,4 +56,11 @@ public function testIsAbstractType()
$this->assertFalse(TypeService::isAbstractType(new StringType()));
$this->assertFalse(TypeService::isAbstractType('invalid type'));
}

public function testGetPropertyValue() {
$arrayData = (new TestObjectType())->getData();

$this->assertEquals('John', TypeService::getPropertyValue($arrayData, 'name'));
$this->assertEquals('John', TypeService::getPropertyValue((object) $arrayData, 'name'));
}
}
2 changes: 1 addition & 1 deletion src/Type/TypeService.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ public static function getPropertyValue($data, $path)
$getter = 'get' . self::classify($path);
}

return is_callable([$data, $getter]) ? $data->$getter() : null;
return is_callable([$data, $getter]) ? $data->$getter() : (isset($data->$path) ? $data->$path : null);
} elseif (is_array($data)) {
return array_key_exists($path, $data) ? $data[$path] : null;
}
Expand Down

0 comments on commit d75e93f

Please sign in to comment.