Skip to content

Commit b3a5201

Browse files
authored
Add AbstractFixerTestCase::getConfigurationOptions (#931)
1 parent bd5f6dc commit b3a5201

13 files changed

+26
-55
lines changed

tests/Fixer/AbstractFixerTestCase.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use PhpCsFixer\Fixer\DeprecatedFixerInterface;
1717
use PhpCsFixer\Fixer\FixerInterface;
1818
use PhpCsFixer\Fixer\WhitespacesAwareFixerInterface;
19+
use PhpCsFixer\FixerConfiguration\FixerOptionInterface;
1920
use PhpCsFixer\Linter\Linter;
2021
use PhpCsFixer\Linter\ProcessLinter;
2122
use PhpCsFixer\Tokenizer\Tokens;
@@ -203,6 +204,16 @@ final protected function doTest(string $expected, ?string $input = null, ?array
203204
self::assertFalse($expectedTokens->isChanged());
204205
}
205206

207+
/**
208+
* @return array<FixerOptionInterface>
209+
*/
210+
final protected function getConfigurationOptions(): array
211+
{
212+
self::assertInstanceOf(ConfigurableFixerInterface::class, $this->fixer);
213+
214+
return $this->fixer->getConfigurationDefinition()->getOptions();
215+
}
216+
206217
final protected function lintSource(string $source): ?string
207218
{
208219
static $linter;

tests/Fixer/CommentedOutFunctionFixerTest.php

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,20 +11,16 @@
1111

1212
namespace Tests\Fixer;
1313

14-
use PhpCsFixer\Fixer\ConfigurableFixerInterface;
15-
1614
/**
1715
* @internal
1816
*
19-
* @property ConfigurableFixerInterface $fixer
20-
*
2117
* @covers \PhpCsFixerCustomFixers\Fixer\CommentedOutFunctionFixer
2218
*/
2319
final class CommentedOutFunctionFixerTest extends AbstractFixerTestCase
2420
{
2521
public function testConfiguration(): void
2622
{
27-
$options = $this->fixer->getConfigurationDefinition()->getOptions();
23+
$options = self::getConfigurationOptions();
2824
self::assertArrayHasKey(0, $options);
2925
self::assertSame('functions', $options[0]->getName());
3026
}
@@ -41,8 +37,7 @@ public function testIsRisky(): void
4137
*/
4238
public function testFix(string $expected, ?string $input = null, ?array $configuration = null): void
4339
{
44-
$this->fixer->configure($configuration ?? []);
45-
$this->doTest($expected, $input);
40+
$this->doTest($expected, $input, $configuration);
4641
}
4742

4843
/**

tests/Fixer/DataProviderNameFixerTest.php

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,23 +11,20 @@
1111

1212
namespace Tests\Fixer;
1313

14-
use PhpCsFixer\Fixer\ConfigurableFixerInterface;
1514
use PhpCsFixer\Fixer\DeprecatedFixerInterface;
16-
use PhpCsFixer\FixerConfiguration\FixerOptionInterface;
1715

1816
/**
1917
* @internal
2018
*
21-
* @property ConfigurableFixerInterface&DeprecatedFixerInterface $fixer
19+
* @property DeprecatedFixerInterface $fixer
2220
*
2321
* @covers \PhpCsFixerCustomFixers\Fixer\DataProviderNameFixer
2422
*/
2523
final class DataProviderNameFixerTest extends AbstractFixerTestCase
2624
{
2725
public function testConfiguration(): void
2826
{
29-
/** @var array<FixerOptionInterface> $options */
30-
$options = $this->fixer->getConfigurationDefinition()->getOptions();
27+
$options = self::getConfigurationOptions();
3128
self::assertArrayHasKey(0, $options);
3229
self::assertSame('prefix', $options[0]->getName());
3330
self::assertSame('provide', $options[0]->getDefault());

tests/Fixer/DataProviderReturnTypeFixerTest.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,12 @@
1111

1212
namespace Tests\Fixer;
1313

14-
use PhpCsFixer\Fixer\ConfigurableFixerInterface;
1514
use PhpCsFixer\Fixer\DeprecatedFixerInterface;
1615

1716
/**
1817
* @internal
1918
*
20-
* @property ConfigurableFixerInterface&DeprecatedFixerInterface $fixer
19+
* @property DeprecatedFixerInterface $fixer
2120
*
2221
* @covers \PhpCsFixerCustomFixers\Fixer\DataProviderReturnTypeFixer
2322
*/

tests/Fixer/DataProviderStaticFixerTest.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,12 @@
1111

1212
namespace Tests\Fixer;
1313

14-
use PhpCsFixer\Fixer\ConfigurableFixerInterface;
1514
use PhpCsFixer\Fixer\DeprecatedFixerInterface;
1615

1716
/**
1817
* @internal
1918
*
20-
* @property ConfigurableFixerInterface&DeprecatedFixerInterface $fixer
19+
* @property DeprecatedFixerInterface $fixer
2120
*
2221
* @covers \PhpCsFixerCustomFixers\Fixer\DataProviderStaticFixer
2322
*/
@@ -35,7 +34,7 @@ public function testSuccessorName(): void
3534

3635
public function testConfiguration(): void
3736
{
38-
$options = $this->fixer->getConfigurationDefinition()->getOptions();
37+
$options = self::getConfigurationOptions();
3938
self::assertArrayHasKey(0, $options);
4039
self::assertSame('force', $options[0]->getName());
4140
}

tests/Fixer/MultilinePromotedPropertiesFixerTest.php

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,9 @@
1111

1212
namespace Tests\Fixer;
1313

14-
use PhpCsFixer\Fixer\ConfigurableFixerInterface;
15-
use PhpCsFixer\Fixer\WhitespacesAwareFixerInterface;
16-
use PhpCsFixer\FixerConfiguration\FixerOptionInterface;
17-
1814
/**
1915
* @internal
2016
*
21-
* @property ConfigurableFixerInterface&WhitespacesAwareFixerInterface $fixer
22-
*
2317
* @covers \PhpCsFixerCustomFixers\Fixer\MultilinePromotedPropertiesFixer
2418
*
2519
* @requires PHP 8.0
@@ -28,8 +22,7 @@ final class MultilinePromotedPropertiesFixerTest extends AbstractFixerTestCase
2822
{
2923
public function testConfiguration(): void
3024
{
31-
/** @var array<FixerOptionInterface> $options */
32-
$options = $this->fixer->getConfigurationDefinition()->getOptions();
25+
$options = self::getConfigurationOptions();
3326
self::assertArrayHasKey(0, $options);
3427
self::assertSame('keep_blank_lines', $options[0]->getName());
3528
self::assertFalse($options[0]->getDefault());

tests/Fixer/NoDuplicatedArrayKeyFixerTest.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,9 @@
1111

1212
namespace Tests\Fixer;
1313

14-
use PhpCsFixer\Fixer\ConfigurableFixerInterface;
15-
1614
/**
1715
* @internal
1816
*
19-
* @property ConfigurableFixerInterface $fixer
20-
*
2117
* @covers \PhpCsFixerCustomFixers\Fixer\NoDuplicatedArrayKeyFixer
2218
*/
2319
final class NoDuplicatedArrayKeyFixerTest extends AbstractFixerTestCase
@@ -29,7 +25,7 @@ public function testIsRisky(): void
2925

3026
public function testConfiguration(): void
3127
{
32-
$options = $this->fixer->getConfigurationDefinition()->getOptions();
28+
$options = self::getConfigurationOptions();
3329
self::assertArrayHasKey(0, $options);
3430
self::assertSame('ignore_expressions', $options[0]->getName());
3531
}

tests/Fixer/NoSuperfluousConcatenationFixerTest.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,9 @@
1111

1212
namespace Tests\Fixer;
1313

14-
use PhpCsFixer\Fixer\ConfigurableFixerInterface;
15-
1614
/**
1715
* @internal
1816
*
19-
* @property ConfigurableFixerInterface $fixer
20-
*
2117
* @covers \PhpCsFixerCustomFixers\Fixer\NoSuperfluousConcatenationFixer
2218
*/
2319
final class NoSuperfluousConcatenationFixerTest extends AbstractFixerTestCase
@@ -29,7 +25,7 @@ public function testIsRisky(): void
2925

3026
public function testConfiguration(): void
3127
{
32-
$options = $this->fixer->getConfigurationDefinition()->getOptions();
28+
$options = self::getConfigurationOptions();
3329
self::assertArrayHasKey(0, $options);
3430
self::assertSame('allow_preventing_trailing_spaces', $options[0]->getName());
3531
}

tests/Fixer/NumericLiteralSeparatorFixerTest.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,11 @@
1111

1212
namespace Tests\Fixer;
1313

14-
use PhpCsFixer\Fixer\ConfigurableFixerInterface;
1514
use PhpCsFixer\Tokenizer\Tokens;
1615

1716
/**
1817
* @internal
1918
*
20-
* @property ConfigurableFixerInterface $fixer
21-
*
2219
* @covers \PhpCsFixerCustomFixers\Fixer\NumericLiteralSeparatorFixer
2320
*/
2421
final class NumericLiteralSeparatorFixerTest extends AbstractFixerTestCase
@@ -30,7 +27,7 @@ public function testIsRisky(): void
3027

3128
public function testConfiguration(): void
3229
{
33-
$options = $this->fixer->getConfigurationDefinition()->getOptions();
30+
$options = self::getConfigurationOptions();
3431
self::assertArrayHasKey(0, $options);
3532
self::assertSame('binary', $options[0]->getName());
3633
self::assertArrayHasKey(1, $options);

tests/Fixer/PhpdocOnlyAllowedAnnotationsFixerTest.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,20 +11,16 @@
1111

1212
namespace Tests\Fixer;
1313

14-
use PhpCsFixer\Fixer\ConfigurableFixerInterface;
15-
1614
/**
1715
* @internal
1816
*
19-
* @property ConfigurableFixerInterface $fixer
20-
*
2117
* @covers \PhpCsFixerCustomFixers\Fixer\PhpdocOnlyAllowedAnnotationsFixer
2218
*/
2319
final class PhpdocOnlyAllowedAnnotationsFixerTest extends AbstractFixerTestCase
2420
{
2521
public function testConfiguration(): void
2622
{
27-
$options = $this->fixer->getConfigurationDefinition()->getOptions();
23+
$options = self::getConfigurationOptions();
2824
self::assertArrayHasKey(0, $options);
2925
self::assertSame('elements', $options[0]->getName());
3026
}

0 commit comments

Comments
 (0)