Example data provider
authorMark A. Hershberger <mah@users.mediawiki.org>
Sat, 23 Oct 2010 16:41:03 +0000 (16:41 +0000)
committerMark A. Hershberger <mah@users.mediawiki.org>
Sat, 23 Oct 2010 16:41:03 +0000 (16:41 +0000)
maintenance/tests/phpunit/includes/SampleTest.php

index 905ff79..065b98a 100644 (file)
@@ -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
         *