From cf9fc81e9669b6c016c044de57ad2bdd5113d167 Mon Sep 17 00:00:00 2001 From: Brad Jorsch Date: Wed, 10 Feb 2016 12:10:38 -0500 Subject: [PATCH] Remove "$that" from SessionManager Also "function () use ( &$ref )" that was being done for similar reasons. Change-Id: If4ec263a9a9c02c1c6a414b26a0e77ba144437f1 --- includes/session/SessionBackend.php | 15 +++++------ .../session/CookieSessionProviderTest.php | 18 ++++++------- .../includes/session/SessionManagerTest.php | 25 ++++++++----------- 3 files changed, 25 insertions(+), 33 deletions(-) diff --git a/includes/session/SessionBackend.php b/includes/session/SessionBackend.php index a79c5cb089..fe446e356b 100644 --- a/includes/session/SessionBackend.php +++ b/includes/session/SessionBackend.php @@ -549,13 +549,11 @@ final class SessionBackend { * @return \ScopedCallback When this goes out of scope, a save will be triggered */ public function delaySave() { - $that = $this; $this->delaySave++; - $ref = &$this->delaySave; - return new \ScopedCallback( function () use ( $that, &$ref ) { - if ( --$ref <= 0 ) { - $ref = 0; - $that->save(); + return new \ScopedCallback( function () { + if ( --$this->delaySave <= 0 ) { + $this->delaySave = 0; + $this->save(); } } ); } @@ -692,9 +690,8 @@ final class SessionBackend { private function checkPHPSession() { if ( !$this->checkPHPSessionRecursionGuard ) { $this->checkPHPSessionRecursionGuard = true; - $ref = &$this->checkPHPSessionRecursionGuard; - $reset = new \ScopedCallback( function () use ( &$ref ) { - $ref = false; + $reset = new \ScopedCallback( function () { + $this->checkPHPSessionRecursionGuard = false; } ); if ( $this->usePhpSessionHandling && session_id() === '' && PHPSessionHandler::isEnabled() && diff --git a/tests/phpunit/includes/session/CookieSessionProviderTest.php b/tests/phpunit/includes/session/CookieSessionProviderTest.php index f5c8b05b78..659826fb53 100644 --- a/tests/phpunit/includes/session/CookieSessionProviderTest.php +++ b/tests/phpunit/includes/session/CookieSessionProviderTest.php @@ -568,8 +568,6 @@ class CookieSessionProviderTest extends MediaWikiTestCase { } public function testPersistSessionWithHook() { - $that = $this; - $provider = new CookieSessionProvider( array( 'priority' => 1, 'sessionName' => 'MySessionName', @@ -620,14 +618,14 @@ class CookieSessionProviderTest extends MediaWikiTestCase { // Logged-in user, no remember $mock = $this->getMock( __CLASS__, array( 'onUserSetCookies' ) ); $mock->expects( $this->once() )->method( 'onUserSetCookies' ) - ->will( $this->returnCallback( function ( $u, &$sessionData, &$cookies ) use ( $that, $user ) { - $that->assertSame( $user, $u ); - $that->assertEquals( array( + ->will( $this->returnCallback( function ( $u, &$sessionData, &$cookies ) use ( $user ) { + $this->assertSame( $user, $u ); + $this->assertEquals( array( 'wsUserID' => $user->getId(), 'wsUserName' => $user->getName(), 'wsToken' => $user->getToken(), ), $sessionData ); - $that->assertEquals( array( + $this->assertEquals( array( 'UserID' => $user->getId(), 'UserName' => $user->getName(), 'Token' => false, @@ -663,14 +661,14 @@ class CookieSessionProviderTest extends MediaWikiTestCase { // Logged-in user, remember $mock = $this->getMock( __CLASS__, array( 'onUserSetCookies' ) ); $mock->expects( $this->once() )->method( 'onUserSetCookies' ) - ->will( $this->returnCallback( function ( $u, &$sessionData, &$cookies ) use ( $that, $user ) { - $that->assertSame( $user, $u ); - $that->assertEquals( array( + ->will( $this->returnCallback( function ( $u, &$sessionData, &$cookies ) use ( $user ) { + $this->assertSame( $user, $u ); + $this->assertEquals( array( 'wsUserID' => $user->getId(), 'wsUserName' => $user->getName(), 'wsToken' => $user->getToken(), ), $sessionData ); - $that->assertEquals( array( + $this->assertEquals( array( 'UserID' => $user->getId(), 'UserName' => $user->getName(), 'Token' => $user->getToken(), diff --git a/tests/phpunit/includes/session/SessionManagerTest.php b/tests/phpunit/includes/session/SessionManagerTest.php index 6be8957709..16beb7299e 100644 --- a/tests/phpunit/includes/session/SessionManagerTest.php +++ b/tests/phpunit/includes/session/SessionManagerTest.php @@ -760,8 +760,6 @@ class SessionManagerTest extends MediaWikiTestCase { public function testAutoCreateUser() { global $wgGroupPermissions; - $that = $this; - \ObjectCache::$instances[__METHOD__] = new TestBagOStuff(); $this->setMwGlobals( array( 'wgMainCacheType' => __METHOD__ ) ); $this->setMWGlobals( array( @@ -1012,10 +1010,10 @@ class SessionManagerTest extends MediaWikiTestCase { $logger->clearBuffer(); // Sanity check that creation still works, and test completion hook - $cb = $this->callback( function ( User $user ) use ( $that ) { - $that->assertNotEquals( 0, $user->getId() ); - $that->assertSame( 'UTSessionAutoCreate4', $user->getName() ); - $that->assertEquals( + $cb = $this->callback( function ( User $user ) { + $this->assertNotEquals( 0, $user->getId() ); + $this->assertSame( 'UTSessionAutoCreate4', $user->getName() ); + $this->assertEquals( $user->getId(), User::idFromName( 'UTSessionAutoCreate4', User::READ_LATEST ) ); return true; @@ -1649,7 +1647,6 @@ class SessionManagerTest extends MediaWikiTestCase { $this->assertSame( array(), $logger->getBuffer() ); // Hook - $that = $this; $called = false; $data = array( 'foo' => 1 ); $this->store->setSession( $id, array( 'metadata' => $metadata, 'data' => $data ) ); @@ -1660,14 +1657,14 @@ class SessionManagerTest extends MediaWikiTestCase { ) ); $this->mergeMwGlobalArrayValue( 'wgHooks', array( 'SessionCheckInfo' => array( function ( &$reason, $i, $r, $m, $d ) use ( - $that, $info, $metadata, $data, $request, &$called + $info, $metadata, $data, $request, &$called ) { - $that->assertSame( $info->getId(), $i->getId() ); - $that->assertSame( $info->getProvider(), $i->getProvider() ); - $that->assertSame( $info->getUserInfo(), $i->getUserInfo() ); - $that->assertSame( $request, $r ); - $that->assertEquals( $metadata, $m ); - $that->assertEquals( $data, $d ); + $this->assertSame( $info->getId(), $i->getId() ); + $this->assertSame( $info->getProvider(), $i->getProvider() ); + $this->assertSame( $info->getUserInfo(), $i->getUserInfo() ); + $this->assertSame( $request, $r ); + $this->assertEquals( $metadata, $m ); + $this->assertEquals( $data, $d ); $called = true; return false; } ) -- 2.20.1