Page 1 of 1

PHPUnit2 help needed

Posted: Mon Jul 31, 2006 8:08 pm
by blizzard_jdf
feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


Need a simple PHPUnit2 example. I have used the BankAccount class and used a simple example called BankAccountTest which has one test. What I need is the code to show the test results in the browser.

Code: Select all

<?php

require_once 'PHPUnit2/Framework/TestCase.php';
require_once 'PHPUnit2/Framework/TestSuite.php';
require_once 'PHPUnit2/Framework/TestResult.php';

class BankAccount{
	private $balance = 0;
	
	public function getBalance(){
		return $this->balance;
	}

	public function setBalance($balance){
		if ($balance >= 0) {
			$this->balance  =$balance;
		}
		else {
			throw new InvalidArgumentException;
		}
	}

	public function depositMoney($amount){
		if($amount >= 0 ){
			$this->balance += $amount;
		}
		else {
			throw new InvalidArgumentException;
		}
	}

	public function withdrawMoney($amount){
		if ($amount >= 0 && $this->balance >= $amount) {
			$this->balance -= $amount;
		}	else {
				throw new InvalidArgumentException;
			}
		
		}
	}

class BankAccountTest extends PHPUnit2_Framework_TestCase{
	
	private $ba;
	
	protected function setUp(){
		$this->ba = new BankAccount;	
	}

	public function testBalanceIsInitiallyZero(){
		$this-> assertEquals(0, $this->ba->getBalance());
	}


}

//Need code to display test results

?>

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]

Posted: Tue Aug 01, 2006 8:05 am
by Buddha443556
Might look into PHPUnit2 HTML Runner.