Skip to content

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

Merged
taylorotwell merged 1 commit into
laravel:9.xfrom
JayBizzle:patch-2
Mar 9, 2022
Merged

[9.x] Add empty directory assertion to Storage::fake()#41398
taylorotwell merged 1 commit into
laravel:9.xfrom
JayBizzle:patch-2

Conversation

@JayBizzle

@JayBizzle JayBizzle commented Mar 8, 2022

Copy link
Copy Markdown
Contributor

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
Copy Markdown
Member

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

@JayBizzle

Copy link
Copy Markdown
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