testing-access-wrapper
Simple unit test helper for accessing non-public properties/methods.
|
Circumvent access restrictions on object internals. More...
Public Member Functions | |
__call ( $method, $args) | |
__set ( $name, $value) | |
__get ( $name) | |
Static Public Member Functions | |
static | newFromObject ( $object) |
Return a proxy object which can be used the same way as the original, except that access restrictions can be ignored (protected and private methods and properties are available for any caller). | |
static | newFromClass ( $className) |
Allow access to non-public static methods and properties of the class. | |
static | constant ( $className, $constantName) |
Allow access to non-public constants of the class. | |
static | construct (string $className,... $args) |
Allow constructing a class with a non-public constructor. | |
Public Attributes | |
$object | |
Circumvent access restrictions on object internals.
This can be helpful for writing tests that can probe object internals, without having to modify the class under test to accommodate.
Wrap an object with private methods as follows: $title = TestingAccessWrapper::newFromObject( Title::newFromDBkey( $key ) );
You can access private and protected instance methods and variables: $formatter = $title->getTitleFormatter();
You can access private and protected constants: $value = TestingAccessWrapper::constant( Foo::class, 'FOO_CONSTANT' );
Wikimedia\TestingAccessWrapper::__call | ( | $method, | |
$args ) |
string | $method | |
array | $args |
Wikimedia\TestingAccessWrapper::__get | ( | $name | ) |
string | $name | Field name |
Wikimedia\TestingAccessWrapper::__set | ( | $name, | |
$value ) |
string | $name | |
mixed | $value |
|
static |
Allow access to non-public constants of the class.
class-string | $className | |
string | $constantName |
|
static |
Allow constructing a class with a non-public constructor.
class-string<T> | $className |
mixed | ...$args |
|
static |
Allow access to non-public static methods and properties of the class.
Returns an object whose methods/properties will correspond to the static methods/properties of the given class.
class-string | $className |
InvalidArgumentException |
|
static |
Return a proxy object which can be used the same way as the original, except that access restrictions can be ignored (protected and private methods and properties are available for any caller).
object | $object |
InvalidArgumentException |