Merge "Add RemexHtml to the list of available Tidy drivers"
[lhc/web/wiklou.git] / tests / phpunit / includes / session / TestUtils.php
index 1619983..f00de55 100644 (file)
@@ -2,6 +2,8 @@
 
 namespace MediaWiki\Session;
 
+use Psr\Log\LoggerInterface;
+
 /**
  * Utility functions for Session unit tests
  */
@@ -10,31 +12,31 @@ class TestUtils {
        /**
         * Override the singleton for unit testing
         * @param SessionManager|null $manager
-        * @return \\ScopedCallback|null
+        * @return \\Wikimedia\ScopedCallback|null
         */
        public static function setSessionManagerSingleton( SessionManager $manager = null ) {
                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 );
@@ -43,7 +45,7 @@ class TestUtils {
                        PHPSessionHandler::install( $manager );
                }
 
-               return new \ScopedCallback( function () use ( &$reset, $oldInstance ) {
+               return new \Wikimedia\ScopedCallback( function () use ( &$reset, $oldInstance ) {
                        foreach ( $reset as &$arr ) {
                                $arr[0]->setValue( $arr[1] );
                        }
@@ -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;
        }