* @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();
}
} );
}
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() &&
}
public function testPersistSessionWithHook() {
- $that = $this;
-
$provider = new CookieSessionProvider( array(
'priority' => 1,
'sessionName' => 'MySessionName',
// 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,
// 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(),
public function testAutoCreateUser() {
global $wgGroupPermissions;
- $that = $this;
-
\ObjectCache::$instances[__METHOD__] = new TestBagOStuff();
$this->setMwGlobals( array( 'wgMainCacheType' => __METHOD__ ) );
$this->setMWGlobals( array(
$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;
$this->assertSame( array(), $logger->getBuffer() );
// Hook
- $that = $this;
$called = false;
$data = array( 'foo' => 1 );
$this->store->setSession( $id, array( 'metadata' => $metadata, 'data' => $data ) );
) );
$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;
} )