PHP Unit Test – part 1

Prerequisites:

  1. PHPUnit Framework installed
  2. extends class PHPUnit_Framework_TestCase

phpunit

  • Test number
class StackTest extends PHPUnit_Framework_TestCase
{
    public function testFailureNumber(){
        $this->assertEquals(1, 1);
    }
}
  • Test string
public function testFailureNumber(){
    $this->assertEquals(1, 1);
 }
  • Test xml
public function testFailureXml(){
    $expected = new DOMDocument;
    $expected->loadXML('<foo><bar/></foo>');
    $actual = new DOMDocument();
    $actual->loadXML('<foo><bar/></foo>');
    $this->assertEquals($expected, $actual);
 }
  • Test object
public function testFailureObject(){
    $expected = new stdClass();
    $expected->foo = 'foo';
    $expected->bar = 'bar';
    $actual = new stdClass();
    $actual->foo = 'foo';
    $actual->bar = 'bar';
    $this->assertEquals($expected, $actual);
 }
Advertisements

One thought on “PHP Unit Test – part 1

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s