jenkins-bot has submitted this change and it was merged.

Change subject: SMW\CompatibilityTestCase to pass tests on MW 1.19.7 as well
......................................................................


SMW\CompatibilityTestCase to pass tests on MW 1.19.7 as well

Running tests against REL1_19 / 1.19.7 are passed as well except
for those that are skipped because of non-support in 1.19

Change-Id: I64c6627a18ce1d379cf0a647bf96ab1d9c0d8735
---
M includes/Setup.php
A tests/phpunit/CompatibilityTestCase.php
M tests/phpunit/includes/FormatFactoryTest.php
M tests/phpunit/includes/ObservableMessageReporterTest.php
M tests/phpunit/includes/export/SMWExpElementTest.php
5 files changed, 184 insertions(+), 11 deletions(-)

Approvals:
  Mwjames: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/includes/Setup.php b/includes/Setup.php
index 54e758e..e1cf91a 100644
--- a/includes/Setup.php
+++ b/includes/Setup.php
@@ -392,13 +392,14 @@
        $wgAutoloadClasses['SMW\Test\ResultPrinterTestCase']         = 
$testsDir . 'QueryPrinterRegistryTestCase.php';
        $wgAutoloadClasses['SMW\Test\QueryPrinterRegistryTestCase']  = 
$testsDir . 'QueryPrinterRegistryTestCase.php';
        $wgAutoloadClasses['SMW\Test\QueryPrinterTestCase']          = 
$testsDir . 'QueryPrinterTestCase.php';
-       $wgAutoloadClasses['SMW\Tests\DataItemTest']              = $testsDir . 
'includes/dataitems/DataItemTest.php';
-       $wgAutoloadClasses['SMW\Test\SemanticMediaWikiTestCase']  = $testsDir . 
'SemanticMediaWikiTestCase.php';
-       $wgAutoloadClasses['SMW\Test\ParserTestCase']             = $testsDir . 
'ParserTestCase.php';
-       $wgAutoloadClasses['SMW\Test\ApiTestCase']                = $testsDir . 
'ApiTestCase.php';
-       $wgAutoloadClasses['SMW\Test\MockSuperUser']              = $testsDir . 
'MockSuperUser.php';
-       $wgAutoloadClasses['SMW\Test\MockObjectBuilder']          = $testsDir . 
'MockObjectBuilder.php';
-       $wgAutoloadClasses['SMW\Test\SpecialPageTestCase']        = $testsDir . 
'SpecialPageTestCase.php';
+       $wgAutoloadClasses['SMW\Tests\DataItemTest']                 = 
$testsDir . 'includes/dataitems/DataItemTest.php';
+       $wgAutoloadClasses['SMW\Test\SemanticMediaWikiTestCase']     = 
$testsDir . 'SemanticMediaWikiTestCase.php';
+       $wgAutoloadClasses['SMW\Test\ParserTestCase']                = 
$testsDir . 'ParserTestCase.php';
+       $wgAutoloadClasses['SMW\Test\ApiTestCase']                   = 
$testsDir . 'ApiTestCase.php';
+       $wgAutoloadClasses['SMW\Test\MockSuperUser']                 = 
$testsDir . 'MockSuperUser.php';
+       $wgAutoloadClasses['SMW\Test\MockObjectBuilder']             = 
$testsDir . 'MockObjectBuilder.php';
+       $wgAutoloadClasses['SMW\Test\SpecialPageTestCase']           = 
$testsDir . 'SpecialPageTestCase.php';
+       $wgAutoloadClasses['SMW\Test\CompatibilityTestCase']         = 
$testsDir . 'CompatibilityTestCase.php';
 
        // Jobs
        $wgJobClasses['SMWUpdateJob']       = 'SMWUpdateJob';
