Fix for assertArrayEquals. Was throwing fatal for object elements
authorjeroendedauw <jeroendedauw@gmail.com>
Sun, 12 Aug 2012 20:55:55 +0000 (22:55 +0200)
committerjeroendedauw <jeroendedauw@gmail.com>
Sun, 12 Aug 2012 20:55:55 +0000 (22:55 +0200)
Change-Id: I8fa45237e028a814e0895ac0f2b3723394b50d6b

tests/phpunit/MediaWikiTestCase.php

index c96eba0..ac459ea 100644 (file)
@@ -401,8 +401,8 @@ abstract class MediaWikiTestCase extends PHPUnit_Framework_TestCase {
         */
        protected function assertArrayEquals( array $expected, array $actual, $ordered = false, $named = false ) {
                if ( !$ordered ) {
-                       asort( $expected );
-                       asort( $actual );
+                       $this->objectAssociativeSort( $expected );
+                       $this->objectAssociativeSort( $actual );
                }
 
                if ( !$named ) {
@@ -416,6 +416,22 @@ abstract class MediaWikiTestCase extends PHPUnit_Framework_TestCase {
                );
        }
 
+       /**
+        * 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;
+                       }
+               );
+       }
+
        /**
         * Utility function for eliminating all string keys from an array.
         * Useful to turn a database result row as returned by fetchRow() into