From e2a9337f4d17ce3b90587b516c0ee56c703d77cc Mon Sep 17 00:00:00 2001 From: "Mark A. Hershberger" Date: Sat, 23 Oct 2010 16:41:03 +0000 Subject: [PATCH] Example data provider --- .../tests/phpunit/includes/SampleTest.php | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/maintenance/tests/phpunit/includes/SampleTest.php b/maintenance/tests/phpunit/includes/SampleTest.php index 905ff796ac..065b98ab10 100644 --- a/maintenance/tests/phpunit/includes/SampleTest.php +++ b/maintenance/tests/phpunit/includes/SampleTest.php @@ -2,9 +2,18 @@ class TestSample extends PHPUnit_Framework_TestCase { + /** + * Anything that needs to happen before your tests should go here. + */ function setUp() { } + /** + * Anything cleanup you need to do should go here. + */ + function tearDown() { + } + function testEqual() { $title = Title::newFromText("text"); $this->assertEquals("Text", $title->__toString(), "Title creation"); @@ -15,6 +24,27 @@ class TestSample extends PHPUnit_Framework_TestCase { } + /** + * If you want to run a the same test with a variety of data. use a data provider. + * See: http://www.phpunit.de/manual/3.4/en/writing-tests-for-phpunit.html + */ + public function provideTitles() { + return array( + array( 'Text', NS_MEDIA, 'Media:Text' ), + array( 'Text', null, 'Text' ), + array( 'Text', NS_USER, 'User:Text' ), + array( 'Text', NS_USER, 'Blah' ) + ); + } + + /** + * @dataProvider provideTitles() + */ + public function testCreation($titleName, $ns, $text) { + $title = Title::newFromText($titleName, $ns); + $this->assertEquals($text, "$title", "see if '$titleName' matches '$text'"); + } + /** * @expectedException MWException object * -- 2.20.1