PHP Fatal error: Declaration of Tests\TestCase::setUp() must be compatible

25 Jul 2019 . Tips and Tricks . 151 views

Hello

If you are suddenly facing the issue on Laravel testing that, PHP Fatal error: Declaration of Tests\TestCase::setUp() must be compatible with Illuminate\Foundation\Testing\TestCase::setUp():.... in that case, this post might be helpful for you.

Normally it happened because of PHP Unit 8 incompatibility issue. If you suddenly upgrade your Laravel version, you might have a high chance to face this issue.

How to solve?

To solve this issue, you need to go to tests/Feature/UserTest.php file and make this change.

class UserTest extends TestCase
{
        public function setUp(): void
   	{
                parent::setUp();

Here, I just add : void after the setUp() method name.

Reference: https://github.com/realodix/urlhub/pull/233

Hope it will work for you.