mirror of
https://github.com/elyby/php-code-style.git
synced 2025-05-31 14:12:05 +05:30
Migrate to PHP-CS-Fixer 3. Upgrade custom rules. Upgrade ruleset.
This commit is contained in:
@ -1,9 +1,10 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Ely\CS\Test\Fixer\Operator;
|
||||
namespace Ely\CS\Test\Fixer\LanguageConstruct;
|
||||
|
||||
use Ely\CS\Fixer\LanguageConstruct\RemoveClassNameMethodUsagesFixer;
|
||||
use PhpCsFixer\AbstractFixer;
|
||||
use PhpCsFixer\Tests\Test\AbstractFixerTestCase;
|
||||
|
||||
/**
|
||||
@ -12,55 +13,53 @@ use PhpCsFixer\Tests\Test\AbstractFixerTestCase;
|
||||
class RemoveClassNameMethodUsagesFixerTest extends AbstractFixerTestCase {
|
||||
|
||||
/**
|
||||
* @param string $expected
|
||||
* @param null|string $input
|
||||
*
|
||||
* @dataProvider provideFixCases
|
||||
*/
|
||||
public function testFix($expected, $input = null) {
|
||||
public function testFix(string $expected, ?string $input = null): void {
|
||||
$this->doTest($expected, $input);
|
||||
}
|
||||
|
||||
public function provideFixCases() {
|
||||
return [
|
||||
[
|
||||
'<?php echo className();',
|
||||
],
|
||||
[
|
||||
'<?php
|
||||
public function provideFixCases(): iterable {
|
||||
yield [
|
||||
'<?php echo className();',
|
||||
];
|
||||
|
||||
yield [
|
||||
'<?php
|
||||
use Foo\Bar\Baz;
|
||||
|
||||
$exceptionString = Baz::classname();
|
||||
',
|
||||
],
|
||||
[
|
||||
'<?php
|
||||
];
|
||||
|
||||
yield [
|
||||
'<?php
|
||||
use Foo\Bar\Baz;
|
||||
|
||||
$className = Baz::class;
|
||||
',
|
||||
'<?php
|
||||
'<?php
|
||||
use Foo\Bar\Baz;
|
||||
|
||||
$className = Baz::className();
|
||||
',
|
||||
],
|
||||
[
|
||||
'<?php
|
||||
];
|
||||
|
||||
yield [
|
||||
'<?php
|
||||
use Foo\Bar\Baz;
|
||||
|
||||
$exceptionString = "The class should be instance of " . Baz::class . " and nothing else";
|
||||
',
|
||||
'<?php
|
||||
'<?php
|
||||
use Foo\Bar\Baz;
|
||||
|
||||
$exceptionString = "The class should be instance of " . Baz::className() . " and nothing else";
|
||||
',
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
protected function createFixer() {
|
||||
protected function createFixer(): AbstractFixer {
|
||||
return new RemoveClassNameMethodUsagesFixer();
|
||||
}
|
||||
|
||||
|
@ -1,319 +0,0 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Ely\CS\Test\Fixer\Operator;
|
||||
|
||||
use Ely\CS\Fixer\Operator\NewWithBracesFixer;
|
||||
use PhpCsFixer\Tests\Test\AbstractFixerTestCase;
|
||||
|
||||
/**
|
||||
* Original file copied from:
|
||||
* @url https://github.com/FriendsOfPHP/PHP-CS-Fixer/blob/5c5de791ab/tests/Fixer/Operator/NewWithBracesFixerTest.php
|
||||
*
|
||||
* @covers \Ely\CS\Fixer\Operator\NewWithBracesFixer
|
||||
*/
|
||||
class NewWithBracesFixerTest extends AbstractFixerTestCase {
|
||||
|
||||
private static $removeForAnonymousClasses = ['remove_for_anonymous_classes' => true];
|
||||
|
||||
/**
|
||||
* @param string $expected
|
||||
* @param null|string $input
|
||||
*
|
||||
* @dataProvider provideFixCases
|
||||
*/
|
||||
public function testFix($expected, $input = null) {
|
||||
$this->doTest($expected, $input);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $expected
|
||||
* @param null|string $input
|
||||
*
|
||||
* @dataProvider provideFix70Cases
|
||||
* @requires PHP 7.0
|
||||
*/
|
||||
public function testFix70($expected, $input = null, array $configuration = null) {
|
||||
if ($configuration !== null) {
|
||||
$this->fixer->configure($configuration);
|
||||
}
|
||||
|
||||
$this->doTest($expected, $input);
|
||||
}
|
||||
|
||||
public function provideFixCases() {
|
||||
return [
|
||||
[
|
||||
'<?php class A { public function B(){ $static = new static(new \SplFileInfo(__FILE__)); }}',
|
||||
],
|
||||
[
|
||||
'<?php $static = new self(new \SplFileInfo(__FILE__));',
|
||||
],
|
||||
[
|
||||
'<?php $x = new X/**/ /**/ /**//**//**/ /**//**/ (/**/ /**/ /**//**//**/ /**//**/)/**/ /**/ /**//**//**/ /**//**/;/**/ /**/ /**//**//**/ /**//**/',
|
||||
],
|
||||
[
|
||||
'<?php $x = new X();',
|
||||
'<?php $x = new X;',
|
||||
],
|
||||
[
|
||||
'<?php $y = new Y() ;',
|
||||
'<?php $y = new Y ;',
|
||||
],
|
||||
[
|
||||
'<?php $x = new Z() /**/;//',
|
||||
'<?php $x = new Z /**/;//',
|
||||
],
|
||||
[
|
||||
'<?php $foo = new $foo();',
|
||||
'<?php $foo = new $foo;',
|
||||
],
|
||||
[
|
||||
'<?php $xyz = new X(new Y(new Z()));',
|
||||
'<?php $xyz = new X(new Y(new Z));',
|
||||
],
|
||||
[
|
||||
'<?php $foo = (new $bar())->foo;',
|
||||
'<?php $foo = (new $bar)->foo;',
|
||||
],
|
||||
[
|
||||
'<?php $foo = (new $bar((new Foo())->bar))->foo;',
|
||||
'<?php $foo = (new $bar((new Foo)->bar))->foo;',
|
||||
],
|
||||
[
|
||||
'<?php $self = new self();',
|
||||
'<?php $self = new self;',
|
||||
],
|
||||
[
|
||||
'<?php $static = new static();',
|
||||
'<?php $static = new static;',
|
||||
],
|
||||
[
|
||||
'<?php $a = array( "key" => new DateTime(), );',
|
||||
'<?php $a = array( "key" => new DateTime, );',
|
||||
],
|
||||
[
|
||||
'<?php $a = array( "key" => new DateTime() );',
|
||||
'<?php $a = array( "key" => new DateTime );',
|
||||
],
|
||||
[
|
||||
'<?php $a = new $b[$c]();',
|
||||
'<?php $a = new $b[$c];',
|
||||
],
|
||||
[
|
||||
'<?php $a = new $b[$c[$d ? foo() : bar("bar[...]") - 1]]();',
|
||||
'<?php $a = new $b[$c[$d ? foo() : bar("bar[...]") - 1]];',
|
||||
],
|
||||
[
|
||||
'<?php $a = new $b[\'class\']();',
|
||||
'<?php $a = new $b[\'class\'];',
|
||||
],
|
||||
[
|
||||
'<?php $a = new $b[\'class\'] ($foo[\'bar\']);',
|
||||
],
|
||||
[
|
||||
'<?php $a = new $b[\'class\'] () ;',
|
||||
],
|
||||
[
|
||||
'<?php $a = new $b[$c] ($hello[$world]) ;',
|
||||
],
|
||||
[
|
||||
"<?php \$a = new \$b['class']()\r\n\t ;",
|
||||
"<?php \$a = new \$b['class']\r\n\t ;",
|
||||
],
|
||||
[
|
||||
'<?php $a = $b ? new DateTime() : $b;',
|
||||
'<?php $a = $b ? new DateTime : $b;',
|
||||
],
|
||||
[
|
||||
'<?php new self::$adapters[$name]["adapter"]();',
|
||||
'<?php new self::$adapters[$name]["adapter"];',
|
||||
],
|
||||
[
|
||||
'<?php $a = new \Exception()?> <?php echo 1;',
|
||||
'<?php $a = new \Exception?> <?php echo 1;',
|
||||
],
|
||||
[
|
||||
'<?php $b = new \StdClass() /**/?>',
|
||||
'<?php $b = new \StdClass /**/?>',
|
||||
],
|
||||
[
|
||||
'<?php $a = new Foo() instanceof Foo;',
|
||||
'<?php $a = new Foo instanceof Foo;',
|
||||
],
|
||||
[
|
||||
'<?php
|
||||
$a = new Foo() + 1;
|
||||
$a = new Foo() - 1;
|
||||
$a = new Foo() * 1;
|
||||
$a = new Foo() / 1;
|
||||
$a = new Foo() % 1;
|
||||
',
|
||||
'<?php
|
||||
$a = new Foo + 1;
|
||||
$a = new Foo - 1;
|
||||
$a = new Foo * 1;
|
||||
$a = new Foo / 1;
|
||||
$a = new Foo % 1;
|
||||
',
|
||||
],
|
||||
[
|
||||
'<?php
|
||||
$a = new Foo() & 1;
|
||||
$a = new Foo() | 1;
|
||||
$a = new Foo() ^ 1;
|
||||
$a = new Foo() << 1;
|
||||
$a = new Foo() >> 1;
|
||||
',
|
||||
'<?php
|
||||
$a = new Foo & 1;
|
||||
$a = new Foo | 1;
|
||||
$a = new Foo ^ 1;
|
||||
$a = new Foo << 1;
|
||||
$a = new Foo >> 1;
|
||||
',
|
||||
],
|
||||
[
|
||||
'<?php
|
||||
$a = new Foo() and 1;
|
||||
$a = new Foo() or 1;
|
||||
$a = new Foo() xor 1;
|
||||
$a = new Foo() && 1;
|
||||
$a = new Foo() || 1;
|
||||
',
|
||||
'<?php
|
||||
$a = new Foo and 1;
|
||||
$a = new Foo or 1;
|
||||
$a = new Foo xor 1;
|
||||
$a = new Foo && 1;
|
||||
$a = new Foo || 1;
|
||||
',
|
||||
],
|
||||
[
|
||||
'<?php
|
||||
if (new DateTime() > $this->startDate) {}
|
||||
if (new DateTime() >= $this->startDate) {}
|
||||
if (new DateTime() < $this->startDate) {}
|
||||
if (new DateTime() <= $this->startDate) {}
|
||||
if (new DateTime() == $this->startDate) {}
|
||||
if (new DateTime() != $this->startDate) {}
|
||||
if (new DateTime() <> $this->startDate) {}
|
||||
if (new DateTime() === $this->startDate) {}
|
||||
if (new DateTime() !== $this->startDate) {}
|
||||
',
|
||||
'<?php
|
||||
if (new DateTime > $this->startDate) {}
|
||||
if (new DateTime >= $this->startDate) {}
|
||||
if (new DateTime < $this->startDate) {}
|
||||
if (new DateTime <= $this->startDate) {}
|
||||
if (new DateTime == $this->startDate) {}
|
||||
if (new DateTime != $this->startDate) {}
|
||||
if (new DateTime <> $this->startDate) {}
|
||||
if (new DateTime === $this->startDate) {}
|
||||
if (new DateTime !== $this->startDate) {}
|
||||
',
|
||||
],
|
||||
[
|
||||
'<?php $a = new \stdClass() ? $b : $c;',
|
||||
'<?php $a = new \stdClass ? $b : $c;',
|
||||
],
|
||||
[
|
||||
'<?php foreach (new Collection() as $x) {}',
|
||||
'<?php foreach (new Collection as $x) {}',
|
||||
],
|
||||
[
|
||||
'<?php $a = [(string) new Foo() => 1];',
|
||||
'<?php $a = [(string) new Foo => 1];',
|
||||
],
|
||||
[
|
||||
'<?php $a = [ "key" => new DateTime(), ];',
|
||||
'<?php $a = [ "key" => new DateTime, ];',
|
||||
],
|
||||
[
|
||||
'<?php $a = [ "key" => new DateTime() ];',
|
||||
'<?php $a = [ "key" => new DateTime ];',
|
||||
],
|
||||
[
|
||||
'<?php
|
||||
$a = new Foo() ** 1;
|
||||
',
|
||||
'<?php
|
||||
$a = new Foo ** 1;
|
||||
',
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
public function provideFix70Cases() {
|
||||
return [
|
||||
[
|
||||
'<?php
|
||||
$a = new Foo() <=> 1;
|
||||
',
|
||||
'<?php
|
||||
$a = new Foo <=> 1;
|
||||
',
|
||||
],
|
||||
[
|
||||
'<?php
|
||||
$a = new class() {use SomeTrait;};
|
||||
$a = new class() implements Foo{};
|
||||
$a = new class() /**/ extends Bar1{};
|
||||
$a = new class() extends Bar2 implements Foo{};
|
||||
$a = new class() extends Bar3 implements Foo, Foo2{};
|
||||
$a = new class() {}?>
|
||||
',
|
||||
'<?php
|
||||
$a = new class {use SomeTrait;};
|
||||
$a = new class implements Foo{};
|
||||
$a = new class /**/ extends Bar1{};
|
||||
$a = new class extends Bar2 implements Foo{};
|
||||
$a = new class extends Bar3 implements Foo, Foo2{};
|
||||
$a = new class {}?>
|
||||
',
|
||||
],
|
||||
[
|
||||
'<?php
|
||||
class A {
|
||||
public function B() {
|
||||
$static = new static(new class(){});
|
||||
}
|
||||
}
|
||||
',
|
||||
'<?php
|
||||
class A {
|
||||
public function B() {
|
||||
$static = new static(new class{});
|
||||
}
|
||||
}
|
||||
',
|
||||
],
|
||||
[
|
||||
'<?php
|
||||
$a = new class {use SomeTrait;};
|
||||
$a = new class implements Foo{};
|
||||
$a = new class /**/ extends Bar1{};
|
||||
$a = new class extends Bar2 implements Foo{};
|
||||
$a = new class extends Bar3 implements Foo, Foo2{};
|
||||
$a = new class {};
|
||||
$a = new class {};
|
||||
',
|
||||
'<?php
|
||||
$a = new class() {use SomeTrait;};
|
||||
$a = new class() implements Foo{};
|
||||
$a = new class() /**/ extends Bar1{};
|
||||
$a = new class() extends Bar2 implements Foo{};
|
||||
$a = new class() extends Bar3 implements Foo, Foo2{};
|
||||
$a = new class() {};
|
||||
$a = new class( ) {};
|
||||
',
|
||||
self::$removeForAnonymousClasses,
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
protected function createFixer() {
|
||||
return new NewWithBracesFixer();
|
||||
}
|
||||
|
||||
}
|
@ -4,6 +4,7 @@ declare(strict_types=1);
|
||||
namespace Ely\CS\Test\Fixer\Whitespace;
|
||||
|
||||
use Ely\CS\Fixer\Whitespace\BlankLineAroundClassBodyFixer;
|
||||
use PhpCsFixer\AbstractFixer;
|
||||
use PhpCsFixer\Tests\Test\AbstractFixerTestCase;
|
||||
use PhpCsFixer\WhitespacesFixerConfig;
|
||||
|
||||
@ -19,40 +20,18 @@ final class BlankLineAroundClassBodyFixerTest extends AbstractFixerTestCase {
|
||||
private static $configurationTwoEmptyLines = ['blank_lines_count' => 2];
|
||||
|
||||
/**
|
||||
* @param string $expected
|
||||
* @param null|string $input
|
||||
* @param null|array $configuration
|
||||
*
|
||||
* @dataProvider provideFixCases
|
||||
*/
|
||||
public function testFix($expected, $input = null, array $configuration = null) {
|
||||
if (null !== $configuration) {
|
||||
public function testFix(string $expected, ?string $input = null, array $configuration = null): void {
|
||||
if ($configuration !== null) {
|
||||
$this->fixer->configure($configuration);
|
||||
}
|
||||
|
||||
$this->doTest($expected, $input);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $expected
|
||||
* @param null|string $input
|
||||
* @param array $configuration
|
||||
*
|
||||
* @dataProvider provideAnonymousClassesCases
|
||||
* @requires PHP 7.0
|
||||
*/
|
||||
public function testFixAnonymousClasses($expected, $input = null, array $configuration = null) {
|
||||
if (null !== $configuration) {
|
||||
$this->fixer->configure($configuration);
|
||||
}
|
||||
|
||||
$this->doTest($expected, $input);
|
||||
}
|
||||
|
||||
public function provideFixCases() {
|
||||
$cases = [];
|
||||
|
||||
$cases[] = [
|
||||
public function provideFixCases(): iterable {
|
||||
yield [
|
||||
'<?php
|
||||
class Good
|
||||
{
|
||||
@ -72,7 +51,8 @@ class Good
|
||||
}
|
||||
}',
|
||||
];
|
||||
$cases[] = [
|
||||
|
||||
yield [
|
||||
'<?php
|
||||
class Good
|
||||
{
|
||||
@ -98,7 +78,8 @@ class Good
|
||||
}
|
||||
}',
|
||||
];
|
||||
$cases[] = [
|
||||
|
||||
yield [
|
||||
'<?php
|
||||
class Good
|
||||
{
|
||||
@ -130,7 +111,8 @@ class Good
|
||||
}',
|
||||
];
|
||||
|
||||
$cases[] = [
|
||||
|
||||
yield [
|
||||
'<?php
|
||||
interface Good
|
||||
{
|
||||
@ -150,7 +132,8 @@ interface Good
|
||||
public function firstMethod();
|
||||
}',
|
||||
];
|
||||
$cases[] = [
|
||||
|
||||
yield [
|
||||
'<?php
|
||||
trait Good
|
||||
{
|
||||
@ -170,7 +153,8 @@ trait Good
|
||||
public function firstMethod() {}
|
||||
}',
|
||||
];
|
||||
$cases[] = [
|
||||
|
||||
yield [
|
||||
'<?php
|
||||
class Good
|
||||
{
|
||||
@ -193,7 +177,8 @@ class Good
|
||||
}
|
||||
}',
|
||||
];
|
||||
$cases[] = [
|
||||
|
||||
yield [
|
||||
'<?php
|
||||
class Good
|
||||
{
|
||||
@ -218,7 +203,8 @@ class Good
|
||||
}
|
||||
}',
|
||||
];
|
||||
$cases[] = [
|
||||
|
||||
yield [
|
||||
'<?php
|
||||
class Good
|
||||
{
|
||||
@ -247,7 +233,8 @@ class Good
|
||||
}
|
||||
}',
|
||||
];
|
||||
$cases[] = [
|
||||
|
||||
yield [
|
||||
'<?php
|
||||
class Good
|
||||
{
|
||||
@ -272,7 +259,7 @@ class Good
|
||||
];
|
||||
|
||||
// check if some fancy whitespaces aren't modified
|
||||
$cases[] = [
|
||||
yield [
|
||||
'<?php
|
||||
class Good
|
||||
{public
|
||||
@ -287,13 +274,7 @@ class Good
|
||||
}',
|
||||
];
|
||||
|
||||
return $cases;
|
||||
}
|
||||
|
||||
public function provideAnonymousClassesCases() {
|
||||
$cases = [];
|
||||
|
||||
$cases[] = [
|
||||
yield [
|
||||
'<?php
|
||||
$class = new class extends \Foo {
|
||||
|
||||
@ -309,7 +290,8 @@ $class = new class extends \Foo {
|
||||
public function firstMethod() {}
|
||||
};',
|
||||
];
|
||||
$cases[] = [
|
||||
|
||||
yield [
|
||||
'<?php
|
||||
$class = new class extends \Foo {
|
||||
public $field;
|
||||
@ -326,17 +308,12 @@ $class = new class extends \Foo {
|
||||
};',
|
||||
self::$configurationDoNotApplyForAnonymousClasses,
|
||||
];
|
||||
|
||||
return $cases;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $expected
|
||||
* @param null|string $input
|
||||
*
|
||||
* @dataProvider provideMessyWhitespacesCases
|
||||
*/
|
||||
public function testMessyWhitespaces($expected, $input = null) {
|
||||
public function testMessyWhitespaces(string $expected, ?string $input = null): void {
|
||||
/** @var \PhpCsFixer\Fixer\WhitespacesAwareFixerInterface $fixer */
|
||||
$fixer = $this->fixer;
|
||||
$fixer->setWhitespacesConfig(new WhitespacesFixerConfig("\t", "\r\n"));
|
||||
@ -344,20 +321,19 @@ $class = new class extends \Foo {
|
||||
$this->doTest($expected, $input);
|
||||
}
|
||||
|
||||
public function provideMessyWhitespacesCases() {
|
||||
return [
|
||||
[
|
||||
"<?php\nclass Foo\n{\r\n\r\n public function bar() {}\r\n\r\n}",
|
||||
"<?php\nclass Foo\n{\n public function bar() {}\n}",
|
||||
],
|
||||
[
|
||||
"<?php\nclass Foo\n{\r\n\r\n public function bar() {}\r\n\r\n}",
|
||||
"<?php\nclass Foo\n{\r\n\r\n\n\n public function bar() {}\n\n\n\n}",
|
||||
],
|
||||
public function provideMessyWhitespacesCases(): iterable {
|
||||
yield [
|
||||
"<?php\nclass Foo\n{\r\n\r\n public function bar() {}\r\n\r\n}",
|
||||
"<?php\nclass Foo\n{\n public function bar() {}\n}",
|
||||
];
|
||||
|
||||
yield [
|
||||
"<?php\nclass Foo\n{\r\n\r\n public function bar() {}\r\n\r\n}",
|
||||
"<?php\nclass Foo\n{\r\n\r\n\n\n public function bar() {}\n\n\n\n}",
|
||||
];
|
||||
}
|
||||
|
||||
protected function createFixer() {
|
||||
protected function createFixer(): AbstractFixer {
|
||||
return new BlankLineAroundClassBodyFixer();
|
||||
}
|
||||
|
||||
|
@ -4,6 +4,7 @@ declare(strict_types=1);
|
||||
namespace Ely\CS\Test\Fixer\Whitespace;
|
||||
|
||||
use Ely\CS\Fixer\Whitespace\BlankLineBeforeReturnFixer;
|
||||
use PhpCsFixer\AbstractFixer;
|
||||
use PhpCsFixer\Tests\Test\AbstractFixerTestCase;
|
||||
use PhpCsFixer\WhitespacesFixerConfig;
|
||||
|
||||
@ -24,23 +25,19 @@ use PhpCsFixer\WhitespacesFixerConfig;
|
||||
final class BlankLineBeforeReturnFixerTest extends AbstractFixerTestCase {
|
||||
|
||||
/**
|
||||
* @param string $expected
|
||||
* @param null|string $input
|
||||
*
|
||||
* @dataProvider provideFixCases
|
||||
*/
|
||||
public function testFix($expected, $input = null) {
|
||||
public function testFix(string $expected, ?string $input = null): void {
|
||||
$this->doTest($expected, $input);
|
||||
}
|
||||
|
||||
public function provideFixCases() {
|
||||
$cases = [];
|
||||
$cases[] = [
|
||||
public function provideFixCases(): iterable {
|
||||
yield [
|
||||
'$a = $a;
|
||||
return $a;
|
||||
',
|
||||
];
|
||||
$cases[] = [
|
||||
yield [
|
||||
'<?php
|
||||
$a = $a;
|
||||
|
||||
@ -48,7 +45,7 @@ return $a;',
|
||||
'<?php
|
||||
$a = $a; return $a;',
|
||||
];
|
||||
$cases[] = [
|
||||
yield [
|
||||
'<?php
|
||||
$b = $b;
|
||||
|
||||
@ -56,7 +53,7 @@ return $b;',
|
||||
'<?php
|
||||
$b = $b;return $b;',
|
||||
];
|
||||
$cases[] = [
|
||||
yield [
|
||||
'<?php
|
||||
$c = $c;
|
||||
|
||||
@ -65,7 +62,7 @@ return $c;',
|
||||
$c = $c;
|
||||
return $c;',
|
||||
];
|
||||
$cases[] = [
|
||||
yield [
|
||||
'<?php
|
||||
$d = $d;
|
||||
|
||||
@ -74,19 +71,19 @@ return $c;',
|
||||
$d = $d;
|
||||
return $d;',
|
||||
];
|
||||
$cases[] = [
|
||||
yield [
|
||||
'<?php
|
||||
if (true) {
|
||||
return 1;
|
||||
}',
|
||||
];
|
||||
$cases[] = [
|
||||
yield [
|
||||
'<?php
|
||||
if (true)
|
||||
return 1;
|
||||
',
|
||||
];
|
||||
$cases[] = [
|
||||
yield [
|
||||
'<?php
|
||||
if (true) {
|
||||
return 1;
|
||||
@ -94,7 +91,7 @@ return $c;',
|
||||
return 2;
|
||||
}',
|
||||
];
|
||||
$cases[] = [
|
||||
yield [
|
||||
'<?php
|
||||
if (true)
|
||||
return 1;
|
||||
@ -102,7 +99,7 @@ return $c;',
|
||||
return 2;
|
||||
',
|
||||
];
|
||||
$cases[] = [
|
||||
yield [
|
||||
'<?php
|
||||
if (true) {
|
||||
return 1;
|
||||
@ -110,7 +107,7 @@ return $c;',
|
||||
return 2;
|
||||
}',
|
||||
];
|
||||
$cases[] = [
|
||||
yield [
|
||||
'<?php
|
||||
if (true)
|
||||
return 1;
|
||||
@ -118,11 +115,11 @@ return $c;',
|
||||
return 2;
|
||||
',
|
||||
];
|
||||
$cases[] = [
|
||||
yield [
|
||||
'<?php
|
||||
throw new Exception("return true;");',
|
||||
];
|
||||
$cases[] = [
|
||||
yield [
|
||||
'<?php
|
||||
function foo()
|
||||
{
|
||||
@ -130,7 +127,7 @@ return $c;',
|
||||
return "foo";
|
||||
}',
|
||||
];
|
||||
$cases[] = [
|
||||
yield [
|
||||
'<?php
|
||||
function foo()
|
||||
{
|
||||
@ -139,7 +136,7 @@ return $c;',
|
||||
return "bar";
|
||||
}',
|
||||
];
|
||||
$cases[] = [
|
||||
yield [
|
||||
'<?php
|
||||
function foo()
|
||||
{
|
||||
@ -147,7 +144,7 @@ return $c;',
|
||||
return "bar";
|
||||
}',
|
||||
];
|
||||
$cases[] = [
|
||||
yield [
|
||||
'<?php
|
||||
function foo() {
|
||||
$a = "a";
|
||||
@ -162,14 +159,14 @@ return $c;',
|
||||
return $a . $b;
|
||||
}',
|
||||
];
|
||||
$cases[] = [
|
||||
yield [
|
||||
'<?php
|
||||
function foo() {
|
||||
$b = "b";
|
||||
return $a . $b;
|
||||
}',
|
||||
];
|
||||
$cases[] = [
|
||||
yield [
|
||||
'<?php
|
||||
function foo() {
|
||||
$a = "a";
|
||||
@ -183,40 +180,33 @@ return $c;',
|
||||
}
|
||||
',
|
||||
];
|
||||
|
||||
return $cases;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $expected
|
||||
* @param null|string $input
|
||||
*
|
||||
* @dataProvider provideMessyWhitespacesCases
|
||||
*/
|
||||
public function testMessyWhitespaces($expected, $input = null) {
|
||||
public function testMessyWhitespaces(string $expected, ?string $input = null): void {
|
||||
$this->fixer->setWhitespacesConfig(new WhitespacesFixerConfig("\t", "\r\n"));
|
||||
|
||||
$this->doTest($expected, $input);
|
||||
}
|
||||
|
||||
public function provideMessyWhitespacesCases() {
|
||||
return [
|
||||
[
|
||||
"<?php\r\n\$a = \$a;\r\n\r\nreturn \$a;",
|
||||
"<?php\r\n\$a = \$a; return \$a;",
|
||||
],
|
||||
[
|
||||
"<?php\r\n\$b = \$b;\r\n\r\nreturn \$b;",
|
||||
"<?php\r\n\$b = \$b;return \$b;",
|
||||
],
|
||||
[
|
||||
"<?php\r\n\$c = \$c;\r\n\r\nreturn \$c;",
|
||||
"<?php\r\n\$c = \$c;\r\nreturn \$c;",
|
||||
],
|
||||
public function provideMessyWhitespacesCases(): iterable {
|
||||
yield [
|
||||
"<?php\r\n\$a = \$a;\r\n\r\nreturn \$a;",
|
||||
"<?php\r\n\$a = \$a; return \$a;",
|
||||
];
|
||||
yield [
|
||||
"<?php\r\n\$b = \$b;\r\n\r\nreturn \$b;",
|
||||
"<?php\r\n\$b = \$b;return \$b;",
|
||||
];
|
||||
yield [
|
||||
"<?php\r\n\$c = \$c;\r\n\r\nreturn \$c;",
|
||||
"<?php\r\n\$c = \$c;\r\nreturn \$c;",
|
||||
];
|
||||
}
|
||||
|
||||
protected function createFixer() {
|
||||
protected function createFixer(): AbstractFixer {
|
||||
return new BlankLineBeforeReturnFixer();
|
||||
}
|
||||
|
||||
|
@ -4,6 +4,7 @@ declare(strict_types=1);
|
||||
namespace Ely\CS\Test\Fixer\Whitespace;
|
||||
|
||||
use Ely\CS\Fixer\Whitespace\LineBreakAfterStatementsFixer;
|
||||
use PhpCsFixer\AbstractFixer;
|
||||
use PhpCsFixer\Tests\Test\AbstractFixerTestCase;
|
||||
|
||||
/**
|
||||
@ -14,20 +15,15 @@ use PhpCsFixer\Tests\Test\AbstractFixerTestCase;
|
||||
class LineBreakAfterStatementsFixerTest extends AbstractFixerTestCase {
|
||||
|
||||
/**
|
||||
* @param string $expected
|
||||
* @param string $input
|
||||
*
|
||||
* @dataProvider provideFixCases
|
||||
*/
|
||||
public function testFix(string $expected, $input = null) {
|
||||
public function testFix(string $expected, ?string $input = null): void {
|
||||
$this->doTest($expected, $input);
|
||||
}
|
||||
|
||||
public function provideFixCases() {
|
||||
$cases = [];
|
||||
|
||||
public function provideFixCases(): iterable {
|
||||
// Simple cases
|
||||
$cases[] = [
|
||||
yield [
|
||||
'<?php
|
||||
class Foo
|
||||
{
|
||||
@ -52,7 +48,8 @@ class Foo
|
||||
}
|
||||
}',
|
||||
];
|
||||
$cases[] = [
|
||||
|
||||
yield [
|
||||
'<?php
|
||||
class Foo
|
||||
{
|
||||
@ -81,7 +78,8 @@ class Foo
|
||||
}
|
||||
}',
|
||||
];
|
||||
$cases[] = [
|
||||
|
||||
yield [
|
||||
'<?php
|
||||
class Foo
|
||||
{
|
||||
@ -106,7 +104,8 @@ class Foo
|
||||
}
|
||||
}',
|
||||
];
|
||||
$cases[] = [
|
||||
|
||||
yield [
|
||||
'<?php
|
||||
class Foo
|
||||
{
|
||||
@ -131,7 +130,8 @@ class Foo
|
||||
}
|
||||
}',
|
||||
];
|
||||
$cases[] = [
|
||||
|
||||
yield [
|
||||
'<?php
|
||||
class Foo
|
||||
{
|
||||
@ -156,7 +156,8 @@ class Foo
|
||||
}
|
||||
}',
|
||||
];
|
||||
$cases[] = [
|
||||
|
||||
yield [
|
||||
'<?php
|
||||
class Foo
|
||||
{
|
||||
@ -181,7 +182,8 @@ class Foo
|
||||
}
|
||||
}',
|
||||
];
|
||||
$cases[] = [
|
||||
|
||||
yield [
|
||||
'<?php
|
||||
class Foo
|
||||
{
|
||||
@ -216,8 +218,9 @@ class Foo
|
||||
}
|
||||
}',
|
||||
];
|
||||
|
||||
// Extended cases
|
||||
$cases[] = [
|
||||
yield [
|
||||
'<?php
|
||||
class Foo
|
||||
{
|
||||
@ -250,7 +253,8 @@ class Foo
|
||||
}
|
||||
}',
|
||||
];
|
||||
$cases[] = [
|
||||
|
||||
yield [
|
||||
'<?php
|
||||
class Foo
|
||||
{
|
||||
@ -283,7 +287,8 @@ class Foo
|
||||
}
|
||||
}',
|
||||
];
|
||||
$cases[] = [
|
||||
|
||||
yield [
|
||||
'<?php
|
||||
class Foo
|
||||
{
|
||||
@ -310,7 +315,8 @@ class Foo
|
||||
}
|
||||
}',
|
||||
];
|
||||
$cases[] = [
|
||||
|
||||
yield [
|
||||
'<?php
|
||||
class Foo
|
||||
{
|
||||
@ -351,7 +357,8 @@ class Foo
|
||||
}
|
||||
}',
|
||||
];
|
||||
$cases[] = [
|
||||
|
||||
yield [
|
||||
'<?php
|
||||
$a = "prev statement";
|
||||
foreach ($coordinates as $coordinate) {
|
||||
@ -359,8 +366,9 @@ foreach ($coordinates as $coordinate) {
|
||||
}
|
||||
',
|
||||
];
|
||||
|
||||
// Issue 5
|
||||
$cases[] = [
|
||||
yield [
|
||||
'<?php
|
||||
class Foo
|
||||
{
|
||||
@ -383,7 +391,8 @@ class Foo
|
||||
}
|
||||
}',
|
||||
];
|
||||
$cases[] = [
|
||||
|
||||
yield [
|
||||
'<?php
|
||||
class Foo
|
||||
{
|
||||
@ -410,7 +419,8 @@ class Foo
|
||||
}
|
||||
}',
|
||||
];
|
||||
$cases[] = [
|
||||
|
||||
yield [
|
||||
'<?php
|
||||
class Foo
|
||||
{
|
||||
@ -433,7 +443,8 @@ class Foo
|
||||
}
|
||||
}',
|
||||
];
|
||||
$cases[] = [
|
||||
|
||||
yield [
|
||||
'<?php
|
||||
class Foo
|
||||
{
|
||||
@ -456,7 +467,8 @@ class Foo
|
||||
}
|
||||
}',
|
||||
];
|
||||
$cases[] = [
|
||||
|
||||
yield [
|
||||
'<?php
|
||||
class Foo
|
||||
{
|
||||
@ -479,7 +491,8 @@ class Foo
|
||||
}
|
||||
}',
|
||||
];
|
||||
$cases[] = [
|
||||
|
||||
yield [
|
||||
'<?php
|
||||
class Foo
|
||||
{
|
||||
@ -504,7 +517,8 @@ class Foo
|
||||
}
|
||||
}',
|
||||
];
|
||||
$cases[] = [
|
||||
|
||||
yield [
|
||||
'<?php
|
||||
class Foo
|
||||
{
|
||||
@ -535,7 +549,8 @@ class Foo
|
||||
}
|
||||
}',
|
||||
];
|
||||
$cases[] = [
|
||||
|
||||
yield [
|
||||
'<?php
|
||||
class Foo
|
||||
{
|
||||
@ -560,11 +575,9 @@ class Foo
|
||||
}
|
||||
}',
|
||||
];
|
||||
|
||||
return $cases;
|
||||
}
|
||||
|
||||
protected function createFixer() {
|
||||
protected function createFixer(): AbstractFixer {
|
||||
return new LineBreakAfterStatementsFixer();
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user