Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[9.x] Add empty directory assertion to Storage::fake() #41398

Merged
merged 1 commit into from
Mar 9, 2022
Merged

[9.x] Add empty directory assertion to Storage::fake() #41398

merged 1 commit into from
Mar 9, 2022

Conversation

JayBizzle
Copy link
Contributor

@JayBizzle JayBizzle commented Mar 8, 2022

I was trying to assert that a given directory was empty in some tests and was surprised to see that there was no bulit-in assertion to handle this.

This PR proposes adding an assertDirectoryEmpty($path) method to the Storage fake.

Obviously this is just a cleaner version of doing...

$this->assertEmpty(Storage::disk('temp')->allFiles('/foo'));

vs

Storage::disk('temp')->assertDirectoryEmpty('/foo');

@taylorotwell
Copy link
Member

What is the behavior if there are no files within the directory but there are other sub-directories?

@JayBizzle
Copy link
Contributor Author

What is the behavior if there are no files within the directory but there are other sub-directories?

The assertion will fail, correctly IMO as the directory is not empty if it contains other folders

Storage::fake('temp');

Storage::disk('temp')->put('/foo/bar.txt', 'string');

Storage::disk('temp')->assertDirectoryEmpty('/'); // fail

@taylorotwell taylorotwell merged commit e98ceae into laravel:9.x Mar 9, 2022
@JayBizzle JayBizzle deleted the patch-2 branch March 15, 2022 19:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants