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?
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');
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With