php - Why does file_get_contents function give me a syntax error when used in PHPUnit test, but works fine otherwise? -


i have class i'm trying run tests on. 1 of functions supposed take in long string 1 of parameters. in production, string come database, now, i'm reading out of .txt file.

in stages, testing adding bottom of same file class in:

$testfile = file_get_contents('./test.txt'); 

and passing $testfile function, , worked fine. i'm trying make actual unit tests, , here's have test that, , bare in mind, experience phpunit pretty limited:

class stacktest extends phpunit_framework_testcase {      public $file = file_get_contents('/path/to/test.txt');      public function setup() {         //instantiate object using $file     }      public function testfileparser() {         //test function     } } 

but when run phpunit on test, give me error:

php parse error:  syntax error, unexpected '(', expecting ',' or ';' in /path/to/tests/tests.php on line 9 

with line 9 being line file_get_contents on. know why it's doing this?

you can't use functions initialize property.

you may in method in case :

class stacktest extends phpunit_framework_testcase {  public $file;  public function setup() {      $this->file = file_get_contents('/path/to/test.txt'); }  public function testfileparser() {     //test function } 

}


Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

javascript - Get parameter of GET request -

javascript - Twitter Bootstrap - how to add some more margin between tooltip popup and element -