oop - variables scope in php -
why can define new instance of class adrequest
inside function this:
require_once 'adrequest.php'; class adrequesttest extends phpunit_framework_testcase{ public $fixture; function testgethash_returnscorrectvalue(){ $fixture = new adrequest(); $fixture->site = "dummy.com"; } }
but when trying create instance this:
require_once 'adrequest.php'; class adrequesttest extends phpunit_framework_testcase{ public $fixture; $fixture = new adrequest(); function testgethash_returnscorrectvalue(){ $fixture->site = "dummy.com"; } }
i got error:
php parse error: syntax error, unexpected '$fixture' (t_variable), expecting function (t_function)
if want create instance once , use in every function , use setup()
, setup() called before each testxxx() method
<?php require_once 'adrequest.php'; class adrequesttest extends phpunit_framework_testcase{ public $fixture; public function setup() { $this->fixture = new adrequest(); } function testgethash_returnscorrectvalue(){ $this->fixture->site = "dummy.com"; }
Comments
Post a Comment