Merge "phpunit: Avoid use of deprecated getMock for PHPUnit 5 compat"
[lhc/web/wiklou.git] / tests / phpunit / includes / session / SessionBackendTest.php
index a3d5de7..4a28f7a 100644 (file)
@@ -293,7 +293,8 @@ class SessionBackendTest extends MediaWikiTestCase {
        }
 
        public function testPersist() {
-               $this->provider = $this->getMock( 'DummySessionProvider', [ 'persistSession' ] );
+               $this->provider = $this->getMockBuilder( 'DummySessionProvider' )
+                       ->setMethods( [ 'persistSession' ] )->getMock();
                $this->provider->expects( $this->once() )->method( 'persistSession' );
                $backend = $this->getBackend();
                $this->assertFalse( $backend->isPersistent(), 'sanity check' );
@@ -312,7 +313,8 @@ class SessionBackendTest extends MediaWikiTestCase {
        }
 
        public function testUnpersist() {
-               $this->provider = $this->getMock( 'DummySessionProvider', [ 'unpersistSession' ] );
+               $this->provider = $this->getMockBuilder( 'DummySessionProvider' )
+                       ->setMethods( [ 'unpersistSession' ] )->getMock();
                $this->provider->expects( $this->once() )->method( 'unpersistSession' );
                $backend = $this->getBackend();
                $wrap = \TestingAccessWrapper::newFromObject( $backend );
@@ -362,7 +364,8 @@ class SessionBackendTest extends MediaWikiTestCase {
        public function testSetUser() {
                $user = static::getTestSysop()->getUser();
 
-               $this->provider = $this->getMock( 'DummySessionProvider', [ 'canChangeUser' ] );
+               $this->provider = $this->getMockBuilder( 'DummySessionProvider' )
+                       ->setMethods( [ 'canChangeUser' ] )->getMock();
                $this->provider->expects( $this->any() )->method( 'canChangeUser' )
                        ->will( $this->returnValue( false ) );
                $backend = $this->getBackend();
@@ -464,7 +467,7 @@ class SessionBackendTest extends MediaWikiTestCase {
                // Save happens when delay is consumed
                $this->onSessionMetadataCalled = false;
                $priv->metaDirty = true;
-               \ScopedCallback::consume( $delay );
+               \Wikimedia\ScopedCallback::consume( $delay );
                $this->assertTrue( $this->onSessionMetadataCalled );
 
                // Test multiple delays
@@ -475,11 +478,11 @@ class SessionBackendTest extends MediaWikiTestCase {
                $priv->metaDirty = true;
                $priv->autosave();
                $this->assertFalse( $this->onSessionMetadataCalled );
-               \ScopedCallback::consume( $delay3 );
+               \Wikimedia\ScopedCallback::consume( $delay3 );
                $this->assertFalse( $this->onSessionMetadataCalled );
-               \ScopedCallback::consume( $delay1 );
+               \Wikimedia\ScopedCallback::consume( $delay1 );
                $this->assertFalse( $this->onSessionMetadataCalled );
-               \ScopedCallback::consume( $delay2 );
+               \Wikimedia\ScopedCallback::consume( $delay2 );
                $this->assertTrue( $this->onSessionMetadataCalled );
        }
 
@@ -488,7 +491,8 @@ class SessionBackendTest extends MediaWikiTestCase {
                $this->store = new TestBagOStuff();
                $testData = [ 'foo' => 'foo!', 'bar', [ 'baz', null ] ];
 
-               $neverHook = $this->getMock( __CLASS__, [ 'onSessionMetadata' ] );
+               $neverHook = $this->getMockBuilder( __CLASS__ )
+                       ->setMethods( [ 'onSessionMetadata' ] )->getMock();
                $neverHook->expects( $this->never() )->method( 'onSessionMetadata' );
 
                $builder = $this->getMockBuilder( 'DummySessionProvider' )
@@ -694,7 +698,8 @@ class SessionBackendTest extends MediaWikiTestCase {
 
                // Bad hook
                $this->provider = null;
-               $mockHook = $this->getMock( __CLASS__, [ 'onSessionMetadata' ] );
+               $mockHook = $this->getMockBuilder( __CLASS__ )
+                       ->setMethods( [ 'onSessionMetadata' ] )->getMock();
                $mockHook->expects( $this->any() )->method( 'onSessionMetadata' )
                        ->will( $this->returnCallback(
                                function ( SessionBackend $backend, array &$metadata, array $requests ) {
@@ -738,7 +743,8 @@ class SessionBackendTest extends MediaWikiTestCase {
                $testData = [ 'foo' => 'foo!', 'bar', [ 'baz', null ] ];
 
                // Not persistent
-               $this->provider = $this->getMock( 'DummySessionProvider', [ 'persistSession' ] );
+               $this->provider = $this->getMockBuilder( 'DummySessionProvider' )
+                       ->setMethods( [ 'persistSession' ] )->getMock();
                $this->provider->expects( $this->never() )->method( 'persistSession' );
                $this->onSessionMetadataCalled = false;
                $this->mergeMwGlobalArrayValue( 'wgHooks', [ 'SessionMetadata' => [ $this ] ] );
@@ -763,7 +769,8 @@ class SessionBackendTest extends MediaWikiTestCase {
                $this->assertNotEquals( 0, $wrap->expires );
 
                // Persistent
-               $this->provider = $this->getMock( 'DummySessionProvider', [ 'persistSession' ] );
+               $this->provider = $this->getMockBuilder( 'DummySessionProvider' )
+                       ->setMethods( [ 'persistSession' ] )->getMock();
                $this->provider->expects( $this->atLeastOnce() )->method( 'persistSession' );
                $this->onSessionMetadataCalled = false;
                $this->mergeMwGlobalArrayValue( 'wgHooks', [ 'SessionMetadata' => [ $this ] ] );
@@ -789,7 +796,8 @@ class SessionBackendTest extends MediaWikiTestCase {
                $this->assertNotEquals( 0, $wrap->expires );
 
                // Not persistent, not expiring
-               $this->provider = $this->getMock( 'DummySessionProvider', [ 'persistSession' ] );
+               $this->provider = $this->getMockBuilder( 'DummySessionProvider' )
+                       ->setMethods( [ 'persistSession' ] )->getMock();
                $this->provider->expects( $this->never() )->method( 'persistSession' );
                $this->onSessionMetadataCalled = false;
                $this->mergeMwGlobalArrayValue( 'wgHooks', [ 'SessionMetadata' => [ $this ] ] );
@@ -822,7 +830,7 @@ class SessionBackendTest extends MediaWikiTestCase {
                        $rProp = new \ReflectionProperty( PHPSessionHandler::class, 'instance' );
                        $rProp->setAccessible( true );
                        $handler = \TestingAccessWrapper::newFromObject( $rProp->getValue() );
-                       $resetHandler = new \ScopedCallback( function () use ( $handler ) {
+                       $resetHandler = new \Wikimedia\ScopedCallback( function () use ( $handler ) {
                                session_write_close();
                                $handler->enable = false;
                        } );
@@ -862,7 +870,7 @@ class SessionBackendTest extends MediaWikiTestCase {
                        $rProp = new \ReflectionProperty( PHPSessionHandler::class, 'instance' );
                        $rProp->setAccessible( true );
                        $handler = \TestingAccessWrapper::newFromObject( $rProp->getValue() );
-                       $resetHandler = new \ScopedCallback( function () use ( $handler ) {
+                       $resetHandler = new \Wikimedia\ScopedCallback( function () use ( $handler ) {
                                session_write_close();
                                $handler->enable = false;
                        } );
@@ -898,7 +906,7 @@ class SessionBackendTest extends MediaWikiTestCase {
                        $rProp = new \ReflectionProperty( PHPSessionHandler::class, 'instance' );
                        $rProp->setAccessible( true );
                        $handler = \TestingAccessWrapper::newFromObject( $rProp->getValue() );
-                       $resetHandler = new \ScopedCallback( function () use ( $handler ) {
+                       $resetHandler = new \Wikimedia\ScopedCallback( function () use ( $handler ) {
                                session_write_close();
                                $handler->enable = false;
                        } );