Skip to content
Permalink
Browse files

Call "configure" method only for non-default config in tests (#163)

  • Loading branch information...
kubawerlos committed Oct 22, 2019
1 parent ef969ad commit 64b60d31e42fa1ddc87dc2db5cc5a0f9545504f2
@@ -19,12 +19,20 @@
final class OperatorLinebreakFixer extends AbstractFixer implements ConfigurationDefinitionFixerInterface, DeprecatingFixerInterface
{
private const BOOLEAN_OPERATORS = [[T_BOOLEAN_AND], [T_BOOLEAN_OR], [T_LOGICAL_AND], [T_LOGICAL_OR], [T_LOGICAL_XOR]];
private const NON_BOOLEAN_OPERATORS = ['%', '&', '*', '+', '-', '.', '/', ':', '<', '=', '>', '?', '^', '|', [T_AND_EQUAL], [T_COALESCE], [T_CONCAT_EQUAL], [T_DIV_EQUAL], [T_DOUBLE_ARROW], [T_IS_EQUAL], [T_IS_GREATER_OR_EQUAL], [T_IS_IDENTICAL], [T_IS_NOT_EQUAL], [T_IS_NOT_IDENTICAL], [T_IS_SMALLER_OR_EQUAL], [T_MINUS_EQUAL], [T_MOD_EQUAL], [T_MUL_EQUAL], [T_OBJECT_OPERATOR], [T_OR_EQUAL], [T_PAAMAYIM_NEKUDOTAYIM], [T_PLUS_EQUAL], [T_POW], [T_POW_EQUAL], [T_SL], [T_SL_EQUAL], [T_SPACESHIP], [T_SR], [T_SR_EQUAL], [T_XOR_EQUAL]];
/** @var string */
private $position = 'beginning';
/** @var array<array<int|string>|string> */
private $operators = [];
public function __construct()
{
$this->operators = \array_merge(self::BOOLEAN_OPERATORS, self::NON_BOOLEAN_OPERATORS);
}
public function getDefinition(): FixerDefinitionInterface
{
return new FixerDefinition(
@@ -54,54 +62,8 @@ public function getConfigurationDefinition(): FixerConfigurationResolver
public function configure(?array $configuration = null): void
{
$this->operators = [[T_BOOLEAN_AND], [T_BOOLEAN_OR], [T_LOGICAL_AND], [T_LOGICAL_OR], [T_LOGICAL_XOR]];
if (!isset($configuration['only_booleans']) || $configuration['only_booleans'] === false) {
$this->operators = \array_merge(
$this->operators,
[
'%',
'&',
'*',
'+',
'-',
'.',
'/',
':',
'<',
'=',
'>',
'?',
'^',
'|',
[T_AND_EQUAL],
[T_COALESCE],
[T_CONCAT_EQUAL],
[T_DIV_EQUAL],
[T_DOUBLE_ARROW],
[T_IS_EQUAL],
[T_IS_GREATER_OR_EQUAL],
[T_IS_IDENTICAL],
[T_IS_NOT_EQUAL],
[T_IS_NOT_IDENTICAL],
[T_IS_SMALLER_OR_EQUAL],
[T_MINUS_EQUAL],
[T_MOD_EQUAL],
[T_MUL_EQUAL],
[T_OBJECT_OPERATOR],
[T_OR_EQUAL],
[T_PAAMAYIM_NEKUDOTAYIM],
[T_PLUS_EQUAL],
[T_POW],
[T_POW_EQUAL],
[T_SL],
[T_SL_EQUAL],
[T_SPACESHIP],
[T_SR],
[T_SR_EQUAL],
[T_XOR_EQUAL],
]
);
if (isset($configuration['only_booleans']) && $configuration['only_booleans'] === true) {
$this->operators = self::BOOLEAN_OPERATORS;
}
$this->position = $configuration['position'] ?? $this->position;
@@ -84,8 +84,12 @@ abstract class AbstractFixerTestCase extends TestCase
static::assertNotSame($codeSample->getCode(), $tokens->generateCode());
}
final protected function doTest(string $expected, ?string $input = null): void
final protected function doTest(string $expected, ?string $input = null, ?array $configuration = null): void
{
if ($configuration !== null) {
$this->fixer->configure($configuration);
}
if ($expected === $input) {
throw new \InvalidArgumentException('Expected must be different to input.');
}
@@ -39,9 +39,7 @@ public function testIsRisky(): void
*/
public function testFix(string $expected, ?string $input = null, ?array $configuration = null): void
{
$this->fixer->configure($configuration);
$this->doTest($expected, $input);
$this->doTest($expected, $input, $configuration);
}
public function provideFixCases(): iterable
@@ -44,8 +44,7 @@ public function testDeprecatingPullRequest(): void
*/
public function testFix(string $expected, ?string $input = null, ?array $configuration = null): void
{
$this->fixer->configure($configuration);
$this->doTest($expected, $input);
$this->doTest($expected, $input, $configuration);
}
public function provideFixCases(): iterable
@@ -214,6 +213,7 @@ private function pairs(): iterable
return $foo +
$bar;
',
['only_booleans' => false],
];
yield 'handle uppercase operator' => [
@@ -39,9 +39,7 @@ public function testIsRisky(): void
*/
public function testFix(string $expected, ?string $input = null, ?array $configuration = null): void
{
$this->fixer->configure($configuration);
$this->doTest($expected, $input);
$this->doTest($expected, $input, $configuration);
}
public function provideFixCases(): iterable
@@ -119,9 +119,7 @@ public function testIsRisky(): void
*/
public function testFix(string $expected, ?string $input = null, ?array $configuration = null): void
{
$this->fixer->configure($configuration);
$this->doTest($expected, $input);
$this->doTest($expected, $input, $configuration);
}
public function provideFixCases(): iterable

0 comments on commit 64b60d3

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