3 class TestSample
extends PHPUnit_Framework_TestCase
{
6 * Anything that needs to happen before your tests should go here.
12 * Anything cleanup you need to do should go here.
17 function testEqual() {
18 $title = Title
::newFromText("text");
19 $this->assertEquals("Text", $title->__toString(), "Title creation");
20 $this->assertEquals("Text", "Text", "Automatic string conversion");
22 $title = Title
::newFromText("text", NS_MEDIA
);
23 $this->assertEquals("Media:Text", $title->__toString(), "Title creation with namespace");
28 * If you want to run a the same test with a variety of data. use a data provider.
29 * see: http://www.phpunit.de/manual/3.4/en/writing-tests-for-phpunit.html
31 public function provideTitles() {
33 array( 'Text', NS_MEDIA
, 'Media:Text' ),
34 array( 'Text', null, 'Text' ),
35 array( 'text', null, 'Text' ),
36 array( 'Text', NS_USER
, 'User:Text' ),
37 array( 'Text', NS_USER
, 'Blah' )
42 * @dataProvider provideTitles()
43 * See http://www.phpunit.de/manual/3.4/en/appendixes.annotations.html#appendixes.annotations.dataProvider
45 public function testTitleCreation($titleName, $ns, $text) {
46 $title = Title
::newFromText($titleName, $ns);
47 $this->assertEquals($text, "$title", "see if '$titleName' matches '$text'");
50 public function testInitialCreation() {
51 $title = Title
::newMainPage();
52 $this->assertEquals("Main Page", "$title", "Test initial creation of a title");
58 * Instead of putting a bunch of tests in a single test method,
59 * you should put only one or two tests in each test method. This
60 * way, the test method names can remain descriptive.
62 * If you want to make tests depend on data created in another
63 * method, you can create dependencies feed whatever you return
64 * from the dependant method (e.g. testInitialCreation in this
65 * example) as arguments to the next method (e.g. $title in
66 * testTitleDepends is whatever testInitialCreatiion returned.)
69 * @depends testInitialCreation
70 * See http://www.phpunit.de/manual/3.4/en/appendixes.annotations.html#appendixes.annotations.depends
72 public function testTitleDepends( $title ) {
73 $this->assertTrue( $title->isLocal() );
77 * If the code you're testing can produce Exceptions, you can also
78 * test for them. In the following example, the test expects a
79 * MWException containing the string "object" in the message..
82 * @expectedException MWException object
83 * See http://www.phpunit.de/manual/3.4/en/appendixes.annotations.html#appendixes.annotations.expectedException
85 function testException() {
86 $title = Title
::newFromText(new Title("test"));