Skip to content
Permalink
Browse files

Merge pull request #159 from kubawerlos/operator-linebreak-more-tests

OperatorLinebreakFixer - more tests
  • Loading branch information...
kubawerlos committed Oct 19, 2019
2 parents 51d29bb + a202c5d commit 2d5fad7fa58e1dd08dba4da8b4798293e8a78763
Showing with 124 additions and 139 deletions.
  1. +1 −1 README.md
  2. +123 −138 tests/Fixer/OperatorLinebreakFixerTest.php
@@ -8,7 +8,7 @@

[![Build status](https://img.shields.io/travis/kubawerlos/php-cs-fixer-custom-fixers/master.svg)](https://travis-ci.org/kubawerlos/php-cs-fixer-custom-fixers)
[![Code coverage](https://img.shields.io/coveralls/github/kubawerlos/php-cs-fixer-custom-fixers/master.svg)](https://coveralls.io/github/kubawerlos/php-cs-fixer-custom-fixers?branch=master)
![Tests](https://img.shields.io/badge/tests-1243-brightgreen.svg)
![Tests](https://img.shields.io/badge/tests-1299-brightgreen.svg)
[![Mutation testing badge](https://badge.stryker-mutator.io/github.com/kubawerlos/php-cs-fixer-custom-fixers/master)](https://stryker-mutator.github.io)
[![Psalm type coverage](https://shepherd.dev/github/kubawerlos/php-cs-fixer-custom-fixers/coverage.svg)](https://shepherd.dev/github/kubawerlos/php-cs-fixer-custom-fixers)

@@ -50,122 +50,189 @@ public function testFix(string $expected, ?string $input = null, ?array $configu
public function provideFixCases(): iterable
{
yield 'handle equal sign' => [
foreach ($this->pairs() as $key => $value) {
yield \sprintf('%s when position is "beginning"', $key) => $value;
}
foreach ($this->pairs() as $key => $value) {
yield \sprintf('%s when position is "end"', $key) => [
$value[1],
$value[0],
['position' => 'end'],
];
}
yield 'ignore add operator when only booleans enabled' => [
'<?php
$foo
= $bar;
return $foo
+
$bar;
',
null,
['only_booleans' => true],
];
yield 'handle operator when on separate line when position is "beginning"' => [
'<?php
return $foo
|| $bar;
',
'<?php
$foo =
return $foo
||
$bar;
',
];
yield 'handle add operator' => [
yield 'handle operator when on separate line when position is "end"' => [
'<?php
return $foo
+ $bar;
return $foo ||
$bar;
',
'<?php
return $foo +
return $foo
||
$bar;
',
['position' => 'end'],
];
yield 'handle uppercase operator' => [
yield 'handle Elvis operator with space inside' => [
'<?php
return $foo
AND $bar;
?: $bar;
',
'<?php
return $foo AND
return $foo ? :
$bar;
',
];
yield 'handle concatenation operator' => [
yield 'handle Elvis operator with space inside when position is "end"' => [
'<?php
return $foo ?:
$bar;
',
'<?php
return $foo
.$bar;
? : $bar;
',
['position' => 'end'],
];
yield 'handle Elvis operator with comment inside' => [
'<?php
return $foo.
return $foo/* Lorem ipsum */
?: $bar;
',
'<?php
return $foo ?/* Lorem ipsum */:
$bar;
',
];
yield 'ignore add operator when only booleans enabled' => [
yield 'handle Elvis operators with comment inside when position is "end"' => [
'<?php
return $foo +
$bar;
return $foo ?:
/* Lorem ipsum */$bar;
',
'<?php
return $foo
?/* Lorem ipsum */: $bar;
',
['position' => 'end'],
];
yield 'nullable type when position is "end"' => [
'<?php
function foo(
?int $x,
?int $y,
?int $z
) {};',
null,
['only_booleans' => true],
['position' => 'end'],
];
yield 'handle ternary operator' => [
yield 'return type' => [
'<?php
return $foo
? $bar
: $baz;
function foo()
:
bool
{};',
];
}
private function pairs(): iterable
{
yield 'handle equal sign' => [
'<?php
$foo
= $bar;
',
'<?php
return $foo ?
$bar :
$baz;
$foo =
$bar;
',
];
yield 'handle multiple operators' => [
yield 'handle add operator' => [
'<?php
return $foo
|| $bar
|| $baz;
+ $bar;
',
'<?php
return $foo ||
$bar ||
$baz;
return $foo +
$bar;
',
];
yield 'handle operator when on separate line' => [
yield 'handle uppercase operator' => [
'<?php
return $foo
|| $bar;
AND $bar;
',
'<?php
return $foo AND
$bar;
',
];
yield 'handle concatenation operator' => [
'<?php
return $foo
||
.$bar;
',
'<?php
return $foo.
$bar;
',
];
yield 'handle multiline operator when position is "end"' => [
yield 'handle ternary operator' => [
'<?php
return $foo ||
$bar ||
return $foo
? $bar
: $baz;
',
'<?php
return $foo ?
$bar :
$baz;
',
];
yield 'handle multiple operators' => [
'<?php
return $foo
|| $bar
|| $baz;
',
['position' => 'end'],
];
yield 'handle operator when on its own line and position is "end"' => [
'<?php
return $foo ||
$bar;
',
'<?php
return $foo
||
$bar;
$bar ||
$baz;
',
['position' => 'end'],
];
yield 'handle operator when no whitespace is before' => [
@@ -183,22 +250,6 @@ function foo() {
',
];
yield 'handle operator when no whitespace is after and position is "end"' => [
'<?php
function foo() {
return $a||
$b;
}
',
'<?php
function foo() {
return $a
||$b;
}
',
['position' => 'end'],
];
yield 'handle operator with one-line comments' => [
'<?php
function getNewCuyamaTotal() {
@@ -286,66 +337,19 @@ function foo() {
',
];
yield 'handle Elvis operator when position is "end"' => [
'<?php
return $foo ?:
$bar;
',
'<?php
return $foo
?: $bar;
',
['position' => 'end'],
];
yield 'handle Elvis operator with space inside' => [
'<?php
return $foo
?: $bar;
',
'<?php
return $foo ? :
$bar;
',
];
yield 'handle Elvis operator with comment inside' => [
'<?php
return $foo/* Lorem ipsum */
?: $bar;
',
'<?php
return $foo ?/* Lorem ipsum */:
$bar;
',
['position' => 'beginning'],
];
yield 'handle Elvis operators with comment inside to end' => [
'<?php
return $foo ?:
/* Lorem ipsum */$bar;
',
'<?php
return $foo
?/* Lorem ipsum */: $bar;
',
['position' => 'end'],
];
yield 'handle ternary operator inside of switch' => [
'<?php
switch ($foo) {
case 1:
return $isOK ? 1 : -1;
case (
$a
$a
? 2
: 3
) :
return 23;
case $b[
$a
$a
? 4
: 5
]
@@ -357,13 +361,13 @@ function foo() {
case 1:
return $isOK ? 1 : -1;
case (
$a
? 2
: 3
$a ?
2 :
3
) :
return 23;
case $b[
$a ?
$a ?
4 :
5
]
@@ -401,31 +405,12 @@ function () {
',
];
yield 'nullable type' => [
'<?php
function foo(
?int $x,
?int $y,
?int $z
) {};',
null,
['position' => 'end'],
];
yield 'return type' => [
'<?php
function foo()
:
bool
{};',
];
foreach ([
'+', '-', '*', '/', '%', '**', // Arithmetic
'+=', '-=', '*=', '/=', '%=', '**=', // Arithmetic assignment
'=', // Assignment
'&', '|', '^', '<<', '>>', // Bitwise
'&=', '|=', '^=', '<<=', '>>=', // Bitwise assignment
'&', '|', '^', '<<', '>>', // Bitwise
'&=', '|=', '^=', '<<=', '>>=', // Bitwise assignment
'==', '===', '!=', '<>', '!==', '<', '>', '<=', '>=', '<=>', // Comparison
'and', 'or', 'xor', '&&', '||', // Logical
'.', '.=', // String

0 comments on commit 2d5fad7

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