Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

php fatal error Declaration of UserTest setUp function

I had to do a PHPUnit testing with setUp function given below:

use PHPUnit\Framework\TestCase;

class UserTest extends TestCase
{
    public function setUp()
    {
       var_dump('1');
    }
}

When I run this test it shows me these errors:

PHP Fatal error:  Declaration of UserTest::setUp() must be compatible with PHPUnit\Framework\TestCase::setUp(): void

How can I fix it?

like image 444
shawn Avatar asked Dec 17 '22 15:12

shawn


2 Answers

You need to declare the return type of template methods such as setUp() to be :void. This is explained here and here.

like image 60
Sebastian Bergmann Avatar answered Dec 20 '22 04:12

Sebastian Bergmann


I fixed this error with a quick time by using void method like given below:

 public function setUp(): void
 {
    var_dump('1');
 }
like image 36
shawn Avatar answered Dec 20 '22 05:12

shawn