A simple helper class to access non-public elements of a class when testing.

1.0.0 2017-04-19 16:43 UTC

This package is auto-updated.

Last update: 2020-09-09 14:32:18 UTC


Latest Stable Version License

Wikimedia Testing Access Wrapper

Testing Access Wrapper is a simple helper for writing unit tests which provides convenient shortcuts for using reflection to access non-public properties/methods.

The code was originally part of MediaWiki. See composer.json for a list of authors.


use Wikimedia\TestingAccessWrapper;

class NonPublic {
	protected $prop;
	protected const CONSTANT = 4;
	protected function func() {}
	protected static function staticFunc() {}

$object = new NonPublic();
$wrapper = TestingAccessWrapper::newFromObject( $object );
$classWrapper = TestingAccessWrapper::newFromClass( NonPublic::class );

$wrapper->prop = 'foo';

$value = TestingAccessWrapper::constant( NonPublic::class, 'CONSTANT' );

Running tests

composer install
composer test