wikimedia/testing-access-wrapper

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

Package info

github.com/wikimedia/testing-access-wrapper

Homepage

pkg:composer/wikimedia/testing-access-wrapper

Statistics

Installs: 2 249 703

Dependents: 13

Suggesters: 0

Stars: 4

4.0.0 2025-11-03 13:34 UTC

Requires

  • php: >=8.1

Suggests

None

Provides

None

Conflicts

None

Replaces

None

GPL-2.0-or-later 7b4ddeb6242c175156538221b451a3ec981b5be9

  • Adam Roses Wight <awight.woop@wikimedia.org>
  • Brad Jorsch <bjorsch.woop@wikimedia.org>
  • GergΕ‘ Tisza <gtisza.woop@wikimedia.org>

This package is auto-updated.

Last update: 2026-06-05 08:42:20 UTC


README

πŸ‘ 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.

Usage

use Wikimedia\TestingAccessWrapper;

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

class NonPublicCtor {
	protected function __construct() {}
}

$object = new NonPublic();
// or:
// $object = TestingAccessWrapper::construct( NonPublicCtor::class );

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

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

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

Running tests

composer install
composer test