diff --git a/tests/phpunit/CompatibilityTestCase.php 
b/tests/phpunit/CompatibilityTestCase.php
new file mode 100644
index 0000000..b695e50
--- /dev/null
+++ b/tests/phpunit/CompatibilityTestCase.php
@@ -0,0 +1,146 @@
+<?php
+
+namespace SMW\Test;
+
+/**
+ * Compatibility layer to pass 1.19.7 tests
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * http://www.gnu.org/copyleft/gpl.html
+ *
+ * @file
+ *
+ * @license GNU GPL v2+
+ * @since   1.9
+ *
+ * @author mwjames
+ */
+
+/**
+ * Compatibility layer to pass 1.19.7 tests
+ *
+ * @ingroup test
+ */
+abstract class CompatibilityTestCase extends SemanticMediaWikiTestCase {
+
+       /**
+        * Does an associative sort that works for objects.
+        *
+        * @since 1.20
+        *
+        * @param array $array
+        */
+       protected function objectAssociativeSort( array &$array ) {
+               uasort(
+                       $array,
+                       function ( $a, $b ) {
+                               return serialize( $a ) > serialize( $b ) ? 1 : 
-1;
+                       }
+               );
+       }
+
+       /**
+        * Assert that two arrays are equal
+        *
+        * @note Copied in order to pass MW 1.19.7 tests
+        *
+        * @see MediaWikiTestCase::assertArrayEquals
+        *
+        * @since  1.9
+        *
+        * @param array $expected
+        * @param array $actual
+        * @param boolean $ordered If the order of the values should match
+        * @param boolean $named If the keys should match
+        */
+       protected function assertArrayEquals( array $expected, array $actual, 
$ordered = false, $named = false ) {
+               if ( !$ordered ) {
+                       $this->objectAssociativeSort( $expected );
+                       $this->objectAssociativeSort( $actual );
+               }
+
+               if ( !$named ) {
+                       $expected = array_values( $expected );
+                       $actual = array_values( $actual );
+               }
+
+               call_user_func_array(
+                       array( $this, 'assertEquals' ),
+                       array_merge( array( $expected, $actual ), array_slice( 
func_get_args(), 4 ) )
+               );
+       }
+
+       /**
+        * Utility method taking an array of elements and wrapping
+        * each element in it's own array. Useful for data providers
+        * that only return a single argument.
+        *
+        * @see MediaWikiTestCase::arrayWrap
+        *
+        * @since 1.9
+        *
+        * @param array $elements
+        *
+        * @return array
+        */
+       protected function arrayWrap( array $elements ) {
+               return array_map(
+                       function ( $element ) {
+                               return array( $element );
+                       },
+                       $elements
+               );
+       }
+
+       /**
+        * Asserts that the provided variable is of the specified
+        * internal type or equals the $value argument. This is useful
+        * for testing return types of functions that return a certain
+        * type or *value* when not set or on error.
+        *
+        * @since 1.20
+        *
+        * @param string $type
+        * @param mixed $actual
+        * @param mixed $value
+        * @param string $message
+        */
+       protected function assertTypeOrValue( $type, $actual, $value = false, 
$message = '' ) {
+               if ( $actual === $value ) {
+                       $this->assertTrue( true, $message );
+               } else {
+                       $this->assertType( $type, $actual, $message );
+               }
+       }
+
+       /**
+        * Asserts the type of the provided value. This can be either
+        * in internal type such as boolean or integer, or a class or
+        * interface the value extends or implements.
+        *
+        * @since 1.20
+        *
+        * @param string $type
+        * @param mixed $actual
+        * @param string $message
+        */
+       protected function assertType( $type, $actual, $message = '' ) {
+               if ( class_exists( $type ) || interface_exists( $type ) ) {
+                       $this->assertInstanceOf( $type, $actual, $message );
+               } else {
+                       $this->assertInternalType( $type, $actual, $message );
+               }
+       }
+}
diff --git a/tests/phpunit/includes/FormatFactoryTest.php 
b/tests/phpunit/includes/FormatFactoryTest.php
index dbfb31a..7a984e2 100644
--- a/tests/phpunit/includes/FormatFactoryTest.php
+++ b/tests/phpunit/includes/FormatFactoryTest.php
@@ -31,7 +31,6 @@
  */
 
 /**
- * Tests for the SMW\FormatFactory class.
  * @covers \SMW\FormatFactory
  *
  * @ingroup Test
@@ -40,7 +39,16 @@
  * @group SMWExtension
  * @group SMWQueries
  */
-class FormatFactoryTest extends \MediaWikiTestCase {
+class FormatFactoryTest extends CompatibilityTestCase {
+
+       /**
+        * Returns the name of the class to be tested
+        *
+        * @return string|false
+        */
+       public function getClass() {
+               return '\SMW\FormatFactory';
+       }
 
        public function testSingleton() {
                $instance = FormatFactory::singleton();
diff --git a/tests/phpunit/includes/ObservableMessageReporterTest.php 
b/tests/phpunit/includes/ObservableMessageReporterTest.php
index ce3a051..8b1cde7 100644
--- a/tests/phpunit/includes/ObservableMessageReporterTest.php
+++ b/tests/phpunit/includes/ObservableMessageReporterTest.php
@@ -38,6 +38,15 @@
 class ObservableMessageReporterTest extends MessageReporterTest {
 
        /**
+        * Returns the name of the class to be tested
+        *
+        * @return string|false
+        */
+       public function getClass() {
+               return '\SMW\ObservableMessageReporter';
+       }
+
+       /**
         * @return MessageReporter[]
         */
        public function getInstances() {
@@ -162,7 +171,7 @@
  * @licence GNU GPL v2+
  * @author Jeroen De Dauw < [email protected] >
  */
-abstract class MessageReporterTest extends \MediaWikiTestCase {
+abstract class MessageReporterTest extends SemanticMediaWikiTestCase {
 
        /**
         * @return MessageReporter[]
diff --git a/tests/phpunit/includes/export/SMWExpElementTest.php 
b/tests/phpunit/includes/export/SMWExpElementTest.php
index bf41930..84f69dc 100644
--- a/tests/phpunit/includes/export/SMWExpElementTest.php
+++ b/tests/phpunit/includes/export/SMWExpElementTest.php
@@ -32,7 +32,16 @@
  * @licence GNU GPL v2+
  * @author Jeroen De Dauw < [email protected] >
  */
-class SMWExpElementTest extends \MediaWikiTestCase {
+class SMWExpElementTest extends CompatibilityTestCase {
+
+       /**
+        * Returns the name of the class to be tested
+        *
+        * @return string|false
+        */
+       public function getClass() {
+               return '\SMWExpElement';
+       }
 
        public function instanceProvider() {
                $instances = array();

-- 
To view, visit https://gerrit.wikimedia.org/r/73959
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I64c6627a18ce1d379cf0a647bf96ab1d9c0d8735
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/SemanticMediaWiki
Gerrit-Branch: master
Gerrit-Owner: Mwjames <[email protected]>
Gerrit-Reviewer: Mwjames <[email protected]>
Gerrit-Reviewer: jenkins-bot

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to