gollumsf/reflection-property-test

Add trait for reflection data and call

Maintainers

Package info

github.com/GollumSF/reflection-property-test

Wiki

pkg:composer/gollumsf/reflection-property-test

Statistics

Installs: 3 543

Dependents: 6

Suggesters: 0

Stars: 1

Open Issues: 0

v2.0.0 2026-03-26 23:16 UTC

This package is auto-updated.

Last update: 2026-03-26 23:17:35 UTC


README

Build Status Coverage License Latest Stable Version Latest Unstable Version Discord

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

}