wikimedia / testing-access-wrapper
A simple helper class to access non-public elements of a class when testing.
3.0.0
2023-11-28 06:57 UTC
Requires
- php: >=7.4
Requires (Dev)
- mediawiki/mediawiki-codesniffer: 41.0.0
- mediawiki/mediawiki-phan-config: 0.12.1
- mediawiki/minus-x: 1.1.1
- ockcyp/covers-validator: 1.6.0
- php-parallel-lint/php-console-highlighter: 1.0.0
- php-parallel-lint/php-parallel-lint: 1.3.2
- phpunit/phpunit: 9.5.28
This package is auto-updated.
Last update: 2024-11-03 20:22:58 UTC
README
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