From 7675773aa9e78cbd3084f2ed2cbea58440922e27 Mon Sep 17 00:00:00 2001 From: Antoine Musso Date: Sun, 6 Feb 2011 21:28:57 +0000 Subject: [PATCH] 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. --- tests/TestsAutoLoader.php | 3 ++ tests/phpunit/includes/Providers.php | 44 ++++++++++++++++++ .../includes/parser/MagicVariableTest.php | 46 +++++-------------- 3 files changed, 59 insertions(+), 34 deletions(-) create mode 100644 tests/phpunit/includes/Providers.php diff --git a/tests/TestsAutoLoader.php b/tests/TestsAutoLoader.php index 35bf20c37c..bc19cdf949 100644 --- a/tests/TestsAutoLoader.php +++ b/tests/TestsAutoLoader.php @@ -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 index 0000000000..90c9eb31d8 --- /dev/null +++ b/tests/phpunit/includes/Providers.php @@ -0,0 +1,44 @@ +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; + } +} diff --git a/tests/phpunit/includes/parser/MagicVariableTest.php b/tests/phpunit/includes/parser/MagicVariableTest.php index bd5500139c..507fbfd101 100644 --- a/tests/phpunit/includes/parser/MagicVariableTest.php +++ b/tests/phpunit/includes/parser/MagicVariableTest.php @@ -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 ); - } } -- 2.20.1