From 761aed98ff5df2afedac647e807f2862feca96e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20Vo=C5=99=C3=AD=C5=A1ek?= Date: Tue, 26 Jan 2021 13:24:51 +0100 Subject: [PATCH] Fix CS config by default too --- .php_cs.dist | 13 +++++++++- src/Finder.php | 4 ++++ tests/ConfigTest.php | 24 +++++++++++++++---- tests/Console/ConfigurationResolverTest.php | 4 ++-- tests/Fixtures/FinderDirectory/.php_cs | 0 tests/Fixtures/FinderDirectory/.php_cs.dist | 0 .../FinderDirectory/somefile2.php.txt | 0 tests/Fixtures/ci-integration/.php_cs.dist | 4 ++-- tests/Smoke/CiIntegrationTest.php | 6 ++--- 9 files changed, 42 insertions(+), 13 deletions(-) create mode 100644 tests/Fixtures/FinderDirectory/.php_cs create mode 100644 tests/Fixtures/FinderDirectory/.php_cs.dist create mode 100644 tests/Fixtures/FinderDirectory/somefile2.php.txt diff --git a/.php_cs.dist b/.php_cs.dist index 1c9ea9b79da..e33c2514d56 100644 --- a/.php_cs.dist +++ b/.php_cs.dist @@ -1,5 +1,15 @@ + * Dariusz RumiƄski + * + * This source file is subject to the MIT license that is bundled + * with this source code in the file LICENSE. + */ + $header = <<<'EOF' This file is part of PHP CS Fixer. @@ -39,7 +49,8 @@ if (false !== getenv('FABBOT_IO')) { PhpCsFixer\FixerFactory::create() ->registerBuiltInFixers() ->registerCustomFixers($config->getCustomFixers()) - ->useRuleSet(new PhpCsFixer\RuleSet($config->getRules())); + ->useRuleSet(new PhpCsFixer\RuleSet($config->getRules())) + ; } catch (PhpCsFixer\ConfigurationException\InvalidConfigurationException $e) { $config->setRules([]); } catch (UnexpectedValueException $e) { diff --git a/src/Finder.php b/src/Finder.php index 807a633f4f5..68a6a3216a4 100644 --- a/src/Finder.php +++ b/src/Finder.php @@ -27,6 +27,10 @@ public function __construct() $this ->files() ->name('*.php') + ->ignoreDotFiles(false) + ->notPath('~(^|/)\.(?!php_cs(\.dist)?(/|$)).+(/|$)~') + ->name('.php_cs') + ->name('.php_cs.dist') ->exclude('vendor') ; } diff --git a/tests/ConfigTest.php b/tests/ConfigTest.php index 780e9a808d8..6ba0a9c6abd 100644 --- a/tests/ConfigTest.php +++ b/tests/ConfigTest.php @@ -127,8 +127,13 @@ public function testThatFinderWorksWithDirSetOnConfig() false ); - static::assertCount(1, $items); - static::assertSame('somefile.php', $items[0]->getFilename()); + static::assertCount(3, $items); + usort($items, function (\SplFileInfo $a, \SplFileInfo $b) { + return strcmp($a->getFilename(), $b->getFilename()); + }); + static::assertSame('.php_cs', $items[0]->getFilename()); + static::assertSame('.php_cs.dist', $items[1]->getFilename()); + static::assertSame('somefile.php', $items[2]->getFilename()); } public function testThatCustomFinderWorks() @@ -143,8 +148,13 @@ public function testThatCustomFinderWorks() false ); - static::assertCount(1, $items); - static::assertSame('somefile.php', $items[0]->getFilename()); + static::assertCount(3, $items); + usort($items, function (\SplFileInfo $a, \SplFileInfo $b) { + return strcmp($a->getFilename(), $b->getFilename()); + }); + static::assertSame('.php_cs', $items[0]->getFilename()); + static::assertSame('.php_cs.dist', $items[1]->getFilename()); + static::assertSame('somefile.php', $items[2]->getFilename()); } public function testThatCustomSymfonyFinderWorks() @@ -159,8 +169,12 @@ public function testThatCustomSymfonyFinderWorks() false ); - static::assertCount(1, $items); + static::assertCount(2, $items); + usort($items, function (\SplFileInfo $a, \SplFileInfo $b) { + return strcmp($a->getFilename(), $b->getFilename()); + }); static::assertSame('somefile.php', $items[0]->getFilename()); + static::assertSame('somefile2.php.txt', $items[1]->getFilename()); } public function testThatCacheFileHasDefaultValue() diff --git a/tests/Console/ConfigurationResolverTest.php b/tests/Console/ConfigurationResolverTest.php index 2133c029ee9..26f9e7f01b0 100644 --- a/tests/Console/ConfigurationResolverTest.php +++ b/tests/Console/ConfigurationResolverTest.php @@ -565,14 +565,14 @@ static function ($item) use ($dir) { ], 'configured only by finder' => [ // don't override if the argument is empty - $cb(['a1.php', 'a2.php', 'b/b1.php', 'b/b2.php', 'b_b/b_b1.php', 'c/c1.php', 'c/d/cd1.php', 'd/d1.php', 'd/d2.php', 'd/e/de1.php', 'd/f/df1.php']), + $cb(['a1.php', 'a2.php', 'b/b1.php', 'b/b2.php', 'b_b/b_b1.php', 'c/c1.php', 'c/d/cd1.php', 'd/.php_cs', 'd/d1.php', 'd/d2.php', 'd/e/de1.php', 'd/f/df1.php']), Finder::create() ->in($dir), [], 'override', ], 'configured only by argument' => [ - $cb(['a1.php', 'a2.php', 'b/b1.php', 'b/b2.php', 'b_b/b_b1.php', 'c/c1.php', 'c/d/cd1.php', 'd/d1.php', 'd/d2.php', 'd/e/de1.php', 'd/f/df1.php']), + $cb(['a1.php', 'a2.php', 'b/b1.php', 'b/b2.php', 'b_b/b_b1.php', 'c/c1.php', 'c/d/cd1.php', 'd/.php_cs', 'd/d1.php', 'd/d2.php', 'd/e/de1.php', 'd/f/df1.php']), Finder::create(), [$dir], 'override', diff --git a/tests/Fixtures/FinderDirectory/.php_cs b/tests/Fixtures/FinderDirectory/.php_cs new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/Fixtures/FinderDirectory/.php_cs.dist b/tests/Fixtures/FinderDirectory/.php_cs.dist new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/Fixtures/FinderDirectory/somefile2.php.txt b/tests/Fixtures/FinderDirectory/somefile2.php.txt new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/Fixtures/ci-integration/.php_cs.dist b/tests/Fixtures/ci-integration/.php_cs.dist index 088317ac351..4faae3319cb 100644 --- a/tests/Fixtures/ci-integration/.php_cs.dist +++ b/tests/Fixtures/ci-integration/.php_cs.dist @@ -1,9 +1,9 @@ setRules(array( + ->setRules([ '@Symfony' => true, - )) + ]) ->setFinder( PhpCsFixer\Finder::create() ->in(__DIR__) diff --git a/tests/Smoke/CiIntegrationTest.php b/tests/Smoke/CiIntegrationTest.php index 79a94eee57c..b25327fd0f0 100644 --- a/tests/Smoke/CiIntegrationTest.php +++ b/tests/Smoke/CiIntegrationTest.php @@ -219,7 +219,7 @@ public function provideIntegrationCases() '', '', ], - '...', + '....', ], 'changes-including-custom-config-file-creation' => [ 'changes-including-custom-config-file-creation', @@ -238,7 +238,7 @@ public function provideIntegrationCases() '', '', ], - '...', + '.....', ], 'changes-including-composer-lock' => [ 'changes-including-composer-lock', @@ -257,7 +257,7 @@ public function provideIntegrationCases() '', '', ], - '...', + '....', ], ]; }