gollumsf/reflection-property-test

Add trait for reflection data and call

v1.0.6 2022-05-02 14:58 UTC

This package is auto-updated.

Last update: 2024-03-01 00:10:18 UTC


README

Build Status Coverage License Latest Stable Version Latest Unstable Version Discord

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);
	}
	
}