aipng/test-helpers

Private properties trait useful for testing purposes

0.1 2018-11-22 09:01 UTC

This package is auto-updated.

Last update: 2024-12-22 21:59:18 UTC


README

PrivatePropertyTrait

Provides an easy way to set private property of an object using reflection.

Do not use in production, use only for testing purposes.

Example: MyClass.php

final class MyClass
{

	private $foo;

	// ...
}

MyClassTest.php

final class MyClassTest extends TestCase
{

	use PrivatePropertyTrait;


	public function testSetPrivateProperties(): void
    {
    	$object = new MyClass;

        $this->setPrivateProperties($object, [
			'foo' => 'bar',
		]);
		
		// ...
	}

}