Page 1 of 1

Using SimpleTest in PHP5

Posted: Mon Apr 26, 2010 1:14 pm
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.

Re: Using SimpleTest in PHP5

Posted: Mon Apr 26, 2010 4:46 pm
by Christopher
In PHP5 you don't need to pass objects around by reference. Your function does not return any value.

Re: Using SimpleTest in PHP5

Posted: Mon Apr 26, 2010 4:54 pm
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.