r81607 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r81606‎ | r81607 | r81608 >
Date:21:28, 6 February 2011
Author:hashar
Status:ok
Tags:
Comment:
Move some providers in new MediaWikiProvide class

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.
Modified paths:
  • /trunk/phase3/tests/TestsAutoLoader.php (modified) (history)
  • /trunk/phase3/tests/phpunit/includes/Providers.php (added) (history)
  • /trunk/phase3/tests/phpunit/includes/parser/MagicVariableTest.php (modified) (history)

Diff [purge]

Index: trunk/phase3/tests/phpunit/includes/parser/MagicVariableTest.php
@@ -52,38 +52,38 @@
5353
5454 # day
5555
56 - /** @dataProvider provideDays */
 56+ /** @dataProvider MediaWikiProvide::Days */
5757 function testCurrentdayIsUnPadded( $day ) {
5858 $this->assertUnPadded( 'currentday', $day );
5959 }
60 - /** @dataProvider provideDays */
 60+ /** @dataProvider MediaWikiProvide::Days */
6161 function testCurrentdaytwoIsZeroPadded( $day ) {
6262 $this->assertZeroPadded( 'currentday2', $day );
6363 }
64 - /** @dataProvider provideDays */
 64+ /** @dataProvider MediaWikiProvide::Days */
6565 function testLocaldayIsUnPadded( $day ) {
6666 $this->assertUnPadded( 'localday', $day );
6767 }
68 - /** @dataProvider provideDays */
 68+ /** @dataProvider MediaWikiProvide::Days */
6969 function testLocaldaytwoIsZeroPadded( $day ) {
7070 $this->assertZeroPadded( 'localday2', $day );
7171 }
7272
7373 # month
7474
75 - /** @dataProvider provideMonths */
 75+ /** @dataProvider MediaWikiProvide::Months */
7676 function testCurrentmonthIsZeroPadded( $month ) {
7777 $this->assertZeroPadded( 'currentmonth', $month );
7878 }
79 - /** @dataProvider provideMonths */
 79+ /** @dataProvider MediaWikiProvide::Months */
8080 function testCurrentmonthoneIsUnPadded( $month ) {
8181 $this->assertUnPadded( 'currentmonth1', $month );
8282 }
83 - /** @dataProvider provideMonths */
 83+ /** @dataProvider MediaWikiProvide::Months */
8484 function testLocalmonthIsZeroPadded( $month ) {
8585 $this->assertZeroPadded( 'localmonth', $month );
8686 }
87 - /** @dataProvider provideMonths */
 87+ /** @dataProvider MediaWikiProvide::Months */
8888 function testLocalmonthoneIsUnPadded( $month ) {
8989 $this->assertUnPadded( 'localmonth1', $month );
9090 }
@@ -91,22 +91,22 @@
9292
9393 # revision day
9494
95 - /** @dataProvider provideDays */
 95+ /** @dataProvider MediaWikiProvide::Days */
9696 function testRevisiondayIsUnPadded( $day ) {
9797 $this->assertUnPadded( 'revisionday', $day );
9898 }
99 - /** @dataProvider provideDays */
 99+ /** @dataProvider MediaWikiProvide::Days */
100100 function testRevisiondaytwoIsZeroPadded( $day ) {
101101 $this->assertZeroPadded( 'revisionday2', $day );
102102 }
103103
104104 # revision month
105105
106 - /** @dataProvider provideMonths */
 106+ /** @dataProvider MediaWikiProvide::Months */
107107 function testRevisionmonthIsZeroPadded( $month ) {
108108 $this->assertZeroPadded( 'revisionmonth', $month );
109109 }
110 - /** @dataProvider provideMonths */
 110+ /** @dataProvider MediaWikiProvide::Months */
111111 function testRevisionmonthoneIsUnPadded( $month ) {
112112 $this->assertUnPadded( 'revisionmonth1', $month );
113113 }
@@ -174,26 +174,4 @@
175175 $msg
176176 );
177177 }
178 -
179 -
180 - ############## PROVIDERS ##########################################
181 -
182 - /* provide an array of numbers from 1 up to @param $num */
183 - private function createProviderUpTo( $num ) {
184 - $ret = array();
185 - for( $i=1; $i<=$num;$i++ ) {
186 - $ret[] = array( $i );
187 - }
188 - return $ret;
189 - }
190 -
191 - /* array of months numbers (as an integer) */
192 - public function provideMonths() {
193 - return $this->createProviderUpTo( 12 );
194 - }
195 -
196 - /* array of days numbers (as an integer) */
197 - public function provideDays() {
198 - return $this->createProviderUpTo( 31 );
199 - }
200178 }
Index: trunk/phase3/tests/phpunit/includes/Providers.php
@@ -0,0 +1,44 @@
 2+<?php
 3+/**
 4+ * Generic providers for the MediaWiki PHPUnit test suite
 5+ *
 6+ * @author Ashar Voultoiz
 7+ * @copyright Copyright © 2011, Ashar Voultoiz
 8+ * @file
 9+ */
 10+
 11+/** */
 12+class MediaWikiProvide {
 13+
 14+ /* provide an array of numbers from 1 up to @param $num */
 15+ private function createProviderUpTo( $num ) {
 16+ $ret = array();
 17+ for( $i=1; $i<=$num;$i++ ) {
 18+ $ret[] = array( $i );
 19+ }
 20+ return $ret;
 21+ }
 22+
 23+ /* array of months numbers (as an integer) */
 24+ public function Months() {
 25+ return $this->createProviderUpTo( 12 );
 26+ }
 27+
 28+ /* array of days numbers (as an integer) */
 29+ public function Days() {
 30+ return $this->createProviderUpTo( 31 );
 31+ }
 32+
 33+ public function DaysMonths() {
 34+ $ret = array();
 35+
 36+ $months = self::Months();
 37+ $days = self::Days();
 38+ foreach( $months as $month) {
 39+ foreach( $days as $day ) {
 40+ $ret[] = array( $day[0], $month[0] );
 41+ }
 42+ }
 43+ return $ret;
 44+ }
 45+}
Property changes on: trunk/phase3/tests/phpunit/includes/Providers.php
___________________________________________________________________
Added: svn:eol-style
146 + native
Index: trunk/phase3/tests/TestsAutoLoader.php
@@ -19,5 +19,8 @@
2020
2121 //Selenium
2222 'SeleniumTestConstants' => "$testFolder/selenium/SeleniumTestConstants.php",
 23+
 24+ //Generic providers
 25+ 'MediaWikiProvide' => "$testFolder/phpunit/includes/Providers.php",
2326 );
2427

Follow-up revisions

RevisionCommit summaryAuthorDate
r82369Fix wrong static callsreedy01:00, 18 February 2011

Status & tagging log