diff --git a/src/Utils/Finder.php b/src/Utils/Finder.php index 491f6902e..a17065464 100644 --- a/src/Utils/Finder.php +++ b/src/Utils/Finder.php @@ -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'); @@ -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'); @@ -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'); @@ -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'); } @@ -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'); } diff --git a/tests/Utils/Finder.basic.phpt b/tests/Utils/Finder.basic.phpt index 95eaffcea..053f24e6b 100644 --- a/tests/Utils/Finder.basic.phpt +++ b/tests/Utils/Finder.basic.phpt @@ -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));