Skip to content

Commit

Permalink
Fix CS config by default too
Browse files Browse the repository at this point in the history
  • Loading branch information
mvorisek committed Jan 26, 2021
1 parent ea98c01 commit 761aed9
Show file tree
Hide file tree
Showing 9 changed files with 42 additions and 13 deletions.
13 changes: 12 additions & 1 deletion .php_cs.dist
@@ -1,5 +1,15 @@
<?php

/*
* This file is part of PHP CS Fixer.
*
* (c) Fabien Potencier <fabien@symfony.com>
* Dariusz Rumiński <dariusz.ruminski@gmail.com>
*
* 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.
Expand Down Expand Up @@ -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) {
Expand Down
4 changes: 4 additions & 0 deletions src/Finder.php
Expand Up @@ -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')
;
}
Expand Down
24 changes: 19 additions & 5 deletions tests/ConfigTest.php
Expand Up @@ -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()
Expand All @@ -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()
Expand All @@ -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()
Expand Down
4 changes: 2 additions & 2 deletions tests/Console/ConfigurationResolverTest.php
Expand Up @@ -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',
Expand Down
Empty file.
Empty file.
Empty file.
4 changes: 2 additions & 2 deletions tests/Fixtures/ci-integration/.php_cs.dist
@@ -1,9 +1,9 @@
<?php

return (new PhpCsFixer\Config())
->setRules(array(
->setRules([
'@Symfony' => true,
))
])
->setFinder(
PhpCsFixer\Finder::create()
->in(__DIR__)
Expand Down
6 changes: 3 additions & 3 deletions tests/Smoke/CiIntegrationTest.php
Expand Up @@ -219,7 +219,7 @@ public function provideIntegrationCases()
'',
'',
],
'...',
'....',
],
'changes-including-custom-config-file-creation' => [
'changes-including-custom-config-file-creation',
Expand All @@ -238,7 +238,7 @@ public function provideIntegrationCases()
'',
'',
],
'...',
'.....',
],
'changes-including-composer-lock' => [
'changes-including-composer-lock',
Expand All @@ -257,7 +257,7 @@ public function provideIntegrationCases()
'',
'',
],
'...',
'....',
],
];
}
Expand Down

0 comments on commit 761aed9

Please sign in to comment.