X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=tests%2Fphpunit%2FMediaWikiTestCase.php;h=c873c5165db8818edae941f0a48f8c1675888a91;hb=29719f846b8887e1190ddf85125387c079f9539b;hp=37297968fd8667ff04554c1badebb0c5265b47f2;hpb=49df232e1e36c37d09d7674fe5a13d7d5113d861;p=lhc%2Fweb%2Fwiklou.git diff --git a/tests/phpunit/MediaWikiTestCase.php b/tests/phpunit/MediaWikiTestCase.php index 37297968fd..c873c5165d 100644 --- a/tests/phpunit/MediaWikiTestCase.php +++ b/tests/phpunit/MediaWikiTestCase.php @@ -326,10 +326,6 @@ abstract class MediaWikiTestCase extends PHPUnit_Framework_TestCase { } - public static function disableInterwikis( $prefix, &$data ) { - return false; - } - /** * Don't throw a warning if $function is deprecated and called later * @@ -348,6 +344,8 @@ abstract class MediaWikiTestCase extends PHPUnit_Framework_TestCase { * the values given in the order of the columns in the $fields parameter. * Note that the rows are sorted by the columns given in $fields. * + * @since 1.20 + * * @param $table String|Array the table(s) to query * @param $fields String|Array the columns to include in the result (and to sort by) * @param $condition String|Array "where" condition(s) @@ -387,19 +385,90 @@ abstract class MediaWikiTestCase extends PHPUnit_Framework_TestCase { $this->assertFalse( $r, "found extra row (after #$i)" ); } + /** + * 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. + * + * @since 1.20 + * + * @param array $elements + * + * @return array + */ + protected function arrayWrap( array $elements ) { + return array_map( + function( $element ) { + return array( $element ); + }, + $elements + ); + } + + /** + * 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 ( !$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 ) ) + ); + } + + /** + * 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 * a pure indexed array. * - * @static + * @since 1.20 + * * @param $r mixed the array to remove string keys from. */ protected static function stripStringKeys( &$r ) { - if ( !is_array( $r ) ) return; + if ( !is_array( $r ) ) { + return; + } foreach ( $r as $k => $v ) { - if ( is_string( $k ) ) unset( $r[$k] ); + if ( is_string( $k ) ) { + unset( $r[$k] ); + } } } + }