Skip to content

Commit

Permalink
Finder: default mask is '*'
Browse files Browse the repository at this point in the history
  • Loading branch information
dg committed Jul 30, 2023
1 parent d4f51c2 commit dfda0ca
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/Utils/Finder.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class Finder implements \IteratorAggregate
/**
* Begins search for files and directories matching mask.
*/
public static function find(string|array $masks): static
public static function find(string|array $masks = ['*']): static
{
$masks = is_array($masks) ? $masks : func_get_args(); // compatibility with variadic
return (new static)->addMask($masks, 'dir')->addMask($masks, 'file');
Expand All @@ -61,7 +61,7 @@ public static function find(string|array $masks): static
/**
* Begins search for files matching mask.
*/
public static function findFiles(string|array $masks): static
public static function findFiles(string|array $masks = ['*']): static
{
$masks = is_array($masks) ? $masks : func_get_args(); // compatibility with variadic
return (new static)->addMask($masks, 'file');
Expand All @@ -71,7 +71,7 @@ public static function findFiles(string|array $masks): static
/**
* Begins search for directories matching mask.
*/
public static function findDirectories(string|array $masks): static
public static function findDirectories(string|array $masks = ['*']): static
{
$masks = is_array($masks) ? $masks : func_get_args(); // compatibility with variadic
return (new static)->addMask($masks, 'dir');
Expand All @@ -81,7 +81,7 @@ public static function findDirectories(string|array $masks): static
/**
* Finds files matching the specified masks.
*/
public function files(string|array $masks): static
public function files(string|array $masks = ['*']): static
{
return $this->addMask((array) $masks, 'file');
}
Expand All @@ -90,7 +90,7 @@ public function files(string|array $masks): static
/**
* Finds directories matching the specified masks.
*/
public function directories(string|array $masks): static
public function directories(string|array $masks = ['*']): static
{
return $this->addMask((array) $masks, 'dir');
}
Expand Down
18 changes: 18 additions & 0 deletions tests/Utils/Finder.basic.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,24 @@ test('expty search', function () {
});


test('default mask', function () {
$finder = Finder::find()->in('fixtures.finder');
Assert::same(['fixtures.finder/file.txt', 'fixtures.finder/images', 'fixtures.finder/subdir'], export($finder));

$finder = Finder::findFiles()->in('fixtures.finder');
Assert::same(['fixtures.finder/file.txt'], export($finder));

$finder = Finder::findDirectories()->in('fixtures.finder');
Assert::same(['fixtures.finder/images', 'fixtures.finder/subdir'], export($finder));

$finder = (new Finder)->files()->in('fixtures.finder');
Assert::same(['fixtures.finder/file.txt'], export($finder));

$finder = (new Finder)->directories()->in('fixtures.finder');
Assert::same(['fixtures.finder/images', 'fixtures.finder/subdir'], export($finder));
});


test('current dir', function () {
$finder = Finder::findFiles('fixtures.finder/*.txt');
Assert::same(['fixtures.finder/file.txt'], export($finder));
Expand Down

0 comments on commit dfda0ca

Please sign in to comment.