Merge "Allow templates in ResourceModules to be array in extension registration"
[lhc/web/wiklou.git] / tests / phpunit / includes / session / TestUtils.php
index 1619983..f1dc9e9 100644 (file)
@@ -2,6 +2,8 @@
 
 namespace MediaWiki\Session;
 
+use Psr\Log\LoggerInterface;
+
 /**
  * Utility functions for Session unit tests
  */
@@ -16,25 +18,25 @@ class TestUtils {
                session_write_close();
 
                $rInstance = new \ReflectionProperty(
-                       'MediaWiki\\Session\\SessionManager', 'instance'
+                       SessionManager::class, 'instance'
                );
                $rInstance->setAccessible( true );
                $rGlobalSession = new \ReflectionProperty(
-                       'MediaWiki\\Session\\SessionManager', 'globalSession'
+                       SessionManager::class, 'globalSession'
                );
                $rGlobalSession->setAccessible( true );
                $rGlobalSessionRequest = new \ReflectionProperty(
-                       'MediaWiki\\Session\\SessionManager', 'globalSessionRequest'
+                       SessionManager::class, 'globalSessionRequest'
                );
                $rGlobalSessionRequest->setAccessible( true );
 
                $oldInstance = $rInstance->getValue();
 
-               $reset = array(
-                       array( $rInstance, $oldInstance ),
-                       array( $rGlobalSession, $rGlobalSession->getValue() ),
-                       array( $rGlobalSessionRequest, $rGlobalSessionRequest->getValue() ),
-               );
+               $reset = [
+                       [ $rInstance, $oldInstance ],
+                       [ $rGlobalSession, $rGlobalSession->getValue() ],
+                       [ $rGlobalSessionRequest, $rGlobalSessionRequest->getValue() ],
+               ];
 
                $rInstance->setValue( $manager );
                $rGlobalSession->setValue( null );
@@ -60,14 +62,16 @@ class TestUtils {
         *  fields necessary.
         */
        public static function getDummySessionBackend() {
-               $rc = new \ReflectionClass( 'MediaWiki\\Session\\SessionBackend' );
+               $rc = new \ReflectionClass( SessionBackend::class );
                if ( !method_exists( $rc, 'newInstanceWithoutConstructor' ) ) {
                        \PHPUnit_Framework_Assert::markTestSkipped(
                                'ReflectionClass::newInstanceWithoutConstructor isn\'t available'
                        );
                }
 
-               return $rc->newInstanceWithoutConstructor();
+               $ret = $rc->newInstanceWithoutConstructor();
+               \TestingAccessWrapper::newFromObject( $ret )->logger = new \TestLogger;
+               return $ret;
        }
 
        /**
@@ -75,10 +79,11 @@ class TestUtils {
         * construct one, use this.
         * @param object $backend Object to serve as the SessionBackend
         * @param int $index Index
+        * @param LoggerInterface $logger
         * @return Session
         */
-       public static function getDummySession( $backend = null, $index = -1 ) {
-               $rc = new \ReflectionClass( 'MediaWiki\\Session\\Session' );
+       public static function getDummySession( $backend = null, $index = -1, $logger = null ) {
+               $rc = new \ReflectionClass( Session::class );
                if ( !method_exists( $rc, 'newInstanceWithoutConstructor' ) ) {
                        \PHPUnit_Framework_Assert::markTestSkipped(
                                'ReflectionClass::newInstanceWithoutConstructor isn\'t available'
@@ -93,6 +98,7 @@ class TestUtils {
                $priv = \TestingAccessWrapper::newFromObject( $session );
                $priv->backend = $backend;
                $priv->index = $index;
+               $priv->logger = $logger ?: new \TestLogger;
                return $session;
        }