Skip to content

Commit

Permalink
add tests, update changelog, increase readability
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrew Huggins committed Apr 20, 2017
1 parent 0665f95 commit 206aae2
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 5 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG-5.5.md
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
17 changes: 12 additions & 5 deletions src/Illuminate/Filesystem/Filesystem.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
);
}

/**
Expand Down
24 changes: 24 additions & 0 deletions tests/Filesystem/FilesystemTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}

0 comments on commit 206aae2

Please sign in to comment.