testing-access-wrapper/en
Appearance
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
- Source code (Phabricator mirror, GitHub mirror)
- Composer package
- API Documentation
- Test coverage report
See also
- shell.php - a script where the
sudo
command can be used to take the same effect