Merge "Remove usages of RequestContext::getStats()"
[lhc/web/wiklou.git] / tests / phpunit / MediaWikiTestCase.php
index fd02a3e..bc9f97c 100644 (file)
@@ -1,9 +1,11 @@
 <?php
+
 use MediaWiki\Logger\LegacySpi;
 use MediaWiki\Logger\LoggerFactory;
 use MediaWiki\Logger\MonologSpi;
 use MediaWiki\MediaWikiServices;
 use Psr\Log\LoggerInterface;
+use Wikimedia\TestingAccessWrapper;
 
 /**
  * @since 1.18
@@ -255,6 +257,7 @@ abstract class MediaWikiTestCase extends PHPUnit_Framework_TestCase {
                                CACHE_ACCEL => $hashCache,
                                CACHE_MEMCACHED => $hashCache,
                                'apc' => $hashCache,
+                               'apcu' => $hashCache,
                                'xcache' => $hashCache,
                                'wincache' => $hashCache,
                        ] + $baseConfig->get( 'ObjectCaches' );
@@ -438,7 +441,7 @@ abstract class MediaWikiTestCase extends PHPUnit_Framework_TestCase {
         * @return string Absolute name of the temporary file
         */
        protected function getNewTempFile() {
-               $fileName = tempnam( wfTempDir(), 'MW_PHPUnit_' . get_class( $this ) . '_' );
+               $fileName = tempnam( wfTempDir(), 'MW_PHPUnit_' . static::class . '_' );
                $this->tmpFiles[] = $fileName;
 
                return $fileName;
@@ -1297,24 +1300,31 @@ abstract class MediaWikiTestCase extends PHPUnit_Framework_TestCase {
         */
        public function __call( $func, $args ) {
                static $compatibility = [
-                       'assertEmpty' => 'assertEmpty2', // assertEmpty was added in phpunit 3.7.32
+                       'createMock' => 'createMock2',
                ];
 
                if ( isset( $compatibility[$func] ) ) {
                        return call_user_func_array( [ $this, $compatibility[$func] ], $args );
                } else {
-                       throw new MWException( "Called non-existent $func method on "
-                               . get_class( $this ) );
+                       throw new MWException( "Called non-existent $func method on " . static::class );
                }
        }
 
        /**
-        * Used as a compatibility method for phpunit < 3.7.32
-        * @param string $value
-        * @param string $msg
+        * Return a test double for the specified class.
+        *
+        * @param string $originalClassName
+        * @return PHPUnit_Framework_MockObject_MockObject
+        * @throws Exception
         */
-       private function assertEmpty2( $value, $msg ) {
-               $this->assertTrue( $value == '', $msg );
+       private function createMock2( $originalClassName ) {
+               return $this->getMockBuilder( $originalClassName )
+                       ->disableOriginalConstructor()
+                       ->disableOriginalClone()
+                       ->disableArgumentCloning()
+                       // New in phpunit-mock-objects 3.2 (phpunit 5.4.0)
+                       // ->disallowMockingUnknownTypes()
+                       ->getMock();
        }
 
        private static function unprefixTable( &$tableName, $ind, $prefix ) {
@@ -1768,51 +1778,6 @@ abstract class MediaWikiTestCase extends PHPUnit_Framework_TestCase {
                $this->assertEmpty( $errors, implode( "\n", $errors ) );
        }
 
-       /**
-        * @param array $matcher
-        * @param string $actual
-        * @param bool $isHtml
-        *
-        * @return bool
-        */
-       private static function tagMatch( $matcher, $actual, $isHtml = true ) {
-               $dom = PHPUnit_Util_XML::load( $actual, $isHtml );
-               $tags = PHPUnit_Util_XML::findNodes( $dom, $matcher, $isHtml );
-               return count( $tags ) > 0 && $tags[0] instanceof DOMNode;
-       }
-
-       /**
-        * Note: we are overriding this method to remove the deprecated error
-        * @see https://phabricator.wikimedia.org/T71505
-        * @see https://github.com/sebastianbergmann/phpunit/issues/1292
-        * @deprecated
-        *
-        * @param array $matcher
-        * @param string $actual
-        * @param string $message
-        * @param bool $isHtml
-        */
-       public static function assertTag( $matcher, $actual, $message = '', $isHtml = true ) {
-               // trigger_error(__METHOD__ . ' is deprecated', E_USER_DEPRECATED);
-
-               self::assertTrue( self::tagMatch( $matcher, $actual, $isHtml ), $message );
-       }
-
-       /**
-        * @see MediaWikiTestCase::assertTag
-        * @deprecated
-        *
-        * @param array $matcher
-        * @param string $actual
-        * @param string $message
-        * @param bool $isHtml
-        */
-       public static function assertNotTag( $matcher, $actual, $message = '', $isHtml = true ) {
-               // trigger_error(__METHOD__ . ' is deprecated', E_USER_DEPRECATED);
-
-               self::assertFalse( self::tagMatch( $matcher, $actual, $isHtml ), $message );
-       }
-
        /**
         * Used as a marker to prevent wfResetOutputBuffers from breaking PHPUnit.
         * @return string