Move some providers in new MediaWikiProvide class
authorAntoine Musso <hashar@users.mediawiki.org>
Sun, 6 Feb 2011 21:28:57 +0000 (21:28 +0000)
committerAntoine Musso <hashar@users.mediawiki.org>
Sun, 6 Feb 2011 21:28:57 +0000 (21:28 +0000)
The MediaWikiProvide class would host providing methods reused in different
tests classes.  To use it, just use the Class::function syntax.

Example:
  /** @dataProvider MediaWikiProvide::Months */

Made a svn copy of phpunit/includes/parser/MagicVariableTest.php
to save the history.

tests/TestsAutoLoader.php
tests/phpunit/includes/Providers.php [new file with mode: 0644]
tests/phpunit/includes/parser/MagicVariableTest.php

index 35bf20c..bc19cdf 100644 (file)
@@ -19,5 +19,8 @@ $wgAutoloadClasses += array(
                
        //Selenium
        'SeleniumTestConstants' => "$testFolder/selenium/SeleniumTestConstants.php",
+
+       //Generic providers
+       'MediaWikiProvide' => "$testFolder/phpunit/includes/Providers.php",
 );
 
diff --git a/tests/phpunit/includes/Providers.php b/tests/phpunit/includes/Providers.php
new file mode 100644 (file)
index 0000000..90c9eb3
--- /dev/null
@@ -0,0 +1,44 @@
+<?php
+/**
+ * Generic providers for the MediaWiki PHPUnit test suite
+ *
+ * @author Ashar Voultoiz
+ * @copyright Copyright © 2011, Ashar Voultoiz
+ * @file
+ */
+
+/** */
+class MediaWikiProvide {
+
+       /* provide an array of numbers from 1 up to @param $num */
+       private function createProviderUpTo( $num ) {
+               $ret = array();
+               for( $i=1; $i<=$num;$i++ ) {
+                       $ret[] = array( $i );
+               }
+               return $ret;
+       }
+
+       /* array of months numbers (as an integer) */
+       public function Months() {
+               return $this->createProviderUpTo( 12 );
+       }
+
+       /* array of days numbers (as an integer) */
+       public function Days() {
+               return $this->createProviderUpTo( 31 );
+       }
+
+       public 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 bd55001..507fbfd 100644 (file)
@@ -52,38 +52,38 @@ class MagicVariableTest extends PHPUnit_Framework_TestCase {
 
        # day
 
-       /** @dataProvider provideDays */
+       /** @dataProvider MediaWikiProvide::Days */
        function testCurrentdayIsUnPadded( $day ) {
                $this->assertUnPadded( 'currentday', $day );
        }
-       /** @dataProvider provideDays */
+       /** @dataProvider MediaWikiProvide::Days */
        function testCurrentdaytwoIsZeroPadded( $day ) {
                $this->assertZeroPadded( 'currentday2', $day );
        }
-       /** @dataProvider provideDays */
+       /** @dataProvider MediaWikiProvide::Days */
        function testLocaldayIsUnPadded( $day ) {
                $this->assertUnPadded( 'localday', $day );
        }
-       /** @dataProvider provideDays */
+       /** @dataProvider MediaWikiProvide::Days */
        function testLocaldaytwoIsZeroPadded( $day ) {
                $this->assertZeroPadded( 'localday2', $day );
        }
        
        # month
 
-       /** @dataProvider provideMonths */
+       /** @dataProvider MediaWikiProvide::Months */
        function testCurrentmonthIsZeroPadded( $month ) {
                $this->assertZeroPadded( 'currentmonth', $month );
        }
-       /** @dataProvider provideMonths */
+       /** @dataProvider MediaWikiProvide::Months */
        function testCurrentmonthoneIsUnPadded( $month ) {
                $this->assertUnPadded( 'currentmonth1', $month );
        }
-       /** @dataProvider provideMonths */
+       /** @dataProvider MediaWikiProvide::Months */
        function testLocalmonthIsZeroPadded( $month ) {
                $this->assertZeroPadded( 'localmonth', $month );
        }
-       /** @dataProvider provideMonths */
+       /** @dataProvider MediaWikiProvide::Months */
        function testLocalmonthoneIsUnPadded( $month ) {
                $this->assertUnPadded( 'localmonth1', $month );
        }
@@ -91,22 +91,22 @@ class MagicVariableTest extends PHPUnit_Framework_TestCase {
 
        # revision day
 
-       /** @dataProvider provideDays */
+       /** @dataProvider MediaWikiProvide::Days */
        function testRevisiondayIsUnPadded( $day ) {
                $this->assertUnPadded( 'revisionday', $day );
        }
-       /** @dataProvider provideDays */
+       /** @dataProvider MediaWikiProvide::Days */
        function testRevisiondaytwoIsZeroPadded( $day ) {
                $this->assertZeroPadded( 'revisionday2', $day );
        }
        
        # revision month
 
-       /** @dataProvider provideMonths */
+       /** @dataProvider MediaWikiProvide::Months */
        function testRevisionmonthIsZeroPadded( $month ) {
                $this->assertZeroPadded( 'revisionmonth', $month );
        }
-       /** @dataProvider provideMonths */
+       /** @dataProvider MediaWikiProvide::Months */
        function testRevisionmonthoneIsUnPadded( $month ) {
                $this->assertUnPadded( 'revisionmonth1', $month );
        }
@@ -174,26 +174,4 @@ class MagicVariableTest extends PHPUnit_Framework_TestCase {
                        $msg
                );
        }
-
-
-       ############## PROVIDERS ##########################################
-
-       /* provide an array of numbers from 1 up to @param $num */
-       private function createProviderUpTo( $num ) {
-               $ret = array();
-               for( $i=1; $i<=$num;$i++ ) {
-                       $ret[] = array( $i );
-               }
-               return $ret;
-       }
-
-       /* array of months numbers (as an integer) */
-       public function provideMonths() {
-               return $this->createProviderUpTo( 12 );
-       }
-
-       /* array of days numbers (as an integer) */
-       public function provideDays() {
-               return $this->createProviderUpTo( 31 );
-       }
 }