From 06e54b828f86928156bf55d7cf91c2ef5a140487 Mon Sep 17 00:00:00 2001 From: jeroendedauw Date: Mon, 2 Jul 2012 16:24:10 +0200 Subject: [PATCH] Added assertArrayEquals method to MediaWikiTestCase to avoid duplicating asort and array_values all over the place Change-Id: I8e8e7257b74268dff8c0d105a399257dfdc01b40 --- tests/phpunit/MediaWikiTestCase.php | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/tests/phpunit/MediaWikiTestCase.php b/tests/phpunit/MediaWikiTestCase.php index 37297968fd..8f18d6edc3 100644 --- a/tests/phpunit/MediaWikiTestCase.php +++ b/tests/phpunit/MediaWikiTestCase.php @@ -387,6 +387,35 @@ abstract class MediaWikiTestCase extends PHPUnit_Framework_TestCase { $this->assertFalse( $r, "found extra row (after #$i)" ); } + /** + * Assert that two arrays are equal. By default this means that both arrays need to hold + * the same set of values. Using additional arguments, order and associated key can also + * be set as relevant. + * + * @since 1.20 + * + * @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 ( !$named ) { + $expected = array_values( $expected ); + $actual = array_values( $actual ); + } + + if ( !$ordered ) { + asort( $expected ); + asort( $actual ); + } + + call_user_func_array( + array( $this, 'assertEquals' ), + array_merge( array( $expected, $actual ), array_slice( func_get_args(), 4 ) ) + ); + } + /** * 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