Using SimpleTest in PHP5

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
dimxasnewfrozen
Forum Commoner
Posts: 84
Joined: Fri Oct 30, 2009 1:21 pm

Using SimpleTest in PHP5

Post by dimxasnewfrozen »

I'm trying to learn how to use the SimpleTest Library. I found a simple example of how to try it out:

Code: Select all

define('TAX_RATE', 0.07);
define('URL', $_SERVER['DOCUMENT_ROOT']);
function caluclate_sales_tax($amount) {
	round($amount * TAX_RATE, 2);
}

// Include Test Library
require_once URL.'/simpletest/unit_tester.php';
require_once URL.'/simpletest/reporter.php';

// The test
class TestingTestCase extends UnitTestCase {
	public function TestingTestCase($name=''){
		$this->UnitTestCase($name);
	}
	public function TestSalesTax(){
		$this->assertEqual(7, calculate_sales_tax(100));
	}
}

$test = new TestingTestCase('Testing Unit Test');
$test->run(new htmlReporter());
This is a PHP4 Example and I'm using PHP5 and getting the error:
"Assigning the return value of new by reference is deprecated"

I read something about passing an object as reference instead of value with the different versions but I'm not quite sure where/how/why its happening.
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: Using SimpleTest in PHP5

Post by Christopher »

In PHP5 you don't need to pass objects around by reference. Your function does not return any value.
(#10850)
User avatar
Eran
DevNet Master
Posts: 3549
Joined: Fri Jan 18, 2008 12:36 am
Location: Israel, ME

Re: Using SimpleTest in PHP5

Post by Eran »

SimpleTest still supports PHP4 for legacy reasons. To run simpletest tests without error warnings you'd need to turn off deprecated level errors.
Post Reply