tests: Refactor GlobalTest to use a data provider
Change-Id: Iba800edd9ca35650f79b933db48eb8f95bd09f04
This commit is contained in:
parent
26b8956cb4
commit
3781f4113b
2 changed files with 12 additions and 14 deletions
|
|
@ -1964,7 +1964,7 @@ function wfRecursiveRemoveDir( $dir ) {
|
|||
}
|
||||
|
||||
/**
|
||||
* @param int $nr The number to format
|
||||
* @param float $nr The number to format
|
||||
* @param int $acc The number of digits after the decimal point, default 2
|
||||
* @param bool $round Whether or not to round the value, default true
|
||||
* @return string
|
||||
|
|
|
|||
|
|
@ -383,9 +383,18 @@ class GlobalTest extends MediaWikiTestCase {
|
|||
|
||||
/**
|
||||
* @covers ::wfPercent
|
||||
* @dataProvider provideWfPercentTest
|
||||
*/
|
||||
public function testWfPercentTest() {
|
||||
$pcts = [
|
||||
public function testWfPercentTest( float $input,
|
||||
string $expected,
|
||||
int $accuracy = 2,
|
||||
bool $round = true
|
||||
) {
|
||||
$this->assertSame( $expected, wfPercent( $input, $accuracy, $round ) );
|
||||
}
|
||||
|
||||
public function provideWfPercentTest() {
|
||||
return [
|
||||
[ 6 / 7, '0.86%', 2, false ],
|
||||
[ 3 / 3, '1%' ],
|
||||
[ 22 / 7, '3.14286%', 5 ],
|
||||
|
|
@ -395,17 +404,6 @@ class GlobalTest extends MediaWikiTestCase {
|
|||
[ 3 / 4 / 5, '0.1%', 1 ],
|
||||
[ 6 / 7 * 8, '6.8571428571%', 10 ],
|
||||
];
|
||||
|
||||
foreach ( $pcts as $pct ) {
|
||||
if ( !isset( $pct[2] ) ) {
|
||||
$pct[2] = 2;
|
||||
}
|
||||
if ( !isset( $pct[3] ) ) {
|
||||
$pct[3] = true;
|
||||
}
|
||||
|
||||
$this->assertEquals( wfPercent( $pct[0], $pct[2], $pct[3] ), $pct[1], $pct[1] );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
Loading…
Reference in a new issue