diff --git a/Tests/Library/Utilities/TypeUtilitiesTest.php b/Tests/Library/Utilities/TypeUtilitiesTest.php index 5200f064..08b01ea1 100644 --- a/Tests/Library/Utilities/TypeUtilitiesTest.php +++ b/Tests/Library/Utilities/TypeUtilitiesTest.php @@ -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 { @@ -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')); + } } diff --git a/src/Type/TypeService.php b/src/Type/TypeService.php index be85a13e..c3f45954 100644 --- a/src/Type/TypeService.php +++ b/src/Type/TypeService.php @@ -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; }