diff --git a/.gitattributes b/.gitattributes index ab73207..3aa6270 100644 --- a/.gitattributes +++ b/.gitattributes @@ -2,5 +2,9 @@ .gitignore export-ignore .github export-ignore .travis.yml export-ignore +ecs.php export-ignore +phpstan.neon export-ignore tests/ export-ignore + *.sh eol=lf +*.php* diff=php linguist-language=PHP diff --git a/.github/funding.yml b/.github/funding.yml new file mode 100644 index 0000000..25adc95 --- /dev/null +++ b/.github/funding.yml @@ -0,0 +1,2 @@ +github: dg +custom: "https://nette.org/donate" diff --git a/.github/workflows/coding-style.yml b/.github/workflows/coding-style.yml new file mode 100644 index 0000000..9530e95 --- /dev/null +++ b/.github/workflows/coding-style.yml @@ -0,0 +1,31 @@ +name: Coding Style + +on: [push, pull_request] + +jobs: + nette_cc: + name: Nette Code Checker + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: shivammathur/setup-php@v2 + with: + php-version: 7.1 + coverage: none + + - run: composer create-project nette/code-checker temp/code-checker ^3 --no-progress + - run: php temp/code-checker/code-checker --strict-types + + + nette_cs: + name: Nette Coding Standard + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: shivammathur/setup-php@v2 + with: + php-version: 7.4 + coverage: none + + - run: composer create-project nette/coding-standard temp/coding-standard ^3 --no-progress + - run: php temp/coding-standard/ecs check diff --git a/.github/workflows/static-analysis.yml b/.github/workflows/static-analysis.yml new file mode 100644 index 0000000..b0692d7 --- /dev/null +++ b/.github/workflows/static-analysis.yml @@ -0,0 +1,21 @@ +name: Static Analysis (only informative) + +on: + push: + branches: + - master + +jobs: + phpstan: + name: PHPStan + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: shivammathur/setup-php@v2 + with: + php-version: 7.4 + coverage: none + + - run: composer install --no-progress --prefer-dist + - run: composer phpstan -- --no-progress + continue-on-error: true # is only informative diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml new file mode 100644 index 0000000..f0eeb05 --- /dev/null +++ b/.github/workflows/tests.yml @@ -0,0 +1,60 @@ +name: Tests + +on: [push, pull_request] + +jobs: + tests: + runs-on: ubuntu-latest + strategy: + matrix: + php: ['7.1', '7.2', '7.3', '7.4', '8.0'] + + fail-fast: false + + name: PHP ${{ matrix.php }} tests + steps: + - uses: actions/checkout@v2 + - uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php }} + coverage: none + + - run: composer install --no-progress --prefer-dist + - run: vendor/bin/tester tests -s -C + - if: failure() + uses: actions/upload-artifact@v2 + with: + name: output + path: tests/**/output + + + lowest_dependencies: + name: Lowest Dependencies + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: shivammathur/setup-php@v1 + with: + php-version: 7.1 + coverage: none + + - run: composer update --no-progress --prefer-dist --prefer-lowest --prefer-stable + - run: vendor/bin/tester tests -s -C + + + code_coverage: + name: Code Coverage + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: shivammathur/setup-php@v2 + with: + php-version: 7.4 + coverage: none + + - run: composer install --no-progress --prefer-dist + - run: vendor/bin/tester -p phpdbg tests -s -C --coverage ./coverage.xml --coverage-src ./src + - run: wget https://github.com/php-coveralls/php-coveralls/releases/download/v2.4.3/php-coveralls.phar + - env: + COVERALLS_REPO_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: php php-coveralls.phar --verbose --config tests/.coveralls.yml diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index b1ecaee..0000000 --- a/.travis.yml +++ /dev/null @@ -1,68 +0,0 @@ -language: php -php: - - 7.1 - - 7.2 - - 7.3 - - 7.4 - -before_install: - # turn off XDebug - - phpenv config-rm xdebug.ini || return 0 - -install: - - travis_retry composer install --no-progress --prefer-dist - -script: - - vendor/bin/tester tests -s - -after_failure: - # Print *.actual content - - for i in $(find tests -name \*.actual); do echo "--- $i"; cat $i; echo; echo; done - -jobs: - include: - - name: Lowest Dependencies - install: - - travis_retry composer update --no-progress --prefer-dist --prefer-lowest --prefer-stable - - - - name: Nette Code Checker - install: - - travis_retry composer create-project nette/code-checker temp/code-checker ^3 --no-progress - script: - - php temp/code-checker/code-checker --strict-types - - - - name: Nette Coding Standard - install: - - travis_retry composer create-project nette/coding-standard temp/coding-standard ^2 --no-progress - script: - - php temp/coding-standard/ecs check src tests --config temp/coding-standard/coding-standard-php71.yml - - - - stage: Static Analysis (informative) - script: - - composer run-script phpstan - - - - stage: Code Coverage - script: - - vendor/bin/tester -p phpdbg tests -s --coverage ./coverage.xml --coverage-src ./src - after_script: - - wget https://github.com/satooshi/php-coveralls/releases/download/v1.0.1/coveralls.phar - - php coveralls.phar --verbose --config tests/.coveralls.yml - - - allow_failures: - - stage: Static Analysis (informative) - - stage: Code Coverage - - -sudo: false - -cache: - directories: - - $HOME/.composer/cache - -notifications: - email: false diff --git a/composer.json b/composer.json index 2ba4cd5..d8f7e9b 100644 --- a/composer.json +++ b/composer.json @@ -3,7 +3,7 @@ "description": "🔍 Nette Finder: find files and directories with an intuitive API.", "keywords": ["nette", "filesystem", "iterator", "glob"], "homepage": "https://nette.org", - "license": ["BSD-3-Clause", "GPL-2.0", "GPL-3.0"], + "license": ["BSD-3-Clause", "GPL-2.0-only", "GPL-3.0-only"], "authors": [ { "name": "David Grudl", @@ -16,27 +16,24 @@ ], "require": { "php": ">=7.1", - "nette/utils": "^2.4 || ^3.0" + "nette/utils": "^3.0" }, "require-dev": { - "nette/tester": "^2.0", - "tracy/tracy": "^2.3", + "nette/tester": "^2.2", + "tracy/tracy": "^2.6", "phpstan/phpstan": "^0.12" }, - "conflict": { - "nette/nette": "<2.2" - }, "autoload": { "classmap": ["src/"] }, "minimum-stability": "dev", "scripts": { - "phpstan": "phpstan analyse --level 5 src", + "phpstan": "phpstan analyse", "tester": "tester tests -s" }, "extra": { "branch-alias": { - "dev-master": "2.5-dev" + "dev-master": "3.0-dev" } } } diff --git a/phpstan.neon b/phpstan.neon new file mode 100644 index 0000000..a084693 --- /dev/null +++ b/phpstan.neon @@ -0,0 +1,5 @@ +parameters: + level: 5 + + paths: + - src diff --git a/readme.md b/readme.md index 1fb7640..e591e91 100644 --- a/readme.md +++ b/readme.md @@ -2,7 +2,7 @@ Nette Finder: Files Searching ============================= [![Downloads this Month](https://img.shields.io/packagist/dm/nette/finder.svg)](https://packagist.org/packages/nette/finder) -[![Build Status](https://travis-ci.org/nette/finder.svg?branch=master)](https://travis-ci.org/nette/finder) +[![Tests](https://github.com/nette/finder/workflows/Tests/badge.svg?branch=master)](https://github.com/nette/finder/actions) [![Coverage Status](https://coveralls.io/repos/github/nette/finder/badge.svg?branch=master)](https://coveralls.io/github/nette/finder?branch=master) [![Latest Stable Version](https://poser.pugx.org/nette/finder/v/stable)](https://github.com/nette/finder/releases) [![License](https://img.shields.io/badge/license-New%20BSD-blue.svg)](https://github.com/nette/finder/blob/master/license.md) @@ -13,169 +13,142 @@ Introduction Nette Finder makes browsing the directory structure really easy. -Documentation can be found on the [website](https://doc.nette.org/finder). +Documentation can be found on the [website](https://doc.nette.org/finder). If you like it, **[please make a donation now](https://github.com/sponsors/dg)**. Thank you! -If you like Nette, **[please make a donation now](https://nette.org/donate)**. Thank you! +Installation: - -Installation ------------- - -The recommended way to install is via Composer: - -``` +```shell composer require nette/finder ``` -It requires PHP version 7.1 and supports PHP up to 7.4. - - -Usage ------ - -How to find all `*.txt` files in `$dir` directory without recursing subdirectories? +All examples assume the following class alias is defined: ```php -foreach (Finder::findFiles('*.txt')->in($dir) as $key => $file) { - echo $key; // $key is a string containing absolute filename with path - echo $file; // $file is an instance of SplFileInfo -} +use Nette\Utils\Finder; ``` -As a result, the finder returns instances of `SplFileInfo`. -If the directory does not exist, an `UnexpectedValueException` is thrown. +Searching for Files +------------------- -And what about searching for `*.txt` files in `$dir` including subdirectories? Instead of `in()`, use `from()`: +How to find all `*.txt` files in `$dir` directory and all its subdirectories? ```php -foreach (Finder::findFiles('*.txt')->from($dir) as $file) { - echo $file; +foreach (Finder::findFiles('*.txt')->from($dir) as $key => $file) { + // $key is a string containing absolute filename with path + // $file is an instance of SplFileInfo } ``` -Search by more masks, even inside more directories within one iteration: +The files in the `$file` variable are instances of the `SplFileInfo` class. -```php -foreach (Finder::findFiles('*.txt', '*.php') - ->in($dir1, $dir2) as $file) { - ... -} -``` +If the directory does not exist, an `Nette\UnexpectedValueException` is thrown. -Parameters can also be arrays: +And what about searching for files in a directory without subdirectories? Instead of `from()` use `in()`: ```php -foreach (Finder::findFiles($masks)->in($dirs) as $file) { - ... -} +Finder::findFiles('*.txt')->in($dir) ``` -Searching for `*.txt` files containing a number in the name: +Search by multiple masks and even multiple directories at once: ```php -foreach (Finder::findFiles('*[0-9]*.txt')->from($dir) as $file) { - ... -} +Finder::findFiles('*.txt', '*.php') + ->in($dir1, $dir2) // or from($dir1, $dir2) ``` -Searching for `*.txt` files, except those containing '`X`' in the name: +Parameters can also be arrays: ```php -foreach (Finder::findFiles('*.txt') - ->exclude('*X*')->from($dir) as $file) { - ... -} +Finder::findFiles(['*.txt', '*.php']) + ->in([$dir1, $dir2]) // or from([$dir1, $dir2]) ``` -`exclude()` is specified just after `findFiles()`, thus it applies to filename. +Depth of search can be limited using the `limitDepth()` method. + +Searching for Directories +------------------------- -Directories to omit can be specified using the `exclude` **after** `from` clause: +In addition to files, it is possible to search for directories using `Finder::findDirectories('subdir*')`. -```php -foreach (Finder::findFiles('*.php') - ->from($dir)->exclude('temp', '.git') as $file) { - ... -} -``` +Or to search for files and directories together using `Finder::find('*.txt')`, the mask in this case only applies to files. When searching recursively with `from()`, the subdirectory is returned first, followed by the files in it, which can be reversed with `childFirst()`. -Here `exclude()` is after `from()`, thus it applies to the directory name. +Mask +---- -And now something a bit more complicated: searching for `*.txt` files located in subdirectories starting with '`te`', but not '`temp`': +The mask does not have to describe only the file name, but also the path. Example: searching for `*.jpg` files located in a subdirectory starting with `imag`: ```php -foreach (Finder::findFiles('te*/*.txt') - ->exclude('temp*/*')->from($dir) as $file) { - ... -} +Finder::findFiles('imag*/*.jpg') ``` -Depth of search can be limited using the `limitDepth()` method. - +Thus, the known wildcards `*` and `?` represent any characters except the directory separator `/`. The double `**` represents any characters, including the directory separator: +```php +Finder::findFiles('imag**/*.jpg') +// finds also image/subdir/file.jpg +``` -Searching for directories -------------------------- +In addition you can use in the mask ranges `[...]` or negative ranges `[!...]` known from regular expressions. Searching for `*.txt` files containing a digit in the name: -In addition to files, it is possible to search for directories using `Finder::findDirectories('subdir*')`, or to search for files and directories: `Finder::find('file.txt')`. +```php +Finder::findFiles('*[0-9]*.txt') +``` -Filtering +Excluding --------- -You can also filter results. For example by size. This way we will traverse the files of size between 100B and 200B: - +Use `exclude()` to pass masks that the file must not match. Searching for `*.txt` files, except those containing '`X`' in the name: ```php -foreach (Finder::findFiles('*.php')->size('>=', 100)->size('<=', 200) - ->from($dir) as $file) { - ... -} +Finder::findFiles('*.txt') + ->exclude('*X*') ``` -Or files changed in the last two weeks: +If `exclude()` is specified **after** `from()`, it applies to crawled subdirectories: ```php -foreach (Finder::findFiles('*.php')->date('>', '- 2 weeks') - ->from($dir) as $file) { - ... -} +Finder::findFiles('*.php') + ->from($dir) + ->exclude('temp', '.git') ``` -Here we traverse PHP files with number of lines greater than 1000. As a filter we use a custom callback: -```php -$finder = Finder::findFiles('*.php')->filter(function($file) { - return count(file($file->getPathname())) > 1000; -})->from($dir); -``` +Filtering +--------- -Finder, find images larger than 50px × 50px: +You can also filter the results, for example by file size. Here's how to find files of size between 100 and 200 bytes: ```php -foreach (Finder::findFiles('*') - ->dimensions('>50', '>50')->from($dir) as $file) { - ... -} +Finder::findFiles('*.php') + ->size('>=', 100) + ->size('<=', 200) + ->from($dir) ``` +Filtering by date of last change. Example: searching for files changed in the last two weeks: -Connection to Amazon S3 ------------------------ +```php +Finder::findFiles('*.php') + ->date('>', '- 2 weeks') + ->from($dir) +``` + +Both functions understand the operators `>`, `>=`, `<`, `<=`, `=`, `!=`. -It's possible to use custom streams, for example Zend_Service_Amazon_S3: +Here we traverse PHP files with number of lines greater than 1000. As a filter we use a custom callback: ```php -$s3 = new Zend_Service_Amazon_S3($key, $secret); -$s3->registerStreamWrapper('s3'); +$hasMoreThan100Lines = function (SplFileInfo $file): bool { + return count(file($file->getPathname())) > 1000; +}; -foreach (Finder::findFiles('photos*') - ->size('<=', 1e6)->in('s3://bucket-name') as $file) { - echo $file; -} +Finder::findFiles('*.php') + ->filter($hasMoreThan100Lines) ``` Handy, right? You will certainly find a use for Finder in your applications. diff --git a/src/Utils/Finder.php b/src/Utils/Finder.php index c3ffabd..0a54959 100644 --- a/src/Utils/Finder.php +++ b/src/Utils/Finder.php @@ -161,8 +161,10 @@ private static function buildPattern(array $masks): ?string $mask = ltrim($mask, '/'); $prefix = '(?<=^/)'; } - $pattern[] = $prefix . strtr(preg_quote($mask, '#'), - ['\*\*' => '.*', '\*' => '[^/]*', '\?' => '[^/]', '\[\!' => '[^', '\[' => '[', '\]' => ']', '\-' => '-']); + $pattern[] = $prefix . strtr( + preg_quote($mask, '#'), + ['\*\*' => '.*', '\*' => '[^/]*', '\?' => '[^/]', '\[\!' => '[^', '\[' => '[', '\]' => ']', '\-' => '-'] + ); } return $pattern ? '#/(' . implode('|', $pattern) . ')$#Di' : null; } @@ -190,14 +192,22 @@ public function getIterator(): \Iterator } elseif (count($this->paths) === 1) { return $this->buildIterator((string) $this->paths[0]); + } - } else { - $iterator = new \AppendIterator(); - foreach ($this->paths as $path) { - $iterator->append($this->buildIterator((string) $path)); - } - return $iterator; + $iterator = new \AppendIterator; + foreach ($this->paths as $path) { + $iterator->append($this->buildIterator((string) $path)); } + return $iterator; + } + + + /** + * @return string[] + */ + public function getPaths(): array + { + return array_keys(iterator_to_array($this->getIterator())); } @@ -369,7 +379,7 @@ public function __call(string $name, array $args) { return isset(self::$extMethods[$name]) ? (self::$extMethods[$name])($this, ...$args) - : Nette\Utils\ObjectHelpers::strictCall(get_class($this), $name, array_keys(self::$extMethods)); + : Nette\Utils\ObjectHelpers::strictCall(static::class, $name, array_keys(self::$extMethods)); } diff --git a/tests/.coveralls.yml b/tests/.coveralls.yml index 82764a3..8450382 100644 --- a/tests/.coveralls.yml +++ b/tests/.coveralls.yml @@ -1,4 +1,4 @@ # for php-coveralls -service_name: travis-ci +service_name: github-actions coverage_clover: coverage.xml json_path: coverage.json diff --git a/tests/Utils/Finder.basic.phpt b/tests/Utils/Finder.basic.phpt index 89524a6..5a6800b 100644 --- a/tests/Utils/Finder.basic.phpt +++ b/tests/Utils/Finder.basic.phpt @@ -24,19 +24,19 @@ function export($iterator) } -test(function () { // count the results +test('count the results', function () { $finder = Finder::findFiles('file.txt')->in('files'); Assert::count(1, $finder); }); -test(function () { // non-recursive file search +test('non-recursive file search', function () { $finder = Finder::findFiles('file.txt')->in('files'); Assert::same(['files/file.txt'], export($finder)); }); -test(function () { // recursive file search +test('recursive file search', function () { $finder = Finder::findFiles('file.txt')->from('files'); Assert::same([ 'files/file.txt', @@ -46,7 +46,21 @@ test(function () { // recursive file search }); -test(function () { // recursive file search with depth limit +test('recursive file search and get paths', function () { + $finder = Finder::findFiles('file.txt')->from('files'); + $pathList = $finder->getPaths(); + $expectedList = [ + 'files/file.txt', + 'files/subdir/file.txt', + 'files/subdir/subdir2/file.txt', + ]; + sort($expectedList); + sort($pathList); + Assert::same($expectedList, $pathList); +}); + + +test('recursive file search with depth limit', function () { $finder = Finder::findFiles('file.txt')->from('files')->limitDepth(1); Assert::same([ 'files/file.txt', @@ -55,7 +69,7 @@ test(function () { // recursive file search with depth limit }); -test(function () { // non-recursive file & directory search +test('non-recursive file & directory search', function () { $finder = Finder::find('file.txt')->in('files'); Assert::same([ 'files/file.txt', @@ -63,7 +77,7 @@ test(function () { // non-recursive file & directory search }); -test(function () { // recursive file & directory search +test('recursive file & directory search', function () { $finder = Finder::find('file.txt')->from('files'); Assert::same([ 'files/file.txt', @@ -73,7 +87,7 @@ test(function () { // recursive file & directory search }); -test(function () { // recursive file & directory search in child-first order +test('recursive file & directory search in child-first order', function () { $finder = Finder::find('file.txt')->from('files')->childFirst(); Assert::same([ 'files/file.txt', @@ -83,7 +97,7 @@ test(function () { // recursive file & directory search in child-first order }); -test(function () { // recursive file & directory search excluding folders +test('recursive file & directory search excluding folders', function () { $finder = Finder::find('file.txt')->from('files')->exclude('images')->exclude('subdir2', '*.txt'); Assert::same([ 'files/file.txt', @@ -92,7 +106,7 @@ test(function () { // recursive file & directory search excluding folders }); -test(function () { // non-recursive directory search +test('non-recursive directory search', function () { $finder = Finder::findDirectories('subdir*')->in('files'); Assert::same([ 'files/subdir', @@ -100,7 +114,7 @@ test(function () { // non-recursive directory search }); -test(function () { // recursive directory search +test('recursive directory search', function () { $finder = Finder::findDirectories('subdir*')->from('files'); Assert::same([ 'files/subdir', @@ -109,7 +123,7 @@ test(function () { // recursive directory search }); -test(function () { // getSubPathName +test('getSubPathName', function () { $res = []; foreach ($iterator = Finder::findFiles('file.txt')->from('files')->getIterator() as $foo) { $res[$iterator->getSubPathName()] = true; @@ -121,7 +135,7 @@ test(function () { // getSubPathName }); -test(function () { // empty args +test('empty args', function () { $finder = Finder::find()->in('files'); Assert::same([ 'files/file.txt', diff --git a/tests/Utils/Finder.filters.phpt b/tests/Utils/Finder.filters.phpt index f046f25..fbe00dc 100644 --- a/tests/Utils/Finder.filters.phpt +++ b/tests/Utils/Finder.filters.phpt @@ -24,7 +24,7 @@ function export($iterator) } -test(function () { // size filter +test('size filter', function () { $finder = Finder::findFiles('*')->size('>8kB')->from('files'); Assert::same([ 'files/images/logo.gif', @@ -32,7 +32,7 @@ test(function () { // size filter }); -test(function () { +test('', function () { $finder = Finder::findFiles('*')->size('> 10')->size('< 100b')->from('files'); Assert::same([ 'files/file.txt', @@ -42,7 +42,7 @@ test(function () { }); -test(function () { +test('', function () { $finder = Finder::find('*')->size('>', 10)->size('< 100b')->from('files'); Assert::same([ 'files/file.txt', @@ -55,13 +55,13 @@ test(function () { }); -test(function () { // date filter +test('date filter', function () { $finder = Finder::findFiles('*')->date('> 2050-01-02')->from('files'); Assert::same([], export($finder)); }); -test(function () { // custom filters +test('custom filters', function () { Finder::extensionMethod('length', function ($finder, $length) { return $finder->filter(function ($file) use ($length) { return strlen($file->getFilename()) == $length; @@ -70,7 +70,7 @@ test(function () { // custom filters }); -test(function () { +test('', function () { $finder = Finder::findFiles('*')->length(6)->from('files'); Assert::same([ 'files/subdir/readme', diff --git a/tests/Utils/Finder.mask.phpt b/tests/Utils/Finder.mask.phpt index e6ba8bc..0e37efa 100644 --- a/tests/Utils/Finder.mask.phpt +++ b/tests/Utils/Finder.mask.phpt @@ -24,7 +24,7 @@ function export($iterator) } -test(function () { // multiple mask +test('multiple mask', function () { $finder = Finder::findFiles('*.txt', '*.gif')->from('files'); Assert::same([ 'files/file.txt', @@ -35,7 +35,7 @@ test(function () { // multiple mask }); -test(function () { +test('', function () { $finder = Finder::findFiles(['*.txt', '*.gif'])->from('files'); Assert::same([ 'files/file.txt', @@ -46,7 +46,7 @@ test(function () { }); -test(function () { // * mask +test('* mask', function () { $finder = Finder::findFiles('*.txt', '*')->in('files/subdir'); Assert::same([ 'files/subdir/file.txt', @@ -55,7 +55,7 @@ test(function () { // * mask }); -test(function () { // *.* mask +test('*.* mask', function () { $finder = Finder::findFiles('*.*')->in('files/subdir'); Assert::same([ 'files/subdir/file.txt', @@ -70,7 +70,7 @@ Assert::same([ ], export($finder)); -test(function () { // subdir mask +test('subdir mask', function () { $finder = Finder::findFiles('*/*2/*')->from('files'); Assert::same([ 'files/subdir/subdir2/file.txt', @@ -78,7 +78,7 @@ test(function () { // subdir mask }); -test(function () { // excluding mask +test('excluding mask', function () { $finder = Finder::findFiles('*')->exclude('*i*')->in('files/subdir'); Assert::same([ 'files/subdir/readme', @@ -86,7 +86,7 @@ test(function () { // excluding mask }); -test(function () { // subdir excluding mask +test('subdir excluding mask', function () { $finder = Finder::findFiles('*')->exclude('*i*/*')->from('files'); Assert::same([ 'files/file.txt', @@ -94,7 +94,7 @@ test(function () { // subdir excluding mask }); -test(function () { // complex mask +test('complex mask', function () { $finder = Finder::findFiles('*[efd][a-z][!a-r]*')->from('files'); Assert::same([ 'files/images/logo.gif', @@ -102,7 +102,7 @@ test(function () { // complex mask }); -test(function () { +test('', function () { $finder = Finder::findFiles('*2*/fi??.*')->from('files'); Assert::same([ 'files/subdir/subdir2/file.txt', @@ -110,7 +110,7 @@ test(function () { }); -test(function () { // anchored +test('anchored', function () { $finder = Finder::findFiles('/f*')->from('files'); Assert::same([ 'files/file.txt', @@ -118,7 +118,7 @@ test(function () { // anchored }); -test(function () { +test('', function () { $finder = Finder::findFiles('/*/f*')->from('files'); Assert::same([ 'files/subdir/file.txt', @@ -126,7 +126,7 @@ test(function () { }); -test(function () { // multidirs mask +test('multidirs mask', function () { $finder = Finder::findFiles('/**/f*')->from('files'); Assert::same([ 'files/subdir/file.txt', diff --git a/tests/Utils/Finder.multiple.phpt b/tests/Utils/Finder.multiple.phpt index ff402a4..0a79b17 100644 --- a/tests/Utils/Finder.multiple.phpt +++ b/tests/Utils/Finder.multiple.phpt @@ -24,14 +24,13 @@ function export($iterator) } -test(function () { // recursive +test('recursive', function () { $finder = Finder::find('*')->from('files/subdir/subdir2', 'files/images'); Assert::same([ 'files/images/logo.gif', 'files/subdir/subdir2/file.txt', ], export($finder)); - $finder = Finder::find('*')->from(['files/subdir/subdir2', 'files/images']); Assert::same([ 'files/images/logo.gif', @@ -44,14 +43,13 @@ test(function () { // recursive }); -test(function () { // non-recursive +test('non-recursive', function () { $finder = Finder::find('*')->in('files/subdir/subdir2', 'files/images'); Assert::same([ 'files/images/logo.gif', 'files/subdir/subdir2/file.txt', ], export($finder)); - $finder = Finder::find('*')->in(['files/subdir/subdir2', 'files/images']); Assert::same([ 'files/images/logo.gif', diff --git a/tests/bootstrap.php b/tests/bootstrap.php index 19fc4b3..adf1d0a 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -15,7 +15,7 @@ date_default_timezone_set('Europe/Prague'); -function test(\Closure $function) +function test(string $title, Closure $function) { $function(); }