php fatal error Declaration of UserTest setUp function

Viewed 3945

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?

2 Answers

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

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

 public function setUp(): void
 {
    var_dump('1');
 }
Related