Reflection - getPropertyValue() method - verify if getter is accessible publicly

This commit is contained in:
Meritoo
2017-09-27 17:00:25 +02:00
parent ffa3fbffe7
commit f9c480aa19
5 changed files with 139 additions and 8 deletions

View File

@@ -19,6 +19,7 @@ use Meritoo\Common\Test\Utilities\Reflection\B;
use Meritoo\Common\Test\Utilities\Reflection\C;
use Meritoo\Common\Test\Utilities\Reflection\D;
use Meritoo\Common\Test\Utilities\Reflection\E;
use Meritoo\Common\Test\Utilities\Reflection\F;
use Meritoo\Common\Utilities\Reflection;
use ReflectionProperty;
@@ -239,6 +240,31 @@ class ReflectionTest extends BaseTestCase
self::assertCount(2, Reflection::getProperties(B::class, null, true));
}
public function testGetPropertyValueWithPublicGetter()
{
$country = 'USA';
$f = new F(1000, 'New York', $country, 'john.scott');
self::assertEquals($country, Reflection::getPropertyValue($f, 'country'));
}
public function testGetPropertyValueWithProtectedGetter()
{
$city = 'New York';
$f = new F(1000, $city, 'USA', 'john.scott');
self::assertEquals($city, Reflection::getPropertyValue($f, 'city'));
}
public function testGetPropertyValueWithPrivateGetter()
{
$accountBalance = 1000;
$f = new F($accountBalance, 'New York', 'USA', 'john.scott');
self::assertEquals($accountBalance, Reflection::getPropertyValue($f, 'accountBalance'));
}
/**
* Provides invalid class and trait
*