X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=tests%2Fphpunit%2Fincludes%2FTestingAccessWrapper.php;h=76a426692d8ab90db6dfb7474e03b56f997c022f;hb=e91875e1eb2e2b3a9b14a56828e1f033a3b47182;hp=63d897198b6da804127e377533bb6ec6a9749f5a;hpb=ac17fbac94f2ba72b3ac64fff2dd188dd76faaf3;p=lhc%2Fweb%2Fwiklou.git diff --git a/tests/phpunit/includes/TestingAccessWrapper.php b/tests/phpunit/includes/TestingAccessWrapper.php index 63d897198b..76a426692d 100644 --- a/tests/phpunit/includes/TestingAccessWrapper.php +++ b/tests/phpunit/includes/TestingAccessWrapper.php @@ -2,75 +2,10 @@ /** * 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. + * Kept around for backwards compatibility. * - * 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: - * - Provide access to static methods and properties. - * - Organize other helper classes in tests/testHelpers.inc into a directory. + * @deprecated Use \Wikimedia\TestingAccessWrapper (proveded by the + * wikimedia/testing-access-wrapper Composer library) */ -class TestingAccessWrapper { - public $object; - - /** - * Return the same object, without access restrictions. - */ - public static function newFromObject( $object ) { - $wrapper = new TestingAccessWrapper(); - $wrapper->object = $object; - return $wrapper; - } - - public function __call( $method, $args ) { - $classReflection = new ReflectionClass( $this->object ); - $methodReflection = $classReflection->getMethod( $method ); - $methodReflection->setAccessible( true ); - return $methodReflection->invokeArgs( $this->object, $args ); - } - - /** - * ReflectionClass::getProperty() fails if the private property is defined - * in a parent class. This works more like ReflectionClass::getMethod(). - */ - private function getProperty( $name ) { - $classReflection = new ReflectionClass( $this->object ); - try { - return $classReflection->getProperty( $name ); - } catch ( ReflectionException $ex ) { - while ( true ) { - $classReflection = $classReflection->getParentClass(); - if ( !$classReflection ) { - throw $ex; - } - try { - $propertyReflection = $classReflection->getProperty( $name ); - } catch ( ReflectionException $ex2 ) { - continue; - } - if ( $propertyReflection->isPrivate() ) { - return $propertyReflection; - } else { - throw $ex; - } - } - } - } - - public function __set( $name, $value ) { - $propertyReflection = $this->getProperty( $name ); - $propertyReflection->setAccessible( true ); - $propertyReflection->setValue( $this->object, $value ); - } - - public function __get( $name ) { - $propertyReflection = $this->getProperty( $name ); - $propertyReflection->setAccessible( true ); - return $propertyReflection->getValue( $this->object ); - } +class TestingAccessWrapper extends \Wikimedia\TestingAccessWrapper { }