From 93fe721105bcee4e75aa047e706102ed0c285de3 Mon Sep 17 00:00:00 2001 From: jeroendedauw Date: Sun, 12 Aug 2012 22:55:55 +0200 Subject: [PATCH] Fix for assertArrayEquals. Was throwing fatal for object elements Change-Id: I8fa45237e028a814e0895ac0f2b3723394b50d6b --- tests/phpunit/MediaWikiTestCase.php | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/tests/phpunit/MediaWikiTestCase.php b/tests/phpunit/MediaWikiTestCase.php index c96eba02f6..ac459ea6a5 100644 --- a/tests/phpunit/MediaWikiTestCase.php +++ b/tests/phpunit/MediaWikiTestCase.php @@ -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 -- 2.20.1