testing-access-wrapper

testing-access-wrapper is a PHP library that provides convenient shortcuts for accessing protected or private properties and methods. It was designed to make unit tests easier to write and uses Reflection under the hood.

use Wikimedia\TestingAccessWrapper;

class NonPublic {
    protected $prop;
    protected function func() {}
    protected static function staticFunc() {}
}

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

$wrapper->prop = 'foo';
$wrapper->func();
$classWrapper->staticFunc();
edit

See also

edit
  • shell.php - a script where the sudo command can be used to take the same effect