From: Gergő Tisza Date: Wed, 19 Apr 2017 19:37:35 +0000 (+0000) Subject: Switch to librarized version of TestingAccessWrapper X-Git-Tag: 1.31.0-rc.0~3453^2 X-Git-Url: http://git.cyclocoop.org/?a=commitdiff_plain;h=525bfbc8df855aa12e01868d92532cd64482dc7d;p=lhc%2Fweb%2Fwiklou.git Switch to librarized version of TestingAccessWrapper Replaces \TestingAccessWrapper (defined in core) with \Wikimedia\TestingAccessWrapper (defined in the composer package wikimedia/testing-access-wrapper). See https://gerrit.wikimedia.org/r/#/q/topic:librarize-testing-access-wrapper for downstream patches. The core version of the class is kept around for a while to avoid circular dependency problems. Bug: T163434 Change-Id: I52cc257e593da3d6c3b01a909e554a950225aec8 --- diff --git a/composer.json b/composer.json index 36fd0ee0ef..be8ce1507e 100644 --- a/composer.json +++ b/composer.json @@ -49,18 +49,19 @@ }, "require-dev": { "composer/spdx-licenses": "1.1.4", + "hamcrest/hamcrest-php": "^2.0", "jakub-onderka/php-parallel-lint": "0.9.2", + "jetbrains/phpstorm-stubs": "dev-master#1b9906084d6635456fcf3f3a01f0d7d5b99a578a", "justinrainbow/json-schema": "~3.0", "mediawiki/mediawiki-codesniffer": "0.7.2", - "jetbrains/phpstorm-stubs": "dev-master#1b9906084d6635456fcf3f3a01f0d7d5b99a578a", "monolog/monolog": "~1.22.1", "nikic/php-parser": "2.1.0", "nmred/kafka-php": "0.1.5", "phpunit/phpunit": "4.8.35", + "psy/psysh": "0.8.3", "wikimedia/avro": "1.7.7", - "hamcrest/hamcrest-php": "^2.0", - "wmde/hamcrest-html-matchers": "^0.1.0", - "psy/psysh": "0.8.3" + "wikimedia/testing-access-wrapper": "~1.0", + "wmde/hamcrest-html-matchers": "^0.1.0" }, "suggest": { "ext-apc": "Local data and opcode cache", diff --git a/tests/integration/includes/http/MWHttpRequestTestCase.php b/tests/integration/includes/http/MWHttpRequestTestCase.php index 6d1fdf56d5..545769681d 100644 --- a/tests/integration/includes/http/MWHttpRequestTestCase.php +++ b/tests/integration/includes/http/MWHttpRequestTestCase.php @@ -1,5 +1,7 @@ privateParentProperty = 9000; - } - - private function incrementPrivateParentPropertyValue() { - $this->privateParentProperty++; - } - - public function getPrivateParentProperty() { - return $this->privateParentProperty; - } -} - -class WellProtectedClass extends WellProtectedParentClass { - protected static $staticProperty = 'sp'; - private static $staticPrivateProperty = 'spp'; - - protected $property; - private $privateProperty; - - protected static function staticMethod() { - return 'sm'; - } - - private static function staticPrivateMethod() { - return 'spm'; - } - - public function __construct() { - parent::__construct(); - $this->property = 1; - $this->privateProperty = 42; - } - - protected function incrementPropertyValue() { - $this->property++; - } - - private function incrementPrivatePropertyValue() { - $this->privateProperty++; - } - - public function getProperty() { - return $this->property; - } - - public function getPrivateProperty() { - return $this->privateProperty; - } - - protected function whatSecondArg( $a, $b = false ) { - return $b; - } -} diff --git a/tests/phpunit/includes/MessageTest.php b/tests/phpunit/includes/MessageTest.php index 58087c1826..912bffe645 100644 --- a/tests/phpunit/includes/MessageTest.php +++ b/tests/phpunit/includes/MessageTest.php @@ -1,5 +1,6 @@ getTitleFormatter(); - * - * TODO: - * - 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 { - /** @var mixed The object, or the class name for static-only access */ - public $object; - - /** - * Return the same object, without access restrictions. - */ - public static function newFromObject( $object ) { - if ( !is_object( $object ) ) { - throw new InvalidArgumentException( __METHOD__ . ' must be called with an object' ); - } - $wrapper = new TestingAccessWrapper(); - $wrapper->object = $object; - return $wrapper; - } - - /** - * Allow access to non-public static methods and properties of the class. - * Use non-static access, - */ - public static function newFromClass( $className ) { - if ( !is_string( $className ) ) { - throw new InvalidArgumentException( __METHOD__ . ' must be called with a class name' ); - } - $wrapper = new TestingAccessWrapper(); - $wrapper->object = $className; - return $wrapper; - } - - public function __call( $method, $args ) { - $methodReflection = $this->getMethod( $method ); - - if ( $this->isStatic() && !$methodReflection->isStatic() ) { - throw new DomainException( __METHOD__ . ': Cannot call non-static when wrapping static class' ); - } - - return $methodReflection->invokeArgs( $methodReflection->isStatic() ? null : $this->object, - $args ); - } - - public function __set( $name, $value ) { - $propertyReflection = $this->getProperty( $name ); - - if ( $this->isStatic() && !$propertyReflection->isStatic() ) { - throw new DomainException( __METHOD__ . ': Cannot set property when wrapping static class' ); - } - - $propertyReflection->setValue( $this->object, $value ); - } - - public function __get( $name ) { - $propertyReflection = $this->getProperty( $name ); - - if ( $this->isStatic() && !$propertyReflection->isStatic() ) { - throw new DomainException( __METHOD__ . ': Cannot get property when wrapping static class' ); - } - - return $propertyReflection->getValue( $this->object ); - } - - private function isStatic() { - return is_string( $this->object ); - } - - /** - * Return a property and make it accessible. - * @param string $name - * @return ReflectionMethod - */ - private function getMethod( $name ) { - $classReflection = new ReflectionClass( $this->object ); - $methodReflection = $classReflection->getMethod( $name ); - $methodReflection->setAccessible( true ); - return $methodReflection; - } - - /** - * 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(). - * - * @param string $name - * @return ReflectionProperty - * @throws ReflectionException - */ - private function getProperty( $name ) { - $classReflection = new ReflectionClass( $this->object ); - try { - $propertyReflection = $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() ) { - break; - } else { - throw $ex; - } - } - } - $propertyReflection->setAccessible( true ); - return $propertyReflection; - } +class TestingAccessWrapper extends \Wikimedia\TestingAccessWrapper { } diff --git a/tests/phpunit/includes/TestingAccessWrapperTest.php b/tests/phpunit/includes/TestingAccessWrapperTest.php deleted file mode 100644 index 23eb023ab9..0000000000 --- a/tests/phpunit/includes/TestingAccessWrapperTest.php +++ /dev/null @@ -1,119 +0,0 @@ -raw = new WellProtectedClass(); - $this->wrapped = TestingAccessWrapper::newFromObject( $this->raw ); - $this->wrappedStatic = TestingAccessWrapper::newFromClass( 'WellProtectedClass' ); - } - - /** - * @expectedException InvalidArgumentException - */ - function testConstructorException() { - TestingAccessWrapper::newFromObject( 'WellProtectedClass' ); - } - - /** - * @expectedException InvalidArgumentException - */ - function testStaticConstructorException() { - TestingAccessWrapper::newFromClass( new WellProtectedClass() ); - } - - function testGetProperty() { - $this->assertSame( 1, $this->wrapped->property ); - $this->assertSame( 42, $this->wrapped->privateProperty ); - $this->assertSame( 9000, $this->wrapped->privateParentProperty ); - $this->assertSame( 'sp', $this->wrapped->staticProperty ); - $this->assertSame( 'spp', $this->wrapped->staticPrivateProperty ); - $this->assertSame( 'sp', $this->wrappedStatic->staticProperty ); - $this->assertSame( 'spp', $this->wrappedStatic->staticPrivateProperty ); - } - - /** - * @expectedException DomainException - */ - function testGetException() { - $this->wrappedStatic->property; - } - - function testSetProperty() { - $this->wrapped->property = 10; - $this->assertSame( 10, $this->wrapped->property ); - $this->assertSame( 10, $this->raw->getProperty() ); - - $this->wrapped->privateProperty = 11; - $this->assertSame( 11, $this->wrapped->privateProperty ); - $this->assertSame( 11, $this->raw->getPrivateProperty() ); - - $this->wrapped->privateParentProperty = 12; - $this->assertSame( 12, $this->wrapped->privateParentProperty ); - $this->assertSame( 12, $this->raw->getPrivateParentProperty() ); - - $this->wrapped->staticProperty = 'x'; - $this->assertSame( 'x', $this->wrapped->staticProperty ); - $this->assertSame( 'x', $this->wrappedStatic->staticProperty ); - - $this->wrapped->staticPrivateProperty = 'y'; - $this->assertSame( 'y', $this->wrapped->staticPrivateProperty ); - $this->assertSame( 'y', $this->wrappedStatic->staticPrivateProperty ); - - $this->wrappedStatic->staticProperty = 'X'; - $this->assertSame( 'X', $this->wrapped->staticProperty ); - $this->assertSame( 'X', $this->wrappedStatic->staticProperty ); - - $this->wrappedStatic->staticPrivateProperty = 'Y'; - $this->assertSame( 'Y', $this->wrapped->staticPrivateProperty ); - $this->assertSame( 'Y', $this->wrappedStatic->staticPrivateProperty ); - - // don't rely on PHPUnit to restore static properties - $this->wrapped->staticProperty = 'sp'; - $this->wrapped->staticPrivateProperty = 'spp'; - } - - /** - * @expectedException DomainException - */ - function testSetException() { - $this->wrappedStatic->property = 1; - } - - function testCallMethod() { - $this->wrapped->incrementPropertyValue(); - $this->assertSame( 2, $this->wrapped->property ); - $this->assertSame( 2, $this->raw->getProperty() ); - - $this->wrapped->incrementPrivatePropertyValue(); - $this->assertSame( 43, $this->wrapped->privateProperty ); - $this->assertSame( 43, $this->raw->getPrivateProperty() ); - - $this->wrapped->incrementPrivateParentPropertyValue(); - $this->assertSame( 9001, $this->wrapped->privateParentProperty ); - $this->assertSame( 9001, $this->raw->getPrivateParentProperty() ); - - $this->assertSame( 'sm', $this->wrapped->staticMethod() ); - $this->assertSame( 'spm', $this->wrapped->staticPrivateMethod() ); - $this->assertSame( 'sm', $this->wrappedStatic->staticMethod() ); - $this->assertSame( 'spm', $this->wrappedStatic->staticPrivateMethod() ); - } - - function testCallMethodTwoArgs() { - $this->assertSame( 'two', $this->wrapped->whatSecondArg( 'one', 'two' ) ); - } - - /** - * @expectedException DomainException - */ - function testCallMethodException() { - $this->wrappedStatic->incrementPropertyValue(); - } - -} diff --git a/tests/phpunit/includes/WatchedItemQueryServiceUnitTest.php b/tests/phpunit/includes/WatchedItemQueryServiceUnitTest.php index 76d1cb9401..872c580fa8 100644 --- a/tests/phpunit/includes/WatchedItemQueryServiceUnitTest.php +++ b/tests/phpunit/includes/WatchedItemQueryServiceUnitTest.php @@ -1,5 +1,7 @@ getMockForAbstractClass( AbstractAuthenticationProvider::class ); - $providerPriv = \TestingAccessWrapper::newFromObject( $provider ); + $providerPriv = TestingAccessWrapper::newFromObject( $provider ); $obj = $this->getMockForAbstractClass( 'Psr\Log\LoggerInterface' ); $provider->setLogger( $obj ); diff --git a/tests/phpunit/includes/auth/AbstractPasswordPrimaryAuthenticationProviderTest.php b/tests/phpunit/includes/auth/AbstractPasswordPrimaryAuthenticationProviderTest.php index a57682b66e..76d8ee933b 100644 --- a/tests/phpunit/includes/auth/AbstractPasswordPrimaryAuthenticationProviderTest.php +++ b/tests/phpunit/includes/auth/AbstractPasswordPrimaryAuthenticationProviderTest.php @@ -3,6 +3,7 @@ namespace MediaWiki\Auth; use MediaWiki\MediaWikiServices; +use Wikimedia\TestingAccessWrapper; /** * @group AuthManager @@ -13,14 +14,14 @@ class AbstractPasswordPrimaryAuthenticationProviderTest extends \MediaWikiTestCa $provider = $this->getMockForAbstractClass( AbstractPasswordPrimaryAuthenticationProvider::class ); - $providerPriv = \TestingAccessWrapper::newFromObject( $provider ); + $providerPriv = TestingAccessWrapper::newFromObject( $provider ); $this->assertTrue( $providerPriv->authoritative ); $provider = $this->getMockForAbstractClass( AbstractPasswordPrimaryAuthenticationProvider::class, [ [ 'authoritative' => false ] ] ); - $providerPriv = \TestingAccessWrapper::newFromObject( $provider ); + $providerPriv = TestingAccessWrapper::newFromObject( $provider ); $this->assertFalse( $providerPriv->authoritative ); } @@ -29,7 +30,7 @@ class AbstractPasswordPrimaryAuthenticationProviderTest extends \MediaWikiTestCa AbstractPasswordPrimaryAuthenticationProvider::class ); $provider->setConfig( MediaWikiServices::getInstance()->getMainConfig() ); - $providerPriv = \TestingAccessWrapper::newFromObject( $provider ); + $providerPriv = TestingAccessWrapper::newFromObject( $provider ); $obj = $providerPriv->getPasswordFactory(); $this->assertInstanceOf( 'PasswordFactory', $obj ); @@ -42,7 +43,7 @@ class AbstractPasswordPrimaryAuthenticationProviderTest extends \MediaWikiTestCa ); $provider->setConfig( MediaWikiServices::getInstance()->getMainConfig() ); $provider->setLogger( new \Psr\Log\NullLogger() ); - $providerPriv = \TestingAccessWrapper::newFromObject( $provider ); + $providerPriv = TestingAccessWrapper::newFromObject( $provider ); $obj = $providerPriv->getPassword( null ); $this->assertInstanceOf( 'Password', $obj ); @@ -61,7 +62,7 @@ class AbstractPasswordPrimaryAuthenticationProviderTest extends \MediaWikiTestCa MediaWikiServices::getInstance()->getMainConfig() ] ) ); $provider->setLogger( new \Psr\Log\NullLogger() ); - $providerPriv = \TestingAccessWrapper::newFromObject( $provider ); + $providerPriv = TestingAccessWrapper::newFromObject( $provider ); $this->mergeMwGlobalArrayValue( 'wgHooks', [ 'ResetPasswordExpiration' => [] ] ); @@ -109,7 +110,7 @@ class AbstractPasswordPrimaryAuthenticationProviderTest extends \MediaWikiTestCa ); $provider->setConfig( MediaWikiServices::getInstance()->getMainConfig() ); $provider->setLogger( new \Psr\Log\NullLogger() ); - $providerPriv = \TestingAccessWrapper::newFromObject( $provider ); + $providerPriv = TestingAccessWrapper::newFromObject( $provider ); $this->assertEquals( $uppStatus, $providerPriv->checkPasswordValidity( 'foo', 'bar' ) ); @@ -133,7 +134,7 @@ class AbstractPasswordPrimaryAuthenticationProviderTest extends \MediaWikiTestCa $provider->setConfig( $config ); $provider->setLogger( new \Psr\Log\NullLogger() ); $provider->setManager( $manager ); - $providerPriv = \TestingAccessWrapper::newFromObject( $provider ); + $providerPriv = TestingAccessWrapper::newFromObject( $provider ); $manager->removeAuthenticationSessionData( null ); $status = \Status::newGood(); @@ -161,7 +162,7 @@ class AbstractPasswordPrimaryAuthenticationProviderTest extends \MediaWikiTestCa AbstractPasswordPrimaryAuthenticationProvider::class, [ [ 'authoritative' => false ] ] ); - $providerPriv = \TestingAccessWrapper::newFromObject( $provider ); + $providerPriv = TestingAccessWrapper::newFromObject( $provider ); $req = new PasswordAuthenticationRequest; @@ -172,7 +173,7 @@ class AbstractPasswordPrimaryAuthenticationProviderTest extends \MediaWikiTestCa AbstractPasswordPrimaryAuthenticationProvider::class, [ [ 'authoritative' => true ] ] ); - $providerPriv = \TestingAccessWrapper::newFromObject( $provider ); + $providerPriv = TestingAccessWrapper::newFromObject( $provider ); $req->password = ''; $ret = $providerPriv->failResponse( $req ); diff --git a/tests/phpunit/includes/auth/AuthManagerTest.php b/tests/phpunit/includes/auth/AuthManagerTest.php index 5c268f84cf..e8ef3ae5d2 100644 --- a/tests/phpunit/includes/auth/AuthManagerTest.php +++ b/tests/phpunit/includes/auth/AuthManagerTest.php @@ -7,6 +7,7 @@ use MediaWiki\Session\UserInfo; use Psr\Log\LogLevel; use StatusValue; use Wikimedia\ScopedCallback; +use Wikimedia\TestingAccessWrapper; /** * @group AuthManager @@ -127,7 +128,7 @@ class AuthManagerTest extends \MediaWikiTestCase { } $this->manager = new AuthManager( $this->request, $this->config ); $this->manager->setLogger( $this->logger ); - $this->managerPriv = \TestingAccessWrapper::newFromObject( $this->manager ); + $this->managerPriv = TestingAccessWrapper::newFromObject( $this->manager ); } /** @@ -170,7 +171,7 @@ class AuthManagerTest extends \MediaWikiTestCase { 'logger' => new \Psr\Log\NullLogger(), 'store' => new \HashBagOStuff(), ] ); - \TestingAccessWrapper::newFromObject( $manager )->getProvider( (string)$provider ); + TestingAccessWrapper::newFromObject( $manager )->getProvider( (string)$provider ); $reset = \MediaWiki\Session\TestUtils::setSessionManagerSingleton( $manager ); @@ -196,7 +197,7 @@ class AuthManagerTest extends \MediaWikiTestCase { $this->assertSame( \RequestContext::getMain()->getRequest(), $singleton->getRequest() ); $this->assertSame( \RequestContext::getMain()->getConfig(), - \TestingAccessWrapper::newFromObject( $singleton )->config + TestingAccessWrapper::newFromObject( $singleton )->config ); } diff --git a/tests/phpunit/includes/auth/CheckBlocksSecondaryAuthenticationProviderTest.php b/tests/phpunit/includes/auth/CheckBlocksSecondaryAuthenticationProviderTest.php index 68f574b6b4..111c855445 100644 --- a/tests/phpunit/includes/auth/CheckBlocksSecondaryAuthenticationProviderTest.php +++ b/tests/phpunit/includes/auth/CheckBlocksSecondaryAuthenticationProviderTest.php @@ -2,6 +2,8 @@ namespace MediaWiki\Auth; +use Wikimedia\TestingAccessWrapper; + /** * @group AuthManager * @group Database @@ -10,7 +12,7 @@ namespace MediaWiki\Auth; class CheckBlocksSecondaryAuthenticationProviderTest extends \MediaWikiTestCase { public function testConstructor() { $provider = new CheckBlocksSecondaryAuthenticationProvider(); - $providerPriv = \TestingAccessWrapper::newFromObject( $provider ); + $providerPriv = TestingAccessWrapper::newFromObject( $provider ); $config = new \HashConfig( [ 'BlockDisablesLogin' => false ] ); @@ -20,7 +22,7 @@ class CheckBlocksSecondaryAuthenticationProviderTest extends \MediaWikiTestCase $provider = new CheckBlocksSecondaryAuthenticationProvider( [ 'blockDisablesLogin' => true ] ); - $providerPriv = \TestingAccessWrapper::newFromObject( $provider ); + $providerPriv = TestingAccessWrapper::newFromObject( $provider ); $config = new \HashConfig( [ 'BlockDisablesLogin' => false ] ); diff --git a/tests/phpunit/includes/auth/ConfirmLinkSecondaryAuthenticationProviderTest.php b/tests/phpunit/includes/auth/ConfirmLinkSecondaryAuthenticationProviderTest.php index 3fc45a4671..9222843c17 100644 --- a/tests/phpunit/includes/auth/ConfirmLinkSecondaryAuthenticationProviderTest.php +++ b/tests/phpunit/includes/auth/ConfirmLinkSecondaryAuthenticationProviderTest.php @@ -2,6 +2,8 @@ namespace MediaWiki\Auth; +use Wikimedia\TestingAccessWrapper; + /** * @group AuthManager * @covers MediaWiki\Auth\ConfirmLinkSecondaryAuthenticationProvider @@ -126,7 +128,7 @@ class ConfirmLinkSecondaryAuthenticationProviderTest extends \MediaWikiTestCase ->will( $this->returnValue( "BadReq" ) ); $user = \User::newFromName( 'UTSysop' ); - $provider = \TestingAccessWrapper::newFromObject( + $provider = TestingAccessWrapper::newFromObject( new ConfirmLinkSecondaryAuthenticationProvider ); $request = new \FauxRequest(); @@ -171,7 +173,7 @@ class ConfirmLinkSecondaryAuthenticationProviderTest extends \MediaWikiTestCase $r->action = AuthManager::ACTION_CHANGE; $r->username = $user->getName(); } - $this->assertEquals( $expectReqs, \TestingAccessWrapper::newFromObject( $req )->linkRequests ); + $this->assertEquals( $expectReqs, TestingAccessWrapper::newFromObject( $req )->linkRequests ); } public function testContinueLinkAttempt() { @@ -190,7 +192,7 @@ class ConfirmLinkSecondaryAuthenticationProviderTest extends \MediaWikiTestCase ->will( $this->returnValue( $obj ) ); $this->assertSame( $obj, - \TestingAccessWrapper::newFromObject( $mock )->continueLinkAttempt( $user, 'state', $reqs ) + TestingAccessWrapper::newFromObject( $mock )->continueLinkAttempt( $user, 'state', $reqs ) ); // Now test the actual functioning @@ -224,7 +226,7 @@ class ConfirmLinkSecondaryAuthenticationProviderTest extends \MediaWikiTestCase $request = new \FauxRequest(); $manager = new AuthManager( $request, $config ); $provider->setManager( $manager ); - $provider = \TestingAccessWrapper::newFromObject( $provider ); + $provider = TestingAccessWrapper::newFromObject( $provider ); $req = new ConfirmLinkAuthenticationRequest( $reqs ); diff --git a/tests/phpunit/includes/auth/EmailNotificationSecondaryAuthenticationProviderTest.php b/tests/phpunit/includes/auth/EmailNotificationSecondaryAuthenticationProviderTest.php index ca6689a9ca..3757069e34 100644 --- a/tests/phpunit/includes/auth/EmailNotificationSecondaryAuthenticationProviderTest.php +++ b/tests/phpunit/includes/auth/EmailNotificationSecondaryAuthenticationProviderTest.php @@ -3,6 +3,7 @@ namespace MediaWiki\Auth; use Psr\Log\LoggerInterface; +use Wikimedia\TestingAccessWrapper; class EmailNotificationSecondaryAuthenticationProviderTest extends \PHPUnit_Framework_TestCase { public function testConstructor() { @@ -13,14 +14,14 @@ class EmailNotificationSecondaryAuthenticationProviderTest extends \PHPUnit_Fram $provider = new EmailNotificationSecondaryAuthenticationProvider(); $provider->setConfig( $config ); - $providerPriv = \TestingAccessWrapper::newFromObject( $provider ); + $providerPriv = TestingAccessWrapper::newFromObject( $provider ); $this->assertTrue( $providerPriv->sendConfirmationEmail ); $provider = new EmailNotificationSecondaryAuthenticationProvider( [ 'sendConfirmationEmail' => false, ] ); $provider->setConfig( $config ); - $providerPriv = \TestingAccessWrapper::newFromObject( $provider ); + $providerPriv = TestingAccessWrapper::newFromObject( $provider ); $this->assertFalse( $providerPriv->sendConfirmationEmail ); } diff --git a/tests/phpunit/includes/auth/LocalPasswordPrimaryAuthenticationProviderTest.php b/tests/phpunit/includes/auth/LocalPasswordPrimaryAuthenticationProviderTest.php index 6e2058c485..b89f1e02e4 100644 --- a/tests/phpunit/includes/auth/LocalPasswordPrimaryAuthenticationProviderTest.php +++ b/tests/phpunit/includes/auth/LocalPasswordPrimaryAuthenticationProviderTest.php @@ -3,6 +3,7 @@ namespace MediaWiki\Auth; use MediaWiki\MediaWikiServices; +use Wikimedia\TestingAccessWrapper; /** * @group AuthManager @@ -131,7 +132,7 @@ class LocalPasswordPrimaryAuthenticationProviderTest extends \MediaWikiTestCase $provider->setConfig( $this->config ); $provider->setLogger( new \Psr\Log\NullLogger() ); $provider->setManager( $this->manager ); - $providerPriv = \TestingAccessWrapper::newFromObject( $provider ); + $providerPriv = TestingAccessWrapper::newFromObject( $provider ); $user = $this->getMutableTestUser()->getUser(); $userName = $user->getName(); diff --git a/tests/phpunit/includes/auth/RememberMeAuthenticationRequestTest.php b/tests/phpunit/includes/auth/RememberMeAuthenticationRequestTest.php index 3f90169cac..9bcab77738 100644 --- a/tests/phpunit/includes/auth/RememberMeAuthenticationRequestTest.php +++ b/tests/phpunit/includes/auth/RememberMeAuthenticationRequestTest.php @@ -2,6 +2,8 @@ namespace MediaWiki\Auth; +use Wikimedia\TestingAccessWrapper; + /** * @group AuthManager * @covers MediaWiki\Auth\RememberMeAuthenticationRequest @@ -17,7 +19,7 @@ class RememberMeAuthenticationRequestTest extends AuthenticationRequestTestCase public function testGetFieldInfo_2() { $req = new RememberMeAuthenticationRequest(); - $reqWrapper = \TestingAccessWrapper::newFromObject( $req ); + $reqWrapper = TestingAccessWrapper::newFromObject( $req ); $reqWrapper->expiration = 30 * 24 * 3600; $this->assertNotEmpty( $req->getFieldInfo() ); @@ -28,7 +30,7 @@ class RememberMeAuthenticationRequestTest extends AuthenticationRequestTestCase protected function getInstance( array $args = [] ) { $req = new RememberMeAuthenticationRequest(); - $reqWrapper = \TestingAccessWrapper::newFromObject( $req ); + $reqWrapper = TestingAccessWrapper::newFromObject( $req ); $reqWrapper->expiration = $args[0]; return $req; } diff --git a/tests/phpunit/includes/auth/ResetPasswordSecondaryAuthenticationProviderTest.php b/tests/phpunit/includes/auth/ResetPasswordSecondaryAuthenticationProviderTest.php index 90ed54274d..f454a96abc 100644 --- a/tests/phpunit/includes/auth/ResetPasswordSecondaryAuthenticationProviderTest.php +++ b/tests/phpunit/includes/auth/ResetPasswordSecondaryAuthenticationProviderTest.php @@ -2,6 +2,8 @@ namespace MediaWiki\Auth; +use Wikimedia\TestingAccessWrapper; + /** * @group AuthManager * @covers MediaWiki\Auth\ResetPasswordSecondaryAuthenticationProvider @@ -85,7 +87,7 @@ class ResetPasswordSecondaryAuthenticationProviderTest extends \MediaWikiTestCas ] ); $manager = new AuthManager( new \FauxRequest, $config ); $provider->setManager( $manager ); - $provider = \TestingAccessWrapper::newFromObject( $provider ); + $provider = TestingAccessWrapper::newFromObject( $provider ); $msg = wfMessage( 'foo' ); $skipReq = new ButtonAuthenticationRequest( diff --git a/tests/phpunit/includes/auth/TemporaryPasswordPrimaryAuthenticationProviderTest.php b/tests/phpunit/includes/auth/TemporaryPasswordPrimaryAuthenticationProviderTest.php index 8d9509e9a1..6f45fa49dc 100644 --- a/tests/phpunit/includes/auth/TemporaryPasswordPrimaryAuthenticationProviderTest.php +++ b/tests/phpunit/includes/auth/TemporaryPasswordPrimaryAuthenticationProviderTest.php @@ -4,6 +4,7 @@ namespace MediaWiki\Auth; use MediaWiki\MediaWikiServices; use Wikimedia\ScopedCallback; +use Wikimedia\TestingAccessWrapper; /** * @group AuthManager @@ -106,13 +107,13 @@ class TemporaryPasswordPrimaryAuthenticationProviderTest extends \MediaWikiTestC 'PasswordReminderResendTime' => 101, ] ); - $p = \TestingAccessWrapper::newFromObject( new TemporaryPasswordPrimaryAuthenticationProvider() ); + $p = TestingAccessWrapper::newFromObject( new TemporaryPasswordPrimaryAuthenticationProvider() ); $p->setConfig( $config ); $this->assertSame( false, $p->emailEnabled ); $this->assertSame( 100, $p->newPasswordExpiry ); $this->assertSame( 101, $p->passwordReminderResendTime ); - $p = \TestingAccessWrapper::newFromObject( new TemporaryPasswordPrimaryAuthenticationProvider( [ + $p = TestingAccessWrapper::newFromObject( new TemporaryPasswordPrimaryAuthenticationProvider( [ 'emailEnabled' => true, 'newPasswordExpiry' => 42, 'passwordReminderResendTime' => 43, @@ -135,7 +136,7 @@ class TemporaryPasswordPrimaryAuthenticationProviderTest extends \MediaWikiTestC $pwhash = $passwordFactory->newFromPlaintext( 'password' )->toString(); $provider = $this->getProvider(); - $providerPriv = \TestingAccessWrapper::newFromObject( $provider ); + $providerPriv = TestingAccessWrapper::newFromObject( $provider ); $this->assertFalse( $provider->testUserCanAuthenticate( '' ) ); $this->assertFalse( $provider->testUserCanAuthenticate( 'DoesNotExist' ) ); @@ -249,7 +250,7 @@ class TemporaryPasswordPrimaryAuthenticationProviderTest extends \MediaWikiTestC $reqs = [ PasswordAuthenticationRequest::class => $req ]; $provider = $this->getProvider(); - $providerPriv = \TestingAccessWrapper::newFromObject( $provider ); + $providerPriv = TestingAccessWrapper::newFromObject( $provider ); $providerPriv->newPasswordExpiry = 100; @@ -573,7 +574,7 @@ class TemporaryPasswordPrimaryAuthenticationProviderTest extends \MediaWikiTestC ScopedCallback::consume( $resetMailer ); $this->assertTrue( $mailed ); - $priv = \TestingAccessWrapper::newFromObject( $provider ); + $priv = TestingAccessWrapper::newFromObject( $provider ); $req->username = ''; $status = $priv->sendPasswordResetEmail( $req ); $this->assertEquals( \Status::newFatal( 'noname' ), $status ); diff --git a/tests/phpunit/includes/auth/ThrottlePreAuthenticationProviderTest.php b/tests/phpunit/includes/auth/ThrottlePreAuthenticationProviderTest.php index ee8283288a..58982de220 100644 --- a/tests/phpunit/includes/auth/ThrottlePreAuthenticationProviderTest.php +++ b/tests/phpunit/includes/auth/ThrottlePreAuthenticationProviderTest.php @@ -2,6 +2,8 @@ namespace MediaWiki\Auth; +use Wikimedia\TestingAccessWrapper; + /** * @group AuthManager * @group Database @@ -10,7 +12,7 @@ namespace MediaWiki\Auth; class ThrottlePreAuthenticationProviderTest extends \MediaWikiTestCase { public function testConstructor() { $provider = new ThrottlePreAuthenticationProvider(); - $providerPriv = \TestingAccessWrapper::newFromObject( $provider ); + $providerPriv = TestingAccessWrapper::newFromObject( $provider ); $config = new \HashConfig( [ 'AccountCreationThrottle' => [ [ 'count' => 123, @@ -26,11 +28,11 @@ class ThrottlePreAuthenticationProviderTest extends \MediaWikiTestCase { 'accountCreationThrottle' => [ [ 'count' => 123, 'seconds' => 86400 ] ], 'passwordAttemptThrottle' => [ [ 'count' => 5, 'seconds' => 300 ] ] ], $providerPriv->throttleSettings ); - $accountCreationThrottle = \TestingAccessWrapper::newFromObject( + $accountCreationThrottle = TestingAccessWrapper::newFromObject( $providerPriv->accountCreationThrottle ); $this->assertSame( [ [ 'count' => 123, 'seconds' => 86400 ] ], $accountCreationThrottle->conditions ); - $passwordAttemptThrottle = \TestingAccessWrapper::newFromObject( + $passwordAttemptThrottle = TestingAccessWrapper::newFromObject( $providerPriv->passwordAttemptThrottle ); $this->assertSame( [ [ 'count' => 5, 'seconds' => 300 ] ], $passwordAttemptThrottle->conditions ); @@ -39,7 +41,7 @@ class ThrottlePreAuthenticationProviderTest extends \MediaWikiTestCase { 'accountCreationThrottle' => [ [ 'count' => 43, 'seconds' => 10000 ] ], 'passwordAttemptThrottle' => [ [ 'count' => 11, 'seconds' => 100 ] ], ] ); - $providerPriv = \TestingAccessWrapper::newFromObject( $provider ); + $providerPriv = TestingAccessWrapper::newFromObject( $provider ); $config = new \HashConfig( [ 'AccountCreationThrottle' => [ [ 'count' => 123, @@ -58,15 +60,15 @@ class ThrottlePreAuthenticationProviderTest extends \MediaWikiTestCase { $cache = new \HashBagOStuff(); $provider = new ThrottlePreAuthenticationProvider( [ 'cache' => $cache ] ); - $providerPriv = \TestingAccessWrapper::newFromObject( $provider ); + $providerPriv = TestingAccessWrapper::newFromObject( $provider ); $provider->setConfig( new \HashConfig( [ 'AccountCreationThrottle' => [ [ 'count' => 1, 'seconds' => 1 ] ], 'PasswordAttemptThrottle' => [ [ 'count' => 1, 'seconds' => 1 ] ], ] ) ); - $accountCreationThrottle = \TestingAccessWrapper::newFromObject( + $accountCreationThrottle = TestingAccessWrapper::newFromObject( $providerPriv->accountCreationThrottle ); $this->assertSame( $cache, $accountCreationThrottle->cache ); - $passwordAttemptThrottle = \TestingAccessWrapper::newFromObject( + $passwordAttemptThrottle = TestingAccessWrapper::newFromObject( $providerPriv->passwordAttemptThrottle ); $this->assertSame( $cache, $passwordAttemptThrottle->cache ); } diff --git a/tests/phpunit/includes/auth/ThrottlerTest.php b/tests/phpunit/includes/auth/ThrottlerTest.php index 33c8ce6e10..f52048adc4 100644 --- a/tests/phpunit/includes/auth/ThrottlerTest.php +++ b/tests/phpunit/includes/auth/ThrottlerTest.php @@ -8,6 +8,7 @@ use InvalidArgumentException; use Psr\Log\AbstractLogger; use Psr\Log\LoggerInterface; use Psr\Log\NullLogger; +use Wikimedia\TestingAccessWrapper; /** * @group AuthManager @@ -25,7 +26,7 @@ class ThrottlerTest extends \MediaWikiTestCase { [ 'type' => 'foo', 'cache' => $cache ] ); $throttler->setLogger( $logger ); - $throttlerPriv = \TestingAccessWrapper::newFromObject( $throttler ); + $throttlerPriv = TestingAccessWrapper::newFromObject( $throttler ); $this->assertSame( [ [ 'count' => 123, 'seconds' => 456 ] ], $throttlerPriv->conditions ); $this->assertSame( 'foo', $throttlerPriv->type ); $this->assertSame( $cache, $throttlerPriv->cache ); @@ -33,7 +34,7 @@ class ThrottlerTest extends \MediaWikiTestCase { $throttler = new Throttler( [ [ 'count' => 123, 'seconds' => 456 ] ] ); $throttler->setLogger( new NullLogger() ); - $throttlerPriv = \TestingAccessWrapper::newFromObject( $throttler ); + $throttlerPriv = TestingAccessWrapper::newFromObject( $throttler ); $this->assertSame( [ [ 'count' => 123, 'seconds' => 456 ] ], $throttlerPriv->conditions ); $this->assertSame( 'custom', $throttlerPriv->type ); $this->assertInstanceOf( BagOStuff::class, $throttlerPriv->cache ); @@ -43,7 +44,7 @@ class ThrottlerTest extends \MediaWikiTestCase { 'seconds' => 654 ] ] ] ); $throttler = new Throttler(); $throttler->setLogger( new NullLogger() ); - $throttlerPriv = \TestingAccessWrapper::newFromObject( $throttler ); + $throttlerPriv = TestingAccessWrapper::newFromObject( $throttler ); $this->assertSame( [ [ 'count' => 321, 'seconds' => 654 ] ], $throttlerPriv->conditions ); $this->assertSame( 'password', $throttlerPriv->type ); $this->assertInstanceOf( BagOStuff::class, $throttlerPriv->cache ); @@ -63,7 +64,7 @@ class ThrottlerTest extends \MediaWikiTestCase { public function testNormalizeThrottleConditions( $condition, $normalized ) { $throttler = new Throttler( $condition ); $throttler->setLogger( new NullLogger() ); - $throttlerPriv = \TestingAccessWrapper::newFromObject( $throttler ); + $throttlerPriv = TestingAccessWrapper::newFromObject( $throttler ); $this->assertSame( $normalized, $throttlerPriv->conditions ); } @@ -85,7 +86,7 @@ class ThrottlerTest extends \MediaWikiTestCase { } public function testNormalizeThrottleConditions2() { - $priv = \TestingAccessWrapper::newFromClass( Throttler::class ); + $priv = TestingAccessWrapper::newFromClass( Throttler::class ); $this->assertSame( [], $priv->normalizeThrottleConditions( null ) ); $this->assertSame( [], $priv->normalizeThrottleConditions( 'bad' ) ); } diff --git a/tests/phpunit/includes/changes/ChangesListBooleanFilterGroupTest.php b/tests/phpunit/includes/changes/ChangesListBooleanFilterGroupTest.php index a30702f480..07dec055cb 100644 --- a/tests/phpunit/includes/changes/ChangesListBooleanFilterGroupTest.php +++ b/tests/phpunit/includes/changes/ChangesListBooleanFilterGroupTest.php @@ -1,5 +1,7 @@ method( 'send' ) ->will( $this->returnValue( true ) ); // evil hax - \TestingAccessWrapper::newFromObject( $mockMethod )->matcher->parametersMatcher = + TestingAccessWrapper::newFromObject( $mockMethod )->matcher->parametersMatcher = new \PHPUnit_Framework_MockObject_Matcher_ConsecutiveParameters( [ [ $this->anything(), $this->anything(), [ 'words' ] ], [ $this->anything(), $this->anything(), [ 'lines' ] ] diff --git a/tests/phpunit/includes/debug/logger/monolog/LineFormatterTest.php b/tests/phpunit/includes/debug/logger/monolog/LineFormatterTest.php index f33cf7e05d..2768d32939 100644 --- a/tests/phpunit/includes/debug/logger/monolog/LineFormatterTest.php +++ b/tests/phpunit/includes/debug/logger/monolog/LineFormatterTest.php @@ -24,7 +24,7 @@ use InvalidArgumentException; use LengthException; use LogicException; use MediaWikiTestCase; -use TestingAccessWrapper; +use Wikimedia\TestingAccessWrapper; class LineFormatterTest extends MediaWikiTestCase { diff --git a/tests/phpunit/includes/deferred/CdnCacheUpdateTest.php b/tests/phpunit/includes/deferred/CdnCacheUpdateTest.php index b96ec08551..11b869a7db 100644 --- a/tests/phpunit/includes/deferred/CdnCacheUpdateTest.php +++ b/tests/phpunit/includes/deferred/CdnCacheUpdateTest.php @@ -1,5 +1,7 @@ setMwGlobals( 'wgCommandLineMode', false ); diff --git a/tests/phpunit/includes/filebackend/FileBackendTest.php b/tests/phpunit/includes/filebackend/FileBackendTest.php index f77720653f..ddcf19bde6 100644 --- a/tests/phpunit/includes/filebackend/FileBackendTest.php +++ b/tests/phpunit/includes/filebackend/FileBackendTest.php @@ -1,5 +1,7 @@ 40 ] ); - $priv = \TestingAccessWrapper::newFromObject( $provider ); + $priv = TestingAccessWrapper::newFromObject( $provider ); $this->assertSame( 40, $priv->priority ); $this->assertSame( '_BPsession', $priv->sessionCookieName ); $this->assertSame( [], $priv->sessionCookieOptions ); @@ -136,7 +137,7 @@ class BotPasswordSessionProviderTest extends MediaWikiTestCase { 'priority' => 40, 'sessionCookieName' => null, ] ); - $priv = \TestingAccessWrapper::newFromObject( $provider ); + $priv = TestingAccessWrapper::newFromObject( $provider ); $this->assertSame( '_BPsession', $priv->sessionCookieName ); $provider = new BotPasswordSessionProvider( [ @@ -144,7 +145,7 @@ class BotPasswordSessionProviderTest extends MediaWikiTestCase { 'sessionCookieName' => 'Foo', 'sessionCookieOptions' => [ 'Bar' ], ] ); - $priv = \TestingAccessWrapper::newFromObject( $provider ); + $priv = TestingAccessWrapper::newFromObject( $provider ); $this->assertSame( 'Foo', $priv->sessionCookieName ); $this->assertSame( [ 'Bar' ], $priv->sessionCookieOptions ); } @@ -289,7 +290,7 @@ class BotPasswordSessionProviderTest extends MediaWikiTestCase { $provider->setLogger( $logger ); $backend = TestUtils::getDummySessionBackend(); - $backendPriv = \TestingAccessWrapper::newFromObject( $backend ); + $backendPriv = TestingAccessWrapper::newFromObject( $backend ); try { $provider->getAllowedUserRights( $backend ); diff --git a/tests/phpunit/includes/session/CookieSessionProviderTest.php b/tests/phpunit/includes/session/CookieSessionProviderTest.php index 73485c828c..a47fd9a18b 100644 --- a/tests/phpunit/includes/session/CookieSessionProviderTest.php +++ b/tests/phpunit/includes/session/CookieSessionProviderTest.php @@ -5,6 +5,7 @@ namespace MediaWiki\Session; use MediaWikiTestCase; use User; use Psr\Log\LogLevel; +use Wikimedia\TestingAccessWrapper; /** * @group Session @@ -76,7 +77,7 @@ class CookieSessionProviderTest extends MediaWikiTestCase { } $config = $this->getConfig(); - $p = \TestingAccessWrapper::newFromObject( + $p = TestingAccessWrapper::newFromObject( new CookieSessionProvider( [ 'priority' => 1 ] ) ); $p->setLogger( new \TestLogger() ); @@ -95,7 +96,7 @@ class CookieSessionProviderTest extends MediaWikiTestCase { ], $p->cookieOptions ); $config->set( 'SessionName', 'SessionName' ); - $p = \TestingAccessWrapper::newFromObject( + $p = TestingAccessWrapper::newFromObject( new CookieSessionProvider( [ 'priority' => 3 ] ) ); $p->setLogger( new \TestLogger() ); @@ -113,7 +114,7 @@ class CookieSessionProviderTest extends MediaWikiTestCase { 'httpOnly' => true, ], $p->cookieOptions ); - $p = \TestingAccessWrapper::newFromObject( new CookieSessionProvider( [ + $p = TestingAccessWrapper::newFromObject( new CookieSessionProvider( [ 'priority' => 10, 'callUserSetCookiesHook' => true, 'cookieOptions' => [ @@ -151,7 +152,7 @@ class CookieSessionProviderTest extends MediaWikiTestCase { $this->assertEquals( $extendedCookies, - \TestingAccessWrapper::newFromObject( $provider )->getExtendedLoginCookies(), + TestingAccessWrapper::newFromObject( $provider )->getExtendedLoginCookies(), 'List of extended cookies (subclasses can add values, but we\'re calling the core one here)' ); @@ -412,7 +413,7 @@ class CookieSessionProviderTest extends MediaWikiTestCase { new \Psr\Log\NullLogger(), 10 ); - \TestingAccessWrapper::newFromObject( $backend )->usePhpSessionHandling = false; + TestingAccessWrapper::newFromObject( $backend )->usePhpSessionHandling = false; $mock = $this->getMockBuilder( 'stdClass' ) ->setMethods( [ 'onUserSetCookies' ] ) @@ -499,7 +500,7 @@ class CookieSessionProviderTest extends MediaWikiTestCase { new \Psr\Log\NullLogger(), 10 ); - \TestingAccessWrapper::newFromObject( $backend )->usePhpSessionHandling = false; + TestingAccessWrapper::newFromObject( $backend )->usePhpSessionHandling = false; $backend->setUser( $user ); $backend->setRememberUser( $remember ); $backend->setForceHTTPS( $secure ); @@ -604,7 +605,7 @@ class CookieSessionProviderTest extends MediaWikiTestCase { new \Psr\Log\NullLogger(), 10 ); - \TestingAccessWrapper::newFromObject( $backend )->usePhpSessionHandling = false; + TestingAccessWrapper::newFromObject( $backend )->usePhpSessionHandling = false; // Anonymous user $mock = $this->getMockBuilder( 'stdClass' ) @@ -736,7 +737,7 @@ class CookieSessionProviderTest extends MediaWikiTestCase { } public function testSetLoggedOutCookie() { - $provider = \TestingAccessWrapper::newFromObject( new CookieSessionProvider( [ + $provider = TestingAccessWrapper::newFromObject( new CookieSessionProvider( [ 'priority' => 1, 'sessionName' => 'MySessionName', 'cookieOptions' => [ 'prefix' => 'x' ], @@ -783,7 +784,7 @@ class CookieSessionProviderTest extends MediaWikiTestCase { $provider->setLogger( new \Psr\Log\NullLogger() ); $provider->setConfig( $this->getConfig() ); $provider->setManager( SessionManager::singleton() ); - $provider = \TestingAccessWrapper::newFromObject( $provider ); + $provider = TestingAccessWrapper::newFromObject( $provider ); $request = new \FauxRequest(); $request->setCookies( [ @@ -815,7 +816,7 @@ class CookieSessionProviderTest extends MediaWikiTestCase { public function testGetLoginCookieExpiration() { $config = $this->getConfig(); - $provider = \TestingAccessWrapper::newFromObject( new CookieSessionProvider( [ + $provider = TestingAccessWrapper::newFromObject( new CookieSessionProvider( [ 'priority' => 10 ] ) ); $provider->setLogger( new \Psr\Log\NullLogger() ); diff --git a/tests/phpunit/includes/session/ImmutableSessionProviderWithCookieTest.php b/tests/phpunit/includes/session/ImmutableSessionProviderWithCookieTest.php index 7ef230e269..086fa28bde 100644 --- a/tests/phpunit/includes/session/ImmutableSessionProviderWithCookieTest.php +++ b/tests/phpunit/includes/session/ImmutableSessionProviderWithCookieTest.php @@ -4,6 +4,7 @@ namespace MediaWiki\Session; use MediaWikiTestCase; use User; +use Wikimedia\TestingAccessWrapper; /** * @group Session @@ -37,7 +38,7 @@ class ImmutableSessionProviderWithCookieTest extends MediaWikiTestCase { public function testConstructor() { $provider = $this->getMockBuilder( ImmutableSessionProviderWithCookie::class ) ->getMockForAbstractClass(); - $priv = \TestingAccessWrapper::newFromObject( $provider ); + $priv = TestingAccessWrapper::newFromObject( $provider ); $this->assertNull( $priv->sessionCookieName ); $this->assertSame( [], $priv->sessionCookieOptions ); @@ -47,7 +48,7 @@ class ImmutableSessionProviderWithCookieTest extends MediaWikiTestCase { 'sessionCookieOptions' => [ 'Bar' ], ] ] ) ->getMockForAbstractClass(); - $priv = \TestingAccessWrapper::newFromObject( $provider ); + $priv = TestingAccessWrapper::newFromObject( $provider ); $this->assertSame( 'Foo', $priv->sessionCookieName ); $this->assertSame( [ 'Bar' ], $priv->sessionCookieOptions ); @@ -119,7 +120,7 @@ class ImmutableSessionProviderWithCookieTest extends MediaWikiTestCase { 'bad' => 'bad', ], '' ); - $provider = \TestingAccessWrapper::newFromObject( $this->getProvider( null ) ); + $provider = TestingAccessWrapper::newFromObject( $this->getProvider( null ) ); try { $provider->getSessionIdFromCookie( $request ); $this->fail( 'Expected exception not thrown' ); @@ -131,28 +132,28 @@ class ImmutableSessionProviderWithCookieTest extends MediaWikiTestCase { ); } - $provider = \TestingAccessWrapper::newFromObject( $this->getProvider( 'Foo' ) ); + $provider = TestingAccessWrapper::newFromObject( $this->getProvider( 'Foo' ) ); $this->assertSame( 'wgfoo---------------------------', $provider->getSessionIdFromCookie( $request ) ); - $provider = \TestingAccessWrapper::newFromObject( $this->getProvider( 'Foo', 'Bar' ) ); + $provider = TestingAccessWrapper::newFromObject( $this->getProvider( 'Foo', 'Bar' ) ); $this->assertSame( 'foobar--------------------------', $provider->getSessionIdFromCookie( $request ) ); - $provider = \TestingAccessWrapper::newFromObject( $this->getProvider( 'Foo', '' ) ); + $provider = TestingAccessWrapper::newFromObject( $this->getProvider( 'Foo', '' ) ); $this->assertSame( 'foo-----------------------------', $provider->getSessionIdFromCookie( $request ) ); - $provider = \TestingAccessWrapper::newFromObject( $this->getProvider( 'bad', '' ) ); + $provider = TestingAccessWrapper::newFromObject( $this->getProvider( 'bad', '' ) ); $this->assertSame( null, $provider->getSessionIdFromCookie( $request ) ); - $provider = \TestingAccessWrapper::newFromObject( $this->getProvider( 'none', '' ) ); + $provider = TestingAccessWrapper::newFromObject( $this->getProvider( 'none', '' ) ); $this->assertSame( null, $provider->getSessionIdFromCookie( $request ) ); } @@ -185,7 +186,7 @@ class ImmutableSessionProviderWithCookieTest extends MediaWikiTestCase { $provider = $this->getProvider( 'session' ); $provider->setLogger( new \Psr\Log\NullLogger() ); - $priv = \TestingAccessWrapper::newFromObject( $provider ); + $priv = TestingAccessWrapper::newFromObject( $provider ); $priv->sessionCookieOptions = [ 'prefix' => 'x', 'path' => 'CookiePath', @@ -211,7 +212,7 @@ class ImmutableSessionProviderWithCookieTest extends MediaWikiTestCase { new \Psr\Log\NullLogger(), 10 ); - \TestingAccessWrapper::newFromObject( $backend )->usePhpSessionHandling = false; + TestingAccessWrapper::newFromObject( $backend )->usePhpSessionHandling = false; $backend->setRememberUser( $remember ); $backend->setForceHTTPS( $secure ); @@ -281,7 +282,7 @@ class ImmutableSessionProviderWithCookieTest extends MediaWikiTestCase { public function testUnpersistSession() { $provider = $this->getProvider( 'session', '' ); $provider->setLogger( new \Psr\Log\NullLogger() ); - $priv = \TestingAccessWrapper::newFromObject( $provider ); + $priv = TestingAccessWrapper::newFromObject( $provider ); // No cookie $priv->sessionCookieName = null; diff --git a/tests/phpunit/includes/session/PHPSessionHandlerTest.php b/tests/phpunit/includes/session/PHPSessionHandlerTest.php index 34e5e449a3..0a2e84e11a 100644 --- a/tests/phpunit/includes/session/PHPSessionHandlerTest.php +++ b/tests/phpunit/includes/session/PHPSessionHandlerTest.php @@ -4,6 +4,7 @@ namespace MediaWiki\Session; use Psr\Log\LogLevel; use MediaWikiTestCase; +use Wikimedia\TestingAccessWrapper; /** * @group Session @@ -26,7 +27,7 @@ class PHPSessionHandlerTest extends MediaWikiTestCase { $rProp = new \ReflectionProperty( PHPSessionHandler::class, 'instance' ); $rProp->setAccessible( true ); if ( $rProp->getValue() ) { - $old = \TestingAccessWrapper::newFromObject( $rProp->getValue() ); + $old = TestingAccessWrapper::newFromObject( $rProp->getValue() ); $oldManager = $old->manager; $oldStore = $old->store; $oldLogger = $old->logger; @@ -40,7 +41,7 @@ class PHPSessionHandlerTest extends MediaWikiTestCase { } public function testEnableFlags() { - $handler = \TestingAccessWrapper::newFromObject( + $handler = TestingAccessWrapper::newFromObject( $this->getMockBuilder( PHPSessionHandler::class ) ->setMethods( null ) ->disableOriginalConstructor() @@ -93,7 +94,7 @@ class PHPSessionHandlerTest extends MediaWikiTestCase { $this->assertFalse( wfIniGetBool( 'session.use_trans_sid' ) ); $this->assertNotNull( $rProp->getValue() ); - $priv = \TestingAccessWrapper::newFromObject( $rProp->getValue() ); + $priv = TestingAccessWrapper::newFromObject( $rProp->getValue() ); $this->assertSame( $manager, $priv->manager ); $this->assertSame( $store, $priv->store ); $this->assertSame( $logger, $priv->logger ); @@ -122,7 +123,7 @@ class PHPSessionHandlerTest extends MediaWikiTestCase { 'logger' => $logger, ] ); PHPSessionHandler::install( $manager ); - $wrap = \TestingAccessWrapper::newFromObject( $rProp->getValue() ); + $wrap = TestingAccessWrapper::newFromObject( $rProp->getValue() ); $reset[] = new \Wikimedia\ScopedCallback( [ $wrap, 'setEnableFlags' ], [ $wrap->enable ? $wrap->warn ? 'warn' : 'enable' : 'disable' ] @@ -323,7 +324,7 @@ class PHPSessionHandlerTest extends MediaWikiTestCase { ->setMethods( null ) ->disableOriginalConstructor() ->getMock(); - \TestingAccessWrapper::newFromObject( $handler )->setEnableFlags( 'disable' ); + TestingAccessWrapper::newFromObject( $handler )->setEnableFlags( 'disable' ); $oldValue = $rProp->getValue(); $rProp->setValue( $handler ); $reset = new \Wikimedia\ScopedCallback( [ $rProp, 'setValue' ], [ $oldValue ] ); @@ -350,7 +351,7 @@ class PHPSessionHandlerTest extends MediaWikiTestCase { ->setMethods( null ) ->disableOriginalConstructor() ->getMock(); - \TestingAccessWrapper::newFromObject( $handler )->setEnableFlags( 'enable' ); + TestingAccessWrapper::newFromObject( $handler )->setEnableFlags( 'enable' ); call_user_func_array( [ $handler, $method ], $args ); } diff --git a/tests/phpunit/includes/session/SessionBackendTest.php b/tests/phpunit/includes/session/SessionBackendTest.php index 4a28f7ae1d..0d345dbbdb 100644 --- a/tests/phpunit/includes/session/SessionBackendTest.php +++ b/tests/phpunit/includes/session/SessionBackendTest.php @@ -4,6 +4,7 @@ namespace MediaWiki\Session; use MediaWikiTestCase; use User; +use Wikimedia\TestingAccessWrapper; /** * @group Session @@ -61,13 +62,13 @@ class SessionBackendTest extends MediaWikiTestCase { $id = new SessionId( $info->getId() ); $backend = new SessionBackend( $id, $info, $this->store, $logger, 10 ); - $priv = \TestingAccessWrapper::newFromObject( $backend ); + $priv = TestingAccessWrapper::newFromObject( $backend ); $priv->persist = false; $priv->requests = [ 100 => new \FauxRequest() ]; $priv->requests[100]->setSessionId( $id ); $priv->usePhpSessionHandling = false; - $manager = \TestingAccessWrapper::newFromObject( $this->manager ); + $manager = TestingAccessWrapper::newFromObject( $this->manager ); $manager->allSessionBackends = [ $backend->getId() => $backend ] + $manager->allSessionBackends; $manager->allSessionIds = [ $backend->getId() => $id ] + $manager->allSessionIds; $manager->sessionProviders = [ (string)$this->provider => $this->provider ]; @@ -168,16 +169,16 @@ class SessionBackendTest extends MediaWikiTestCase { $this->assertSame( $info->wasPersisted(), $backend->isPersistent() ); $this->assertSame( $info->wasRemembered(), $backend->shouldRememberUser() ); $this->assertSame( $info->forceHTTPS(), $backend->shouldForceHTTPS() ); - $this->assertSame( $expire, \TestingAccessWrapper::newFromObject( $backend )->expires ); + $this->assertSame( $expire, TestingAccessWrapper::newFromObject( $backend )->expires ); $this->assertSame( [ 'foo' ], $backend->getProviderMetadata() ); } public function testSessionStuff() { $backend = $this->getBackend(); - $priv = \TestingAccessWrapper::newFromObject( $backend ); + $priv = TestingAccessWrapper::newFromObject( $backend ); $priv->requests = []; // Remove dummy session - $manager = \TestingAccessWrapper::newFromObject( $this->manager ); + $manager = TestingAccessWrapper::newFromObject( $this->manager ); $request1 = new \FauxRequest(); $session1 = $backend->getSession( $request1 ); @@ -188,7 +189,7 @@ class SessionBackendTest extends MediaWikiTestCase { $this->assertInstanceOf( Session::class, $session2 ); $this->assertSame( 2, count( $priv->requests ) ); - $index = \TestingAccessWrapper::newFromObject( $session1 )->index; + $index = TestingAccessWrapper::newFromObject( $session1 )->index; $this->assertSame( $request1, $backend->getRequest( $index ) ); $this->assertSame( null, $backend->suggestLoginUsername( $index ) ); @@ -220,7 +221,7 @@ class SessionBackendTest extends MediaWikiTestCase { public function testSetProviderMetadata() { $backend = $this->getBackend(); - $priv = \TestingAccessWrapper::newFromObject( $backend ); + $priv = TestingAccessWrapper::newFromObject( $backend ); $priv->providerMetadata = [ 'dummy' ]; try { @@ -265,7 +266,7 @@ class SessionBackendTest extends MediaWikiTestCase { ->will( $this->returnValue( false ) ); $this->provider->expects( $this->never() )->method( 'sessionIdWasReset' ); $backend = $this->getBackend( User::newFromName( 'UTSysop' ) ); - $manager = \TestingAccessWrapper::newFromObject( $this->manager ); + $manager = TestingAccessWrapper::newFromObject( $this->manager ); $sessionId = $backend->getSessionId(); $backend->resetId(); $this->assertSame( self::SESSIONID, $backend->getId() ); @@ -279,7 +280,7 @@ class SessionBackendTest extends MediaWikiTestCase { $backend = $this->getBackend(); $this->provider->expects( $this->once() )->method( 'sessionIdWasReset' ) ->with( $this->identicalTo( $backend ), $this->identicalTo( self::SESSIONID ) ); - $manager = \TestingAccessWrapper::newFromObject( $this->manager ); + $manager = TestingAccessWrapper::newFromObject( $this->manager ); $sessionId = $backend->getSessionId(); $backend->resetId(); $this->assertNotEquals( self::SESSIONID, $backend->getId() ); @@ -305,7 +306,7 @@ class SessionBackendTest extends MediaWikiTestCase { $this->provider = null; $backend = $this->getBackend(); - $wrap = \TestingAccessWrapper::newFromObject( $backend ); + $wrap = TestingAccessWrapper::newFromObject( $backend ); $wrap->persist = true; $wrap->expires = 0; $backend->persist(); @@ -317,7 +318,7 @@ class SessionBackendTest extends MediaWikiTestCase { ->setMethods( [ 'unpersistSession' ] )->getMock(); $this->provider->expects( $this->once() )->method( 'unpersistSession' ); $backend = $this->getBackend(); - $wrap = \TestingAccessWrapper::newFromObject( $backend ); + $wrap = TestingAccessWrapper::newFromObject( $backend ); $wrap->store = new \CachedBagOStuff( $this->store ); $wrap->persist = true; $wrap->dataDirty = true; @@ -391,7 +392,7 @@ class SessionBackendTest extends MediaWikiTestCase { public function testDirty() { $backend = $this->getBackend(); - $priv = \TestingAccessWrapper::newFromObject( $backend ); + $priv = TestingAccessWrapper::newFromObject( $backend ); $priv->dataDirty = false; $backend->dirty(); $this->assertTrue( $priv->dataDirty ); @@ -401,7 +402,7 @@ class SessionBackendTest extends MediaWikiTestCase { $backend = $this->getBackend(); $data = $backend->getData(); $this->assertSame( [], $data ); - $this->assertTrue( \TestingAccessWrapper::newFromObject( $backend )->dataDirty ); + $this->assertTrue( TestingAccessWrapper::newFromObject( $backend )->dataDirty ); $data['???'] = '!!!'; $this->assertSame( [ '???' => '!!!' ], $data ); @@ -409,12 +410,12 @@ class SessionBackendTest extends MediaWikiTestCase { $this->store->setSessionData( self::SESSIONID, $testData ); $backend = $this->getBackend(); $this->assertSame( $testData, $backend->getData() ); - $this->assertFalse( \TestingAccessWrapper::newFromObject( $backend )->dataDirty ); + $this->assertFalse( TestingAccessWrapper::newFromObject( $backend )->dataDirty ); } public function testAddData() { $backend = $this->getBackend(); - $priv = \TestingAccessWrapper::newFromObject( $backend ); + $priv = TestingAccessWrapper::newFromObject( $backend ); $priv->data = [ 'foo' => 1 ]; $priv->dataDirty = false; @@ -438,7 +439,7 @@ class SessionBackendTest extends MediaWikiTestCase { public function testDelaySave() { $this->mergeMwGlobalArrayValue( 'wgHooks', [ 'SessionMetadata' => [ $this ] ] ); $backend = $this->getBackend(); - $priv = \TestingAccessWrapper::newFromObject( $backend ); + $priv = TestingAccessWrapper::newFromObject( $backend ); $priv->persist = true; // Saves happen normally when no delay is in effect @@ -509,8 +510,8 @@ class SessionBackendTest extends MediaWikiTestCase { $backend = $this->getBackend( $user ); $this->store->deleteSession( self::SESSIONID ); $this->assertFalse( $backend->isPersistent(), 'sanity check' ); - \TestingAccessWrapper::newFromObject( $backend )->metaDirty = false; - \TestingAccessWrapper::newFromObject( $backend )->dataDirty = false; + TestingAccessWrapper::newFromObject( $backend )->metaDirty = false; + TestingAccessWrapper::newFromObject( $backend )->dataDirty = false; $backend->save(); $this->assertFalse( $this->store->getSession( self::SESSIONID ), 'making sure it didn\'t save' ); @@ -522,11 +523,11 @@ class SessionBackendTest extends MediaWikiTestCase { $this->store->setSessionData( self::SESSIONID, $testData ); $backend = $this->getBackend( $user ); $this->store->deleteSession( self::SESSIONID ); - \TestingAccessWrapper::newFromObject( $backend )->persist = false; - \TestingAccessWrapper::newFromObject( $backend )->forcePersist = true; + TestingAccessWrapper::newFromObject( $backend )->persist = false; + TestingAccessWrapper::newFromObject( $backend )->forcePersist = true; $this->assertFalse( $backend->isPersistent(), 'sanity check' ); - \TestingAccessWrapper::newFromObject( $backend )->metaDirty = false; - \TestingAccessWrapper::newFromObject( $backend )->dataDirty = false; + TestingAccessWrapper::newFromObject( $backend )->metaDirty = false; + TestingAccessWrapper::newFromObject( $backend )->dataDirty = false; $backend->save(); $this->assertFalse( $this->store->getSession( self::SESSIONID ), 'making sure it didn\'t save' ); @@ -535,14 +536,14 @@ class SessionBackendTest extends MediaWikiTestCase { $this->mergeMwGlobalArrayValue( 'wgHooks', [ 'SessionMetadata' => [ $neverHook ] ] ); $this->store->setSessionData( self::SESSIONID, $testData ); $backend = $this->getBackend( $user ); - \TestingAccessWrapper::newFromObject( $backend )->requests[100] + TestingAccessWrapper::newFromObject( $backend )->requests[100] ->setSessionId( new SessionId( 'x' ) ); $this->store->deleteSession( self::SESSIONID ); - \TestingAccessWrapper::newFromObject( $backend )->persist = false; - \TestingAccessWrapper::newFromObject( $backend )->forcePersist = true; + TestingAccessWrapper::newFromObject( $backend )->persist = false; + TestingAccessWrapper::newFromObject( $backend )->forcePersist = true; $this->assertFalse( $backend->isPersistent(), 'sanity check' ); - \TestingAccessWrapper::newFromObject( $backend )->metaDirty = false; - \TestingAccessWrapper::newFromObject( $backend )->dataDirty = false; + TestingAccessWrapper::newFromObject( $backend )->metaDirty = false; + TestingAccessWrapper::newFromObject( $backend )->dataDirty = false; $backend->save(); $this->assertFalse( $this->store->getSession( self::SESSIONID ), 'making sure it didn\'t save' ); @@ -554,8 +555,8 @@ class SessionBackendTest extends MediaWikiTestCase { $backend = $this->getBackend( $user ); $this->store->deleteSession( self::SESSIONID ); $this->assertFalse( $backend->isPersistent(), 'sanity check' ); - \TestingAccessWrapper::newFromObject( $backend )->metaDirty = false; - \TestingAccessWrapper::newFromObject( $backend )->dataDirty = true; + TestingAccessWrapper::newFromObject( $backend )->metaDirty = false; + TestingAccessWrapper::newFromObject( $backend )->dataDirty = true; $backend->save(); $this->assertTrue( $this->onSessionMetadataCalled ); $blob = $this->store->getSession( self::SESSIONID ); @@ -574,10 +575,10 @@ class SessionBackendTest extends MediaWikiTestCase { $this->store->setSessionData( self::SESSIONID, $testData ); $backend = $this->getBackend( $user ); $this->store->deleteSession( self::SESSIONID ); - \TestingAccessWrapper::newFromObject( $backend )->persist = true; + TestingAccessWrapper::newFromObject( $backend )->persist = true; $this->assertTrue( $backend->isPersistent(), 'sanity check' ); - \TestingAccessWrapper::newFromObject( $backend )->metaDirty = false; - \TestingAccessWrapper::newFromObject( $backend )->dataDirty = false; + TestingAccessWrapper::newFromObject( $backend )->metaDirty = false; + TestingAccessWrapper::newFromObject( $backend )->dataDirty = false; $backend->save(); $this->assertFalse( $this->store->getSession( self::SESSIONID ), 'making sure it didn\'t save' ); @@ -589,11 +590,11 @@ class SessionBackendTest extends MediaWikiTestCase { $this->store->setSessionData( self::SESSIONID, $testData ); $backend = $this->getBackend( $user ); $this->store->deleteSession( self::SESSIONID ); - \TestingAccessWrapper::newFromObject( $backend )->persist = true; - \TestingAccessWrapper::newFromObject( $backend )->forcePersist = true; + TestingAccessWrapper::newFromObject( $backend )->persist = true; + TestingAccessWrapper::newFromObject( $backend )->forcePersist = true; $this->assertTrue( $backend->isPersistent(), 'sanity check' ); - \TestingAccessWrapper::newFromObject( $backend )->metaDirty = false; - \TestingAccessWrapper::newFromObject( $backend )->dataDirty = false; + TestingAccessWrapper::newFromObject( $backend )->metaDirty = false; + TestingAccessWrapper::newFromObject( $backend )->dataDirty = false; $backend->save(); $this->assertFalse( $this->store->getSession( self::SESSIONID ), 'making sure it didn\'t save' ); @@ -604,10 +605,10 @@ class SessionBackendTest extends MediaWikiTestCase { $this->store->setSessionData( self::SESSIONID, $testData ); $backend = $this->getBackend( $user ); $this->store->deleteSession( self::SESSIONID ); - \TestingAccessWrapper::newFromObject( $backend )->persist = true; + TestingAccessWrapper::newFromObject( $backend )->persist = true; $this->assertTrue( $backend->isPersistent(), 'sanity check' ); - \TestingAccessWrapper::newFromObject( $backend )->metaDirty = false; - \TestingAccessWrapper::newFromObject( $backend )->dataDirty = true; + TestingAccessWrapper::newFromObject( $backend )->metaDirty = false; + TestingAccessWrapper::newFromObject( $backend )->dataDirty = true; $backend->save(); $this->assertTrue( $this->onSessionMetadataCalled ); $blob = $this->store->getSession( self::SESSIONID ); @@ -629,11 +630,11 @@ class SessionBackendTest extends MediaWikiTestCase { $this->store->setSessionData( self::SESSIONID, $testData ); $backend = $this->getBackend( $user ); $this->store->deleteSession( self::SESSIONID ); - \TestingAccessWrapper::newFromObject( $backend )->persist = true; - \TestingAccessWrapper::newFromObject( $backend )->forcePersist = true; + TestingAccessWrapper::newFromObject( $backend )->persist = true; + TestingAccessWrapper::newFromObject( $backend )->forcePersist = true; $this->assertTrue( $backend->isPersistent(), 'sanity check' ); - \TestingAccessWrapper::newFromObject( $backend )->metaDirty = false; - \TestingAccessWrapper::newFromObject( $backend )->dataDirty = true; + TestingAccessWrapper::newFromObject( $backend )->metaDirty = false; + TestingAccessWrapper::newFromObject( $backend )->dataDirty = true; $backend->save(); $this->assertTrue( $this->onSessionMetadataCalled ); $blob = $this->store->getSession( self::SESSIONID ); @@ -655,10 +656,10 @@ class SessionBackendTest extends MediaWikiTestCase { $this->store->setSessionData( self::SESSIONID, $testData ); $backend = $this->getBackend( $user ); $this->store->deleteSession( self::SESSIONID ); - \TestingAccessWrapper::newFromObject( $backend )->persist = true; + TestingAccessWrapper::newFromObject( $backend )->persist = true; $this->assertTrue( $backend->isPersistent(), 'sanity check' ); - \TestingAccessWrapper::newFromObject( $backend )->metaDirty = true; - \TestingAccessWrapper::newFromObject( $backend )->dataDirty = false; + TestingAccessWrapper::newFromObject( $backend )->metaDirty = true; + TestingAccessWrapper::newFromObject( $backend )->dataDirty = false; $backend->save(); $this->assertTrue( $this->onSessionMetadataCalled ); $blob = $this->store->getSession( self::SESSIONID ); @@ -679,11 +680,11 @@ class SessionBackendTest extends MediaWikiTestCase { $this->store->setSessionData( self::SESSIONID, $testData ); $backend = $this->getBackend( $user ); $this->store->deleteSession( self::SESSIONID ); - \TestingAccessWrapper::newFromObject( $backend )->persist = true; + TestingAccessWrapper::newFromObject( $backend )->persist = true; $this->assertTrue( $backend->isPersistent(), 'sanity check' ); - \TestingAccessWrapper::newFromObject( $backend )->metaDirty = false; - \TestingAccessWrapper::newFromObject( $backend )->dataDirty = false; - \TestingAccessWrapper::newFromObject( $backend )->dataHash = 'Doesn\'t match'; + TestingAccessWrapper::newFromObject( $backend )->metaDirty = false; + TestingAccessWrapper::newFromObject( $backend )->dataDirty = false; + TestingAccessWrapper::newFromObject( $backend )->dataHash = 'Doesn\'t match'; $backend->save(); $this->assertTrue( $this->onSessionMetadataCalled ); $blob = $this->store->getSession( self::SESSIONID ); @@ -721,7 +722,7 @@ class SessionBackendTest extends MediaWikiTestCase { } // SessionManager::preventSessionsForUser - \TestingAccessWrapper::newFromObject( $this->manager )->preventUsers = [ + TestingAccessWrapper::newFromObject( $this->manager )->preventUsers = [ $user->getName() => true, ]; $this->provider = $neverProvider; @@ -729,10 +730,10 @@ class SessionBackendTest extends MediaWikiTestCase { $this->store->setSessionData( self::SESSIONID, $testData ); $backend = $this->getBackend( $user ); $this->store->deleteSession( self::SESSIONID ); - \TestingAccessWrapper::newFromObject( $backend )->persist = true; + TestingAccessWrapper::newFromObject( $backend )->persist = true; $this->assertTrue( $backend->isPersistent(), 'sanity check' ); - \TestingAccessWrapper::newFromObject( $backend )->metaDirty = true; - \TestingAccessWrapper::newFromObject( $backend )->dataDirty = true; + TestingAccessWrapper::newFromObject( $backend )->metaDirty = true; + TestingAccessWrapper::newFromObject( $backend )->dataDirty = true; $backend->save(); $this->assertFalse( $this->store->getSession( self::SESSIONID ), 'making sure it didn\'t save' ); } @@ -751,7 +752,7 @@ class SessionBackendTest extends MediaWikiTestCase { $this->store->setSessionData( self::SESSIONID, $testData ); $backend = $this->getBackend( $user ); $this->store->deleteSession( self::SESSIONID ); - $wrap = \TestingAccessWrapper::newFromObject( $backend ); + $wrap = TestingAccessWrapper::newFromObject( $backend ); $this->assertFalse( $backend->isPersistent(), 'sanity check' ); $wrap->metaDirty = false; $wrap->dataDirty = false; @@ -777,7 +778,7 @@ class SessionBackendTest extends MediaWikiTestCase { $this->store->setSessionData( self::SESSIONID, $testData ); $backend = $this->getBackend( $user ); $this->store->deleteSession( self::SESSIONID ); - $wrap = \TestingAccessWrapper::newFromObject( $backend ); + $wrap = TestingAccessWrapper::newFromObject( $backend ); $wrap->persist = true; $this->assertTrue( $backend->isPersistent(), 'sanity check' ); $wrap->metaDirty = false; @@ -804,7 +805,7 @@ class SessionBackendTest extends MediaWikiTestCase { $this->store->setSessionData( self::SESSIONID, $testData ); $backend = $this->getBackend( $user ); $this->store->deleteSession( self::SESSIONID ); - $wrap = \TestingAccessWrapper::newFromObject( $backend ); + $wrap = TestingAccessWrapper::newFromObject( $backend ); $this->assertFalse( $backend->isPersistent(), 'sanity check' ); $wrap->metaDirty = false; $wrap->dataDirty = false; @@ -829,7 +830,7 @@ class SessionBackendTest extends MediaWikiTestCase { if ( !PHPSessionHandler::isEnabled() ) { $rProp = new \ReflectionProperty( PHPSessionHandler::class, 'instance' ); $rProp->setAccessible( true ); - $handler = \TestingAccessWrapper::newFromObject( $rProp->getValue() ); + $handler = TestingAccessWrapper::newFromObject( $rProp->getValue() ); $resetHandler = new \Wikimedia\ScopedCallback( function () use ( $handler ) { session_write_close(); $handler->enable = false; @@ -838,27 +839,27 @@ class SessionBackendTest extends MediaWikiTestCase { } $backend = $this->getBackend( static::getTestSysop()->getUser() ); - \TestingAccessWrapper::newFromObject( $backend )->usePhpSessionHandling = true; + TestingAccessWrapper::newFromObject( $backend )->usePhpSessionHandling = true; $resetSingleton = TestUtils::setSessionManagerSingleton( $this->manager ); - $manager = \TestingAccessWrapper::newFromObject( $this->manager ); + $manager = TestingAccessWrapper::newFromObject( $this->manager ); $request = \RequestContext::getMain()->getRequest(); $manager->globalSession = $backend->getSession( $request ); $manager->globalSessionRequest = $request; session_id( '' ); - \TestingAccessWrapper::newFromObject( $backend )->checkPHPSession(); + TestingAccessWrapper::newFromObject( $backend )->checkPHPSession(); $this->assertSame( $backend->getId(), session_id() ); session_write_close(); $backend2 = $this->getBackend( User::newFromName( 'UTSysop' ), 'bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb' ); - \TestingAccessWrapper::newFromObject( $backend2 )->usePhpSessionHandling = true; + TestingAccessWrapper::newFromObject( $backend2 )->usePhpSessionHandling = true; session_id( '' ); - \TestingAccessWrapper::newFromObject( $backend2 )->checkPHPSession(); + TestingAccessWrapper::newFromObject( $backend2 )->checkPHPSession(); $this->assertSame( '', session_id() ); } @@ -869,7 +870,7 @@ class SessionBackendTest extends MediaWikiTestCase { if ( !PHPSessionHandler::isEnabled() ) { $rProp = new \ReflectionProperty( PHPSessionHandler::class, 'instance' ); $rProp->setAccessible( true ); - $handler = \TestingAccessWrapper::newFromObject( $rProp->getValue() ); + $handler = TestingAccessWrapper::newFromObject( $rProp->getValue() ); $resetHandler = new \Wikimedia\ScopedCallback( function () use ( $handler ) { session_write_close(); $handler->enable = false; @@ -878,11 +879,11 @@ class SessionBackendTest extends MediaWikiTestCase { } $backend = $this->getBackend( User::newFromName( 'UTSysop' ) ); - \TestingAccessWrapper::newFromObject( $backend )->usePhpSessionHandling = true; + TestingAccessWrapper::newFromObject( $backend )->usePhpSessionHandling = true; $resetSingleton = TestUtils::setSessionManagerSingleton( $this->manager ); - $manager = \TestingAccessWrapper::newFromObject( $this->manager ); + $manager = TestingAccessWrapper::newFromObject( $this->manager ); $request = \RequestContext::getMain()->getRequest(); $manager->globalSession = $backend->getSession( $request ); $manager->globalSessionRequest = $request; @@ -905,7 +906,7 @@ class SessionBackendTest extends MediaWikiTestCase { if ( !PHPSessionHandler::isEnabled() ) { $rProp = new \ReflectionProperty( PHPSessionHandler::class, 'instance' ); $rProp->setAccessible( true ); - $handler = \TestingAccessWrapper::newFromObject( $rProp->getValue() ); + $handler = TestingAccessWrapper::newFromObject( $rProp->getValue() ); $resetHandler = new \Wikimedia\ScopedCallback( function () use ( $handler ) { session_write_close(); $handler->enable = false; @@ -914,13 +915,13 @@ class SessionBackendTest extends MediaWikiTestCase { } $backend = $this->getBackend( User::newFromName( 'UTSysop' ) ); - $wrap = \TestingAccessWrapper::newFromObject( $backend ); + $wrap = TestingAccessWrapper::newFromObject( $backend ); $wrap->usePhpSessionHandling = true; $wrap->persist = true; $resetSingleton = TestUtils::setSessionManagerSingleton( $this->manager ); - $manager = \TestingAccessWrapper::newFromObject( $this->manager ); + $manager = TestingAccessWrapper::newFromObject( $this->manager ); $request = \RequestContext::getMain()->getRequest(); $manager->globalSession = $backend->getSession( $request ); $manager->globalSessionRequest = $request; diff --git a/tests/phpunit/includes/session/SessionManagerTest.php b/tests/phpunit/includes/session/SessionManagerTest.php index c4b1072cda..9eb46bc381 100644 --- a/tests/phpunit/includes/session/SessionManagerTest.php +++ b/tests/phpunit/includes/session/SessionManagerTest.php @@ -5,6 +5,7 @@ namespace MediaWiki\Session; use MediaWikiTestCase; use Psr\Log\LogLevel; use User; +use Wikimedia\TestingAccessWrapper; /** * @group Session @@ -59,7 +60,7 @@ class SessionManagerTest extends MediaWikiTestCase { } $rProp = new \ReflectionProperty( PHPSessionHandler::class, 'instance' ); $rProp->setAccessible( true ); - $handler = \TestingAccessWrapper::newFromObject( $rProp->getValue() ); + $handler = TestingAccessWrapper::newFromObject( $rProp->getValue() ); $oldEnable = $handler->enable; $reset[] = new \Wikimedia\ScopedCallback( function () use ( $handler, $oldEnable ) { if ( $handler->enable ) { @@ -100,15 +101,15 @@ class SessionManagerTest extends MediaWikiTestCase { } public function testConstructor() { - $manager = \TestingAccessWrapper::newFromObject( $this->getManager() ); + $manager = TestingAccessWrapper::newFromObject( $this->getManager() ); $this->assertSame( $this->config, $manager->config ); $this->assertSame( $this->logger, $manager->logger ); $this->assertSame( $this->store, $manager->store ); - $manager = \TestingAccessWrapper::newFromObject( new SessionManager() ); + $manager = TestingAccessWrapper::newFromObject( new SessionManager() ); $this->assertSame( \RequestContext::getMain()->getConfig(), $manager->config ); - $manager = \TestingAccessWrapper::newFromObject( new SessionManager( [ + $manager = TestingAccessWrapper::newFromObject( new SessionManager( [ 'config' => $this->config, ] ) ); $this->assertSame( \ObjectCache::$instances['testSessionStore'], $manager->store ); @@ -418,7 +419,7 @@ class SessionManagerTest extends MediaWikiTestCase { public function testGetEmptySession() { $manager = $this->getManager(); - $pmanager = \TestingAccessWrapper::newFromObject( $manager ); + $pmanager = TestingAccessWrapper::newFromObject( $manager ); $request = new \FauxRequest(); $providerBuilder = $this->getMockBuilder( 'DummySessionProvider' ) @@ -747,14 +748,14 @@ class SessionManagerTest extends MediaWikiTestCase { public function testGetProviders() { $realManager = $this->getManager(); - $manager = \TestingAccessWrapper::newFromObject( $realManager ); + $manager = TestingAccessWrapper::newFromObject( $realManager ); $this->config->set( 'SessionProviders', [ [ 'class' => 'DummySessionProvider' ], ] ); $providers = $manager->getProviders(); $this->assertArrayHasKey( 'DummySessionProvider', $providers ); - $provider = \TestingAccessWrapper::newFromObject( $providers['DummySessionProvider'] ); + $provider = TestingAccessWrapper::newFromObject( $providers['DummySessionProvider'] ); $this->assertSame( $manager->logger, $provider->logger ); $this->assertSame( $manager->config, $provider->config ); $this->assertSame( $realManager, $provider->getManager() ); @@ -776,7 +777,7 @@ class SessionManagerTest extends MediaWikiTestCase { } public function testShutdown() { - $manager = \TestingAccessWrapper::newFromObject( $this->getManager() ); + $manager = TestingAccessWrapper::newFromObject( $this->getManager() ); $manager->setLogger( new \Psr\Log\NullLogger() ); $mock = $this->getMockBuilder( 'stdClass' ) @@ -788,7 +789,7 @@ class SessionManagerTest extends MediaWikiTestCase { } public function testGetSessionFromInfo() { - $manager = \TestingAccessWrapper::newFromObject( $this->getManager() ); + $manager = TestingAccessWrapper::newFromObject( $this->getManager() ); $request = new \FauxRequest(); $id = 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'; @@ -800,11 +801,11 @@ class SessionManagerTest extends MediaWikiTestCase { 'userInfo' => UserInfo::newFromName( 'UTSysop', true ), 'idIsSafe' => true, ] ); - \TestingAccessWrapper::newFromObject( $info )->idIsSafe = true; - $session1 = \TestingAccessWrapper::newFromObject( + TestingAccessWrapper::newFromObject( $info )->idIsSafe = true; + $session1 = TestingAccessWrapper::newFromObject( $manager->getSessionFromInfo( $info, $request ) ); - $session2 = \TestingAccessWrapper::newFromObject( + $session2 = TestingAccessWrapper::newFromObject( $manager->getSessionFromInfo( $info, $request ) ); @@ -813,7 +814,7 @@ class SessionManagerTest extends MediaWikiTestCase { $this->assertSame( $session1->getSessionId(), $session2->getSessionId() ); $this->assertSame( $id, $session1->getId() ); - \TestingAccessWrapper::newFromObject( $info )->idIsSafe = false; + TestingAccessWrapper::newFromObject( $info )->idIsSafe = false; $session3 = $manager->getSessionFromInfo( $info, $request ); $this->assertNotSame( $id, $session3->getId() ); } @@ -822,7 +823,7 @@ class SessionManagerTest extends MediaWikiTestCase { $manager = $this->getManager(); $session = $manager->getSessionForRequest( new \FauxRequest ); - $backend = \TestingAccessWrapper::newFromObject( $session )->backend; + $backend = TestingAccessWrapper::newFromObject( $session )->backend; $sessionId = $session->getSessionId(); $id = (string)$sessionId; @@ -959,7 +960,7 @@ class SessionManagerTest extends MediaWikiTestCase { $provider3->expects( $this->any() )->method( '__toString' ) ->will( $this->returnValue( 'Mock3' ) ); - \TestingAccessWrapper::newFromObject( $manager )->sessionProviders = [ + TestingAccessWrapper::newFromObject( $manager )->sessionProviders = [ (string)$provider => $provider, (string)$provider2 => $provider2, (string)$provider3 => $provider3, diff --git a/tests/phpunit/includes/session/SessionProviderTest.php b/tests/phpunit/includes/session/SessionProviderTest.php index 8284d05e97..052c0167a9 100644 --- a/tests/phpunit/includes/session/SessionProviderTest.php +++ b/tests/phpunit/includes/session/SessionProviderTest.php @@ -3,6 +3,7 @@ namespace MediaWiki\Session; use MediaWikiTestCase; +use Wikimedia\TestingAccessWrapper; /** * @group Session @@ -17,7 +18,7 @@ class SessionProviderTest extends MediaWikiTestCase { $config = new \HashConfig(); $provider = $this->getMockForAbstractClass( SessionProvider::class ); - $priv = \TestingAccessWrapper::newFromObject( $provider ); + $priv = TestingAccessWrapper::newFromObject( $provider ); $provider->setConfig( $config ); $this->assertSame( $config, $priv->config ); @@ -148,7 +149,7 @@ class SessionProviderTest extends MediaWikiTestCase { $provider = $this->getMockForAbstractClass( SessionProvider::class, [], 'MockSessionProvider' ); $provider->setConfig( $config ); - $priv = \TestingAccessWrapper::newFromObject( $provider ); + $priv = TestingAccessWrapper::newFromObject( $provider ); $this->assertSame( 'eoq8cb1mg7j30ui5qolafps4hg29k5bb', $priv->hashToSessionId( 'foobar' ) ); $this->assertSame( '4do8j7tfld1g8tte9jqp3csfgmulaun9', @@ -198,7 +199,7 @@ class SessionProviderTest extends MediaWikiTestCase { ); } - \TestingAccessWrapper::newFromObject( $backend )->provider = $provider; + TestingAccessWrapper::newFromObject( $backend )->provider = $provider; $this->assertNull( $provider->getAllowedUserRights( $backend ) ); } diff --git a/tests/phpunit/includes/session/SessionTest.php b/tests/phpunit/includes/session/SessionTest.php index f6c88ecf08..adf0f5db50 100644 --- a/tests/phpunit/includes/session/SessionTest.php +++ b/tests/phpunit/includes/session/SessionTest.php @@ -5,6 +5,7 @@ namespace MediaWiki\Session; use Psr\Log\LogLevel; use MediaWikiTestCase; use User; +use Wikimedia\TestingAccessWrapper; /** * @group Session @@ -14,16 +15,16 @@ class SessionTest extends MediaWikiTestCase { public function testConstructor() { $backend = TestUtils::getDummySessionBackend(); - \TestingAccessWrapper::newFromObject( $backend )->requests = [ -1 => 'dummy' ]; - \TestingAccessWrapper::newFromObject( $backend )->id = new SessionId( 'abc' ); + TestingAccessWrapper::newFromObject( $backend )->requests = [ -1 => 'dummy' ]; + TestingAccessWrapper::newFromObject( $backend )->id = new SessionId( 'abc' ); $session = new Session( $backend, 42, new \TestLogger ); - $priv = \TestingAccessWrapper::newFromObject( $session ); + $priv = TestingAccessWrapper::newFromObject( $session ); $this->assertSame( $backend, $priv->backend ); $this->assertSame( 42, $priv->index ); $request = new \FauxRequest(); - $priv2 = \TestingAccessWrapper::newFromObject( $session->sessionWithRequest( $request ) ); + $priv2 = TestingAccessWrapper::newFromObject( $session->sessionWithRequest( $request ) ); $this->assertSame( $backend, $priv2->backend ); $this->assertNotSame( $priv->index, $priv2->index ); $this->assertSame( $request, $priv2->getRequest() ); @@ -98,7 +99,7 @@ class SessionTest extends MediaWikiTestCase { public function testDataAccess() { $session = TestUtils::getDummySession(); - $backend = \TestingAccessWrapper::newFromObject( $session )->backend; + $backend = TestingAccessWrapper::newFromObject( $session )->backend; $this->assertEquals( 1, $session->get( 'foo' ) ); $this->assertEquals( 'zero', $session->get( 0 ) ); @@ -158,7 +159,7 @@ class SessionTest extends MediaWikiTestCase { public function testArrayAccess() { $logger = new \TestLogger; $session = TestUtils::getDummySession( null, -1, $logger ); - $backend = \TestingAccessWrapper::newFromObject( $session )->backend; + $backend = TestingAccessWrapper::newFromObject( $session )->backend; $this->assertEquals( 1, $session['foo'] ); $this->assertEquals( 'zero', $session[0] ); @@ -222,7 +223,7 @@ class SessionTest extends MediaWikiTestCase { public function testClear() { $session = TestUtils::getDummySession(); - $priv = \TestingAccessWrapper::newFromObject( $session ); + $priv = TestingAccessWrapper::newFromObject( $session ); $backend = $this->getMockBuilder( DummySessionBackend::class ) ->setMethods( [ 'canSetUser', 'setUser', 'save' ] ) @@ -269,10 +270,10 @@ class SessionTest extends MediaWikiTestCase { public function testTokens() { $session = TestUtils::getDummySession(); - $priv = \TestingAccessWrapper::newFromObject( $session ); + $priv = TestingAccessWrapper::newFromObject( $session ); $backend = $priv->backend; - $token = \TestingAccessWrapper::newFromObject( $session->getToken() ); + $token = TestingAccessWrapper::newFromObject( $session->getToken() ); $this->assertArrayHasKey( 'wsTokenSecrets', $backend->data ); $this->assertArrayHasKey( 'default', $backend->data['wsTokenSecrets'] ); $secret = $backend->data['wsTokenSecrets']['default']; @@ -280,13 +281,13 @@ class SessionTest extends MediaWikiTestCase { $this->assertSame( '', $token->salt ); $this->assertTrue( $token->wasNew() ); - $token = \TestingAccessWrapper::newFromObject( $session->getToken( 'foo' ) ); + $token = TestingAccessWrapper::newFromObject( $session->getToken( 'foo' ) ); $this->assertSame( $secret, $token->secret ); $this->assertSame( 'foo', $token->salt ); $this->assertFalse( $token->wasNew() ); $backend->data['wsTokenSecrets']['secret'] = 'sekret'; - $token = \TestingAccessWrapper::newFromObject( + $token = TestingAccessWrapper::newFromObject( $session->getToken( [ 'bar', 'baz' ], 'secret' ) ); $this->assertSame( 'sekret', $token->secret ); @@ -358,7 +359,7 @@ class SessionTest extends MediaWikiTestCase { // Unserializable data $iv = \MWCryptRand::generate( 16, true ); - list( $encKey, $hmacKey ) = \TestingAccessWrapper::newFromObject( $session )->getSecretKeys(); + list( $encKey, $hmacKey ) = TestingAccessWrapper::newFromObject( $session )->getSecretKeys(); $ciphertext = openssl_encrypt( 'foobar', 'aes-256-ctr', $encKey, OPENSSL_RAW_DATA, $iv ); $sealed = base64_encode( $iv ) . '.' . base64_encode( $ciphertext ); $hmac = hash_hmac( 'sha256', $sealed, $hmacKey, true ); diff --git a/tests/phpunit/includes/session/TestUtils.php b/tests/phpunit/includes/session/TestUtils.php index f00de55a30..af29d6bd7d 100644 --- a/tests/phpunit/includes/session/TestUtils.php +++ b/tests/phpunit/includes/session/TestUtils.php @@ -3,6 +3,7 @@ namespace MediaWiki\Session; use Psr\Log\LoggerInterface; +use Wikimedia\TestingAccessWrapper; /** * Utility functions for Session unit tests @@ -70,7 +71,7 @@ class TestUtils { } $ret = $rc->newInstanceWithoutConstructor(); - \TestingAccessWrapper::newFromObject( $ret )->logger = new \TestLogger; + TestingAccessWrapper::newFromObject( $ret )->logger = new \TestLogger; return $ret; } @@ -95,7 +96,7 @@ class TestUtils { } $session = $rc->newInstanceWithoutConstructor(); - $priv = \TestingAccessWrapper::newFromObject( $session ); + $priv = TestingAccessWrapper::newFromObject( $session ); $priv->backend = $backend; $priv->index = $index; $priv->logger = $logger ?: new \TestLogger; diff --git a/tests/phpunit/includes/session/TokenTest.php b/tests/phpunit/includes/session/TokenTest.php index ca001f3654..47976527ca 100644 --- a/tests/phpunit/includes/session/TokenTest.php +++ b/tests/phpunit/includes/session/TokenTest.php @@ -3,6 +3,7 @@ namespace MediaWiki\Session; use MediaWikiTestCase; +use Wikimedia\TestingAccessWrapper; /** * @group Session @@ -27,7 +28,7 @@ class TokenTest extends MediaWikiTestCase { } public function testToStringAtTimestamp() { - $token = \TestingAccessWrapper::newFromObject( new Token( 'sekret', 'salty', false ) ); + $token = TestingAccessWrapper::newFromObject( new Token( 'sekret', 'salty', false ) ); $this->assertSame( 'd9ade0c7d4349e9df9094e61c33a5a0d5644fde2+\\', @@ -53,7 +54,7 @@ class TokenTest extends MediaWikiTestCase { } public function testMatch() { - $token = \TestingAccessWrapper::newFromObject( new Token( 'sekret', 'salty', false ) ); + $token = TestingAccessWrapper::newFromObject( new Token( 'sekret', 'salty', false ) ); $test = $token->toStringAtTimestamp( time() - 10 ); $this->assertTrue( $token->match( $test ) ); diff --git a/tests/phpunit/includes/specialpage/ChangesListSpecialPageTest.php b/tests/phpunit/includes/specialpage/ChangesListSpecialPageTest.php index 1ddb98d07d..b536c22f2e 100644 --- a/tests/phpunit/includes/specialpage/ChangesListSpecialPageTest.php +++ b/tests/phpunit/includes/specialpage/ChangesListSpecialPageTest.php @@ -1,4 +1,7 @@