Cleanup MagicVariableTest
authoraddshore <addshorewiki@gmail.com>
Tue, 22 Oct 2013 09:46:48 +0000 (11:46 +0200)
committerHashar <hashar@free.fr>
Wed, 23 Oct 2013 07:58:14 +0000 (07:58 +0000)
 - Give methods scope
 - Make providers static
 - Add @covers todo
 - Merge the Providers file that is only used in here

Change-Id: I60a6bbd5a8ad3d9d414de493ec2b083f52114a7b

tests/TestsAutoLoader.php
tests/phpunit/includes/Providers.php [deleted file]
tests/phpunit/includes/parser/MagicVariableTest.php

index 0939ebe..cd9a93e 100644 (file)
@@ -40,7 +40,6 @@ $wgAutoloadClasses += array(
        'MediaWikiPHPUnitCommand' => "$testDir/phpunit/MediaWikiPHPUnitCommand.php",
        'MediaWikiPHPUnitTestListener' => "$testDir/phpunit/MediaWikiPHPUnitTestListener.php",
        'MediaWikiLangTestCase' => "$testDir/phpunit/MediaWikiLangTestCase.php",
-       'MediaWikiProvide' => "$testDir/phpunit/includes/Providers.php",
        'TestUser' => "$testDir/phpunit/includes/TestUser.php",
 
        # tests/phpunit/includes
diff --git a/tests/phpunit/includes/Providers.php b/tests/phpunit/includes/Providers.php
deleted file mode 100644 (file)
index 4ddc0b0..0000000
+++ /dev/null
@@ -1,46 +0,0 @@
-<?php
-/**
- * Generic providers for the MediaWiki PHPUnit test suite
- *
- * @author Antoine Musso
- * @copyright Copyright © 2011, Antoine Musso
- * @file
- */
-
-/** */
-class MediaWikiProvide {
-
-       /* provide an array of numbers from 1 up to @param $num */
-       private static function createProviderUpTo( $num ) {
-               $ret = array();
-               for ( $i = 1; $i <= $num; $i++ ) {
-                       $ret[] = array( $i );
-               }
-
-               return $ret;
-       }
-
-       /* array of months numbers (as an integer) */
-       public static function Months() {
-               return self::createProviderUpTo( 12 );
-       }
-
-       /* array of days numbers (as an integer) */
-       public static function Days() {
-               return self::createProviderUpTo( 31 );
-       }
-
-       public static function DaysMonths() {
-               $ret = array();
-
-               $months = self::Months();
-               $days = self::Days();
-               foreach ( $months as $month ) {
-                       foreach ( $days as $day ) {
-                               $ret[] = array( $day[0], $month[0] );
-                       }
-               }
-
-               return $ret;
-       }
-}
index 263df5f..c2c97c0 100644 (file)
@@ -9,11 +9,13 @@
  * @author Antoine Musso
  * @copyright Copyright © 2011, Antoine Musso
  * @file
+ * @todo covers tags
  */
 
-/** */
 class MagicVariableTest extends MediaWikiTestCase {
-       /** Will contains a parser object*/
+       /**
+        * @var Parser
+        */
        private $testParser = null;
 
        /**
@@ -51,11 +53,31 @@ class MagicVariableTest extends MediaWikiTestCase {
                $this->testParser->setTitle( $title );
        }
 
-       /** destroy parser (TODO: is it really neded?)*/
-       protected function tearDown() {
-               unset( $this->testParser );
+       /**
+        * @param int $num upper limit for numbers
+        * @return array of numbers from 1 up to $num
+        */
+       private static function createProviderUpTo( $num ) {
+               $ret = array();
+               for ( $i = 1; $i <= $num; $i++ ) {
+                       $ret[] = array( $i );
+               }
+
+               return $ret;
+       }
+
+       /**
+        * @return array of months numbers (as an integer)
+        */
+       public static function provideMonths() {
+               return self::createProviderUpTo( 12 );
+       }
 
-               parent::tearDown();
+       /**
+        * @return array of days numbers (as an integer)
+        */
+       public static function provideDays() {
+               return self::createProviderUpTo( 31 );
        }
 
        ############### TESTS #############################################
@@ -65,70 +87,69 @@ class MagicVariableTest extends MediaWikiTestCase {
 
        # day
 
-       /** @dataProvider MediaWikiProvide::Days */
-       function testCurrentdayIsUnPadded( $day ) {
+       /** @dataProvider provideDays */
+       public function testCurrentdayIsUnPadded( $day ) {
                $this->assertUnPadded( 'currentday', $day );
        }
 
-       /** @dataProvider MediaWikiProvide::Days */
-       function testCurrentdaytwoIsZeroPadded( $day ) {
+       /** @dataProvider provideDays */
+       public function testCurrentdaytwoIsZeroPadded( $day ) {
                $this->assertZeroPadded( 'currentday2', $day );
        }
 
-       /** @dataProvider MediaWikiProvide::Days */
-       function testLocaldayIsUnPadded( $day ) {
+       /** @dataProvider provideDays */
+       public function testLocaldayIsUnPadded( $day ) {
                $this->assertUnPadded( 'localday', $day );
        }
 
-       /** @dataProvider MediaWikiProvide::Days */
-       function testLocaldaytwoIsZeroPadded( $day ) {
+       /** @dataProvider provideDays */
+       public function testLocaldaytwoIsZeroPadded( $day ) {
                $this->assertZeroPadded( 'localday2', $day );
        }
 
        # month
 
-       /** @dataProvider MediaWikiProvide::Months */
-       function testCurrentmonthIsZeroPadded( $month ) {
+       /** @dataProvider provideMonths */
+       public function testCurrentmonthIsZeroPadded( $month ) {
                $this->assertZeroPadded( 'currentmonth', $month );
        }
 
-       /** @dataProvider MediaWikiProvide::Months */
-       function testCurrentmonthoneIsUnPadded( $month ) {
+       /** @dataProvider provideMonths */
+       public function testCurrentmonthoneIsUnPadded( $month ) {
                $this->assertUnPadded( 'currentmonth1', $month );
        }
 
-       /** @dataProvider MediaWikiProvide::Months */
-       function testLocalmonthIsZeroPadded( $month ) {
+       /** @dataProvider provideMonths */
+       public function testLocalmonthIsZeroPadded( $month ) {
                $this->assertZeroPadded( 'localmonth', $month );
        }
 
-       /** @dataProvider MediaWikiProvide::Months */
-       function testLocalmonthoneIsUnPadded( $month ) {
+       /** @dataProvider provideMonths */
+       public function testLocalmonthoneIsUnPadded( $month ) {
                $this->assertUnPadded( 'localmonth1', $month );
        }
 
-
        # revision day
 
-       /** @dataProvider MediaWikiProvide::Days */
-       function testRevisiondayIsUnPadded( $day ) {
+       /** @dataProvider provideDays */
+       public function testRevisiondayIsUnPadded( $day ) {
                $this->assertUnPadded( 'revisionday', $day );
        }
 
-       /** @dataProvider MediaWikiProvide::Days */
-       function testRevisiondaytwoIsZeroPadded( $day ) {
+       /** @dataProvider provideDays */
+       public function testRevisiondaytwoIsZeroPadded( $day ) {
                $this->assertZeroPadded( 'revisionday2', $day );
        }
 
        # revision month
 
-       /** @dataProvider MediaWikiProvide::Months */
-       function testRevisionmonthIsZeroPadded( $month ) {
+       /** @dataProvider provideMonths */
+       public function testRevisionmonthIsZeroPadded( $month ) {
                $this->assertZeroPadded( 'revisionmonth', $month );
        }
 
-       /** @dataProvider MediaWikiProvide::Months */
-       function testRevisionmonthoneIsUnPadded( $month ) {
+       /** @dataProvider provideMonths */
+       public function testRevisionmonthoneIsUnPadded( $month ) {
                $this->assertUnPadded( 'revisionmonth1', $month );
        }
 
@@ -136,15 +157,15 @@ class MagicVariableTest extends MediaWikiTestCase {
         * Rough tests for {{SERVERNAME}} magic word
         * Bug 31176
         * @group Database
-        * @dataProvider dataServernameFromDifferentProtocols
+        * @dataProvider provideDataServernameFromDifferentProtocols
         */
-       function testServernameFromDifferentProtocols( $server ) {
+       public function testServernameFromDifferentProtocols( $server ) {
                $this->setMwGlobals( 'wgServer', $server );
 
                $this->assertMagic( 'localhost', 'servername' );
        }
 
-       function dataServernameFromDifferentProtocols() {
+       public static function provideDataServernameFromDifferentProtocols() {
                return array(
                        array( 'http://localhost/' ),
                        array( 'https://localhost/' ),
@@ -155,12 +176,12 @@ class MagicVariableTest extends MediaWikiTestCase {
        ############### HELPERS ############################################
 
        /** assertion helper expecting a magic output which is zero padded */
-       PUBLIC function assertZeroPadded( $magic, $value ) {
+       public function assertZeroPadded( $magic, $value ) {
                $this->assertMagicPadding( $magic, $value, '%02d' );
        }
 
        /** assertion helper expecting a magic output which is unpadded */
-       PUBLIC function assertUnPadded( $magic, $value ) {
+       public function assertUnPadded( $magic, $value ) {
                $this->assertMagicPadding( $magic, $value, '%d' );
        }