Summer Sale! All accounts are 50% off this week.

andreich1980's avatar

How to delete temporary folder in tearDown

My laravel app can create a folder.

In a feature test I call the endpoint. The app creates a folder with data.

I want to delete the folder after test.

I created tearDown() method

protected function tearDown() {
    parent::tearDown();
    \File::deleteDirectory(public_path($this->folder));
}

And I receive an error

Class path.public does not exist

If I pass a real path

\File::deleteDirectory('D:\path\to\the\folder');

It deletes the folder but I still receive another error

Class files does not exist

But both of them work fine in a test method. What's wrong with tearDown()? (or with me?)

0 likes
3 replies
bheath's avatar
bheath
Best Answer
Level 3

I believe all that gets destroyed in the parent teardown, so try moving your delete to before parent::teardown()?

3 likes

Please or to participate in this conversation.