gollumsf / reflection-property-test
Add trait for reflection data and call
Package info
github.com/GollumSF/reflection-property-test
pkg:composer/gollumsf/reflection-property-test
v2.0.0
2026-03-26 23:16 UTC
Requires
- php: >=8.2
Requires (Dev)
- doctrine/orm: ^2.14|^3.0
- phpunit/phpunit: ^11.0
README
Add trait for reflection data and call
Requirements
- PHP >= 8.2
Install:
composer require --dev gollumsf/reflection-property-test
Usage:
use GollumSF\ReflectionPropertyTest\ReflectionPropertyTrait; class MyPrivate { private int $dataPrivate = 10; private function functionPrivate(int $value): int { return 11 + $value; } } class MyExtend extends MyPrivate { } class MyTest extends TestCase { use ReflectionPropertyTrait; public function testMyFunction(): void { $obj = new MyPrivate(); $this->assertEquals($this->reflectionGetValue($obj, 'dataPrivate'), 10); $this->reflectionSetValue($obj, 'dataPrivate', 20); $this->assertEquals($this->reflectionGetValue($obj, 'dataPrivate'), 20); $this->assertEquals($this->reflectionCallMethod($obj, 'functionPrivate', [19]), 30); $obj2 = new MyExtend(); $this->assertEquals($this->reflectionGetValue($obj2, 'dataPrivate', MyPrivate::class), 10); $this->reflectionSetValue($obj2, 'dataPrivate', 20, MyPrivate::class); $this->assertEquals($this->reflectionGetValue($obj2, 'dataPrivate', MyPrivate::class), 20); $this->assertEquals($this->reflectionCallMethod($obj2, 'functionPrivate', [19], MyPrivate::class), 30); } }