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 *

Bad art was as good as good art. Grammar and spelling were no longer important. To be clean was no better than to be filthy. Good manners were no better than bad. Family life was derided as an outdated bourgeois concept. Criminals deserved as much sympathy as their victims. Many homes and classrooms became disorderly – if there was neither right nor wrong there could be no basis for punishment or reward. Violence and soft pornography became accepted in the media. Thus was sown the wind; and we are now reaping the whirlwind.

— Norman Tebbit