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
} 
Comments: None so far...be the first!

Leave a reply

Your email address will not be published. Required fields are marked *

Now I know I’ve got a heart, ’cause it’s breaking…

— Tin Woodsman