From 206aae2a7a5c97a7e0af3bed8e842635504de306 Mon Sep 17 00:00:00 2001 From: Andrew Huggins Date: Wed, 19 Apr 2017 20:01:59 -0400 Subject: [PATCH] add tests, update changelog, increase readability --- CHANGELOG-5.5.md | 3 +++ src/Illuminate/Filesystem/Filesystem.php | 17 ++++++++++++----- tests/Filesystem/FilesystemTest.php | 24 ++++++++++++++++++++++++ 3 files changed, 39 insertions(+), 5 deletions(-) diff --git a/CHANGELOG-5.5.md b/CHANGELOG-5.5.md index b2e8d05abcc4..ebd46c280ae6 100644 --- a/CHANGELOG-5.5.md +++ b/CHANGELOG-5.5.md @@ -53,6 +53,9 @@ ### Events - ⚠️ Removed calling queue method on handlers ([0360cb1](https://github.com/laravel/framework/commit/0360cb1c6b71ec89d406517b19d1508511e98fb5), [ec96979](https://github.com/laravel/framework/commit/ec969797878f2c731034455af2397110732d14c4), [d9be4bf](https://github.com/laravel/framework/commit/d9be4bfe0367a8e07eed4931bdabf135292abb1b)) +### Filesystem +- ⚠️ Made `Storage::files()` work like `Storage::allFiles()` ([#18874](https://github.com/laravel/framework/pull/18874)) + ### Helpers - Added `throw_if()` and `throw_unless()` helpers ([18bb4df](https://github.com/laravel/framework/commit/18bb4dfc77c7c289e9b40c4096816ebeff1cd843)) - Added `dispatch_now()` helper function ([#18668](https://github.com/laravel/framework/pull/18668), [61f2e7b](https://github.com/laravel/framework/commit/61f2e7b4106f8eb0b79603d9792426f7c6a6d273)) diff --git a/src/Illuminate/Filesystem/Filesystem.php b/src/Illuminate/Filesystem/Filesystem.php index e2a2135db799..56938c189766 100644 --- a/src/Illuminate/Filesystem/Filesystem.php +++ b/src/Illuminate/Filesystem/Filesystem.php @@ -370,23 +370,30 @@ public function glob($pattern, $flags = 0) * Get an array of all files in a directory. * * @param string $directory + * @param bool $ignoreDotFiles * @return array */ - public function files($directory, $hidden = false) + public function files($directory, $ignoreDotFiles = false) { - return iterator_to_array(Finder::create()->files()->ignoreDotFiles(! $hidden)->in($directory)->depth(0), false); + return iterator_to_array( + Finder::create()->files()->ignoreDotFiles(! $ignoreDotFiles)->in($directory)->depth(0), + false + ); } /** * Get all of the files from the given directory (recursive). * * @param string $directory - * @param bool $hidden + * @param bool $ignoreDotFiles * @return array */ - public function allFiles($directory, $hidden = false) + public function allFiles($directory, $ignoreDotFiles = false) { - return iterator_to_array(Finder::create()->files()->ignoreDotFiles(! $hidden)->in($directory), false); + return iterator_to_array( + Finder::create()->files()->ignoreDotFiles(! $ignoreDotFiles)->in($directory), + false + ); } /** diff --git a/tests/Filesystem/FilesystemTest.php b/tests/Filesystem/FilesystemTest.php index 427d01fb3e0b..fb6bf0a2de10 100755 --- a/tests/Filesystem/FilesystemTest.php +++ b/tests/Filesystem/FilesystemTest.php @@ -414,4 +414,28 @@ public function testIsFileChecksFilesProperly() $this->assertTrue($filesystem->isFile($this->tempDir.'/foo/foo.txt')); $this->assertFalse($filesystem->isFile($this->tempDir.'./foo')); } + + public function testFilesMethodReturnsFileInfoObjects() + { + mkdir($this->tempDir.'/foo'); + file_put_contents($this->tempDir.'/foo/1.txt', '1'); + file_put_contents($this->tempDir.'/foo/2.txt', '2'); + mkdir($this->tempDir.'/foo/bar'); + $files = new Filesystem(); + foreach ($files->files($this->tempDir.'/foo') as $file) { + $this->assertInstanceOf(\SplFileInfo::class, $file); + } + unset($files); + } + + public function testAllFilesReturnsFileInfoObjects() + { + file_put_contents($this->tempDir.'/foo.txt', 'foo'); + file_put_contents($this->tempDir.'/bar.txt', 'bar'); + $files = new Filesystem(); + $allFiles = []; + foreach ($files->allFiles($this->tempDir) as $file) { + $this->assertInstanceOf(\SplFileInfo::class, $file); + } + } }