testing-access-wrapper

From mediawiki.org

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

External links[edit]

See also[edit]

  • shell.php where the sudo command can be used to the same effect