r81599 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r81598‎ | r81599 | r81600 >
Date:18:02, 6 February 2011
Author:hashar
Status:ok
Tags:
Comment:
wfShorthandToInteger() PHPUnit code coverage

Some easy assertions.

$ php phpunit.php --configuration suite.xml --filter Shorthand
PHPUnit 3.5.10 by Sebastian Bergmann.
...........................
Time: 2 seconds, Memory: 22.00Mb
OK (27 tests, 27 assertions)
Modified paths:
  • /trunk/phase3/tests/phpunit/includes/GlobalTest.php (modified) (history)

Diff [purge]

Index: trunk/phase3/tests/phpunit/includes/GlobalTest.php
@@ -633,6 +633,61 @@
634634 }
635635
636636 /**
 637+ * test @see wfShorthandToInteger()
 638+ * @dataProvider provideShorthand
 639+ */
 640+ public function testWfShorthandToInteger( $shorthand, $expected ) {
 641+ $this->assertEquals( $expected,
 642+ wfShorthandToInteger( $shorthand )
 643+ );
 644+ }
 645+
 646+ /** array( shorthand, expected integer ) */
 647+ public function provideShorthand() {
 648+ return array(
 649+ # Null, empty ...
 650+ array( '', -1),
 651+ array( ' ', -1),
 652+ array( null, -1),
 653+
 654+ # Failures returns 0 :(
 655+ array( 'ABCDEFG', 0 ),
 656+ array( 'Ak', 0 ),
 657+
 658+ # Int, strings with spaces
 659+ array( 1, 1 ),
 660+ array( ' 1 ', 1 ),
 661+ array( 1023, 1023 ),
 662+ array( ' 1023 ', 1023 ),
 663+
 664+ # kilo, Mega, Giga
 665+ array( '1k', 1024 ),
 666+ array( '1K', 1024 ),
 667+ array( '1m', 1024 * 1024 ),
 668+ array( '1M', 1024 * 1024 ),
 669+ array( '1g', 1024 * 1024 * 1024 ),
 670+ array( '1G', 1024 * 1024 * 1024 ),
 671+
 672+ # Negatives
 673+ array( -1, -1 ),
 674+ array( -500, -500 ),
 675+ array( '-500', -500 ),
 676+ array( '-1k', -1024 ),
 677+
 678+ # Zeroes
 679+ array( '0', 0 ),
 680+ array( '0k', 0 ),
 681+ array( '0M', 0 ),
 682+ array( '0G', 0 ),
 683+ array( '-0', 0 ),
 684+ array( '-0k', 0 ),
 685+ array( '-0M', 0 ),
 686+ array( '-0G', 0 ),
 687+ );
 688+ }
 689+
 690+
 691+ /**
637692 * test @see wfBCP47().
638693 * Please note the BCP explicitly state that language codes are case
639694 * insensitive, there are some exceptions to the rule :)

Status & tagging log