Merge "Fix for assertArrayEquals. Was throwing fatal for object elements"
authorAaron Schulz <aschulz@wikimedia.org>
Mon, 13 Aug 2012 20:09:10 +0000 (20:09 +0000)
committerGerrit Code Review <gerrit@wikimedia.org>
Mon, 13 Aug 2012 20:09:10 +0000 (20:09 +0000)
tests/phpunit/MediaWikiTestCase.php

index b9b45ae..b895370 100644 (file)
@@ -403,8 +403,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 ) {
@@ -418,6 +418,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