Skip to content
Permalink
Browse files

Merge pull request #143 from kubawerlos/fix-test-with-configuration

Cleanup configurable fixers
  • Loading branch information...
kubawerlos committed Sep 23, 2019
2 parents 97adfab + b963223 commit 310796ef909e012f35864429f4162bc1add7082d
@@ -5,8 +5,10 @@
namespace PhpCsFixerCustomFixersDev\Readme;
use PhpCsFixer\Console\Command\HelpCommand;
use PhpCsFixer\Fixer\ConfigurableFixerInterface;
use PhpCsFixer\Fixer\ConfigurationDefinitionFixerInterface;
use PhpCsFixer\Fixer\DeprecatedFixerInterface;
use PhpCsFixer\FixerDefinition\CodeSample;
use PhpCsFixer\StdinFileInfo;
use PhpCsFixer\Tokenizer\Tokens;
use PhpCsFixerCustomFixers\Fixer\DeprecatingFixerInterface;
@@ -205,7 +207,14 @@ private function fixers(): string
}
}
$originalCode = $fixer->getDefinition()->getCodeSamples()[0]->getCode();
/** @var CodeSample $codeSample */
$codeSample = $fixer->getDefinition()->getCodeSamples()[0];
$originalCode = $codeSample->getCode();
if ($fixer instanceof ConfigurableFixerInterface) {
$fixer->configure($codeSample->getConfiguration());
}
$tokens = Tokens::fromCode($originalCode);
$fixer->fix(new StdinFileInfo(), $tokens);
$fixedCode = $tokens->generateCode();
@@ -42,9 +42,7 @@ public function getConfigurationDefinition(): FixerConfigurationResolver
public function configure(?array $configuration = null): void
{
if (isset($configuration['style'])) {
$this->style = $configuration['style'];
}
$this->style = $configuration['style'] ?? $this->style;
}
public function isCandidate(Tokens $tokens): bool
@@ -94,7 +94,7 @@ public function getConfigurationDefinition(): FixerConfigurationResolver
public function configure(?array $configuration = null): void
{
$this->allowLinebreak = $configuration['allow_linebreak'];
$this->allowLinebreak = $configuration['allow_linebreak'] ?? $this->allowLinebreak;
}
public function isCandidate(Tokens $tokens): bool
@@ -39,9 +39,7 @@ public function testIsRisky(): void
*/
public function testFix(string $expected, ?string $input = null, ?array $configuration = null): void
{
if ($configuration !== null) {
$this->fixer->configure($configuration);
}
$this->fixer->configure($configuration);
$this->doTest($expected, $input);
}
@@ -44,9 +44,7 @@ public function testDeprecatingPullRequest(): void
*/
public function testFix(string $expected, ?string $input = null, ?array $configuration = null): void
{
if ($configuration !== null) {
$this->fixer->configure($configuration);
}
$this->fixer->configure($configuration);
$this->doTest($expected, $input);
}
@@ -119,9 +119,7 @@ public function testIsRisky(): void
*/
public function testFix(string $expected, ?string $input = null, ?array $configuration = null): void
{
if ($configuration !== null) {
$this->fixer->configure($configuration);
}
$this->fixer->configure($configuration);
$this->doTest($expected, $input);
}

0 comments on commit 310796e

Please sign in to comment.
You can’t perform that action at this time.