PHP : First Unit Test

Code to be tested

// Check.php
class Check {
	public function spitFalse() {
		return false;
	}	
	public function spitTrue() {
		return true;
	}
}

Test Code

// CheckTest.php
require_once('Check.php');
class CheckTest extends PHPUnit_Framework_TestCase
{
	public function setUp(){ }
	public function tearDown(){ }
	public function testSpitFalse() {
		$chk = new Check();
		$this->assertFalse($chk->spitFalse());
	}	
	public function testSpitTrue() {
		$chk = new Check();
		$this->assertTrue($chk->spitFalse());
	}
}

Run Test Code

phpunit CheckTest

Result

OK (2 tests, 2 assertions)
Advertisements

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

%d bloggers like this: