MediaWiki REL1_28
TestingAccessWrapper Class Reference

Circumvent access restrictions on object internals. More...

Public Member Functions

 __call ( $method, $args)
 
 __get ( $name)
 
 __set ( $name, $value)
 

Static Public Member Functions

static newFromClass ( $className)
 Allow access to non-public static methods and properties of the class.
 
static newFromObject ( $object)
 Return the same object, without access restrictions.
 

Public Attributes

mixed $object
 The object, or the class name for static-only access.
 

Private Member Functions

 getMethod ( $name)
 Return a property and make it accessible.
 
 getProperty ( $name)
 Return a property and make it accessible.
 
 isStatic ()
 

Detailed Description

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 accomodate.

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

TODO:

  • Organize other helper classes in tests/testHelpers.inc into a directory.

Definition at line 17 of file TestingAccessWrapper.php.

Member Function Documentation

◆ __call()

TestingAccessWrapper::__call (   $method,
  $args 
)

Definition at line 46 of file TestingAccessWrapper.php.

References $args, getMethod(), and isStatic().

◆ __get()

TestingAccessWrapper::__get (   $name)

Definition at line 67 of file TestingAccessWrapper.php.

References $name, getProperty(), and isStatic().

◆ __set()

TestingAccessWrapper::__set (   $name,
  $value 
)

Definition at line 57 of file TestingAccessWrapper.php.

References $name, $value, getProperty(), and isStatic().

◆ getMethod()

TestingAccessWrapper::getMethod (   $name)
private

Return a property and make it accessible.

Parameters
string$name
Returns
ReflectionMethod

Definition at line 86 of file TestingAccessWrapper.php.

References $name.

Referenced by __call().

◆ getProperty()

TestingAccessWrapper::getProperty (   $name)
private

Return a property and make it accessible.

ReflectionClass::getProperty() fails if the private property is defined in a parent class. This works more like ReflectionClass::getMethod().

Parameters
string$name
Returns
ReflectionProperty
Exceptions
ReflectionException

Definition at line 103 of file TestingAccessWrapper.php.

References $name.

Referenced by __get(), and __set().

◆ isStatic()

TestingAccessWrapper::isStatic ( )
private

Definition at line 77 of file TestingAccessWrapper.php.

Referenced by __call(), __get(), and __set().

◆ newFromClass()

static TestingAccessWrapper::newFromClass (   $className)
static

Allow access to non-public static methods and properties of the class.

Use non-static access,

Definition at line 37 of file TestingAccessWrapper.php.

◆ newFromObject()

static TestingAccessWrapper::newFromObject (   $object)
static

Member Data Documentation

◆ $object

mixed TestingAccessWrapper::$object

The object, or the class name for static-only access.

Definition at line 19 of file TestingAccessWrapper.php.


The documentation for this class was generated from the following file: