Add trait for reflection data
composer require gollumsf/reflection-property-test
use GollumSF\ReflectionPropertyTest\ReflectionPropertyTrait;
class MyPrivate {
private $dataPrivate = 10;
private function functionPrivate($value) {
return 11 + $value;
}
}
class MyExtend extends MyPrivate {
}
class MyTest extends TestCase {
use ReflectionPropertyTrait;
testMyFunction() {
$obj = new MyPrivate();
$this->assertEqual($this->reflectionGetValue($obj, 'reflectionGetValue'), 10);
$this->reflectionSetValue($obj, 'reflectionGetValue', 20);
$this->assertEqual($this->reflectionGetValue($obj, 'reflectionGetValue'), 20);
$this->assertEqual($this->reflectionGetValue($obj, 'functionPrivate', [ 19 ]), 30);
$obj2 = new MyExtend();
$this->assertEqual($this->reflectionGetValue($obj2, 'reflectionGetValue', MyPrivate::class), 10);
$this->reflectionSetValue($obj2, 'reflectionGetValue', 20, MyPrivate::class);
$this->assertEqual($this->reflectionGetValue($obj2, 'reflectionGetValue', MyPrivate::class), 20);
$this->assertEqual($this->reflectionGetValue($obj2, 'functionPrivate', [ 19 ], MyPrivate::class), 30);
}
}