Browse Source

minor #6189 Finder - fix usage of ignoreDotFiles (kubawerlos)

This PR was squashed before being merged into the master branch (closes #6189).

Discussion
----------

Finder - fix usage of ignoreDotFiles

Commits
-------

0a59bb47e Finder - fix usage of ignoreDotFiles
SpacePossum 3 years ago
parent
commit
45bf9e3d73
2 changed files with 21 additions and 1 deletions
  1. 1 1
      src/Finder.php
  2. 20 0
      tests/FinderTest.php

+ 1 - 1
src/Finder.php

@@ -28,7 +28,7 @@ class Finder extends BaseFinder
 
         $this
             ->files()
-            ->name('*.php')
+            ->name('/\.php$/')
             ->exclude('vendor')
         ;
     }

+ 20 - 0
tests/FinderTest.php

@@ -15,6 +15,7 @@ declare(strict_types=1);
 namespace PhpCsFixer\Tests;
 
 use PhpCsFixer\Finder;
+use Symfony\Component\Finder\SplFileInfo;
 
 /**
  * @internal
@@ -31,4 +32,23 @@ final class FinderTest extends TestCase
         $finder = Finder::create();
         $finder->getIterator();
     }
+
+    public function testThatFinderFindsDotFilesWhenConfigured(): void
+    {
+        $finder = Finder::create()
+            ->in(__DIR__.'/..')
+            ->depth(0)
+            ->ignoreDotFiles(false)
+        ;
+
+        static::assertContains(
+            realpath(__DIR__.'/../.php-cs-fixer.dist.php'),
+            array_map(
+                function (SplFileInfo $file): string {
+                    return $file->getRealPath();
+                },
+                iterator_to_array($finder->getIterator())
+            )
+        );
+    }
 }