Laravel 5.8 and PHPUnit tearDown!

When trying to run my Laravel/PHPUnit integration tests I received this error:

ReflectionException: Class config does not exist

It is one of those vague error messages that can be triggered by a lot of different problems and none of the many solutions to these common issues worked for me. In the end the solution came down to some detective work.

I use the setUp() and tearDown() method. What was going wrong was that I did the parent::tearDown() before the rest of the cleanup. So a case of trying to use data after it has been torn down. The following is how it should be setup:

public function setUp(): void
{
   parent::setUp(); // Must be first
   // Your own setup
}
public function tearDown(): void
{
   // Your own teardown MUST come before down the parent::tearDown
   parent::tearDown(); // Must be last
} 

Share Article

Comments: None so far...be the first!

Leave a reply

Please fill in the form fields and improve Skynet by completing the captcha!

Thank you! All comments are moderated so yours will appear shortly.

The truth unspoken is the coin of tomorrow.

— Haldwin