gollumsf / reflection-property-test
Add trait for reflection data and call
Installs: 3 117
Dependents: 5
Suggesters: 0
Security: 0
Stars: 1
Watchers: 2
Forks: 0
Open Issues: 0
Requires (Dev)
- doctrine/orm: *
- phpunit/phpunit: ^8.5
README
Add trait for reflection data
Install:
composer require gollumsf/reflection-property-test
Usage:
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); } }