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: 2020-03-22 12:02:15 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',
		]);
		
		// ...
	}

